remote-helper: Refactor option handling
Group `["option", "progress", ..]`, and `["option", ..]` cases together during match. Make the key/value matching cleaner using `ok_or_else` and then matching on the key value.
This commit is contained in:
parent
876d22b072
commit
4e67467966
|
|
@ -236,10 +236,7 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> {
|
||||||
push_option(args, &mut opts)?;
|
push_option(args, &mut opts)?;
|
||||||
println!("ok");
|
println!("ok");
|
||||||
}
|
}
|
||||||
["option", "progress", ..] => {
|
["option", "progress", ..] | ["option", ..] => {
|
||||||
println!("unsupported");
|
|
||||||
}
|
|
||||||
["option", ..] => {
|
|
||||||
println!("unsupported");
|
println!("unsupported");
|
||||||
}
|
}
|
||||||
["fetch", oid, refstr] => {
|
["fetch", oid, refstr] => {
|
||||||
|
|
@ -302,22 +299,21 @@ fn push_option(args: &[&str], opts: &mut Options) -> Result<(), Error> {
|
||||||
_ => {
|
_ => {
|
||||||
let args = args.join(" ");
|
let args = args.join(" ");
|
||||||
|
|
||||||
if let Some((key, val)) = args.split_once('=') {
|
let (key, val) = args
|
||||||
match key {
|
.split_once('=')
|
||||||
"patch.message" => {
|
.ok_or_else(|| Error::UnsupportedPushOption(args.to_owned()))?;
|
||||||
opts.message.append(val);
|
|
||||||
}
|
match key {
|
||||||
"patch.base" => {
|
"patch.message" => {
|
||||||
let base =
|
opts.message.append(val);
|
||||||
cli::args::rev(&val.into()).map_err(|e| Error::Base(e.into()))?;
|
}
|
||||||
opts.base = Some(base);
|
"patch.base" => {
|
||||||
}
|
let base = cli::args::rev(&val.into()).map_err(|e| Error::Base(e.into()))?;
|
||||||
other => {
|
opts.base = Some(base);
|
||||||
return Err(Error::UnsupportedPushOption(other.to_owned()));
|
}
|
||||||
}
|
other => {
|
||||||
|
return Err(Error::UnsupportedPushOption(other.to_owned()));
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err(Error::UnsupportedPushOption(args.to_owned()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue