cli: Create terminal::cob

Use a new module, `terminal::cob`, to collect collaborative object code to
improve consistency.

Signed-off-by: Slack Coder <slackcoder@server.ky>
This commit is contained in:
Slack Coder 2023-01-19 08:28:37 -05:00 committed by Alexis Sellier
parent a0588460f3
commit 87ff1990c0
No known key found for this signature in database
3 changed files with 18 additions and 11 deletions

View File

@ -8,7 +8,6 @@ mod list;
mod show;
use std::ffi::OsString;
use std::str::FromStr;
use anyhow::anyhow;
@ -94,14 +93,6 @@ pub struct Options {
pub verbose: bool,
}
fn parse_patch_id(val: OsString) -> Result<OptPatch, anyhow::Error> {
let val = val
.to_str()
.ok_or_else(|| anyhow!("patch id specified is not UTF-8"))?;
let patch_id = PatchId::from_str(val).map_err(|_| anyhow!("invalid patch id '{}'", val))?;
Ok(OptPatch::Patch(patch_id))
}
impl Args for Options {
fn from_args(args: Vec<OsString>) -> anyhow::Result<(Self, Vec<OsString>)> {
use lexopt::prelude::*;
@ -166,10 +157,10 @@ impl Args for Options {
unknown => anyhow::bail!("unknown operation '{}'", unknown),
},
Value(val) if op == Some(OperationName::Show) && patch_id == OptPatch::Any => {
patch_id = parse_patch_id(val)?;
patch_id = OptPatch::Patch(term::cob::parse_patch_id(val)?);
}
Value(val) if op == Some(OperationName::Update) && patch_id == OptPatch::Any => {
patch_id = parse_patch_id(val)?;
patch_id = OptPatch::Patch(term::cob::parse_patch_id(val)?);
}
_ => return Err(anyhow::anyhow!(arg.unexpected())),
}

View File

@ -1,4 +1,5 @@
pub mod args;
pub mod cob;
pub mod command;
pub mod format;
pub mod io;

View File

@ -0,0 +1,15 @@
use std::str::FromStr;
use super::*;
use radicle::cob::patch;
use anyhow::anyhow;
pub fn parse_patch_id(val: OsString) -> Result<patch::PatchId, anyhow::Error> {
let val = val
.to_str()
.ok_or_else(|| anyhow!("patch id specified is not UTF-8"))?;
let patch_id =
patch::PatchId::from_str(val).map_err(|_| anyhow!("invalid patch id '{}'", val))?;
Ok(patch_id)
}