cli: fix ambiguity between mutually exclusive args
There are some cases where it is just safe to skip the `--x` flag because it is already set to true by default, and other cases where we need to use an option value. Also, I may miss some team code conventions regarding the PartialEq and Eq macros to enable the quality on the `Comment` type! Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
parent
1b00e8a413
commit
c7d5ffe51b
|
|
@ -98,20 +98,25 @@ impl Args for Options {
|
||||||
|
|
||||||
// Options.
|
// Options.
|
||||||
Long("message") | Short('m') => {
|
Long("message") | Short('m') => {
|
||||||
|
if message != Comment::Blank {
|
||||||
|
// We skip this code when `no-message` is specified.
|
||||||
let txt: String = parser.value()?.to_string_lossy().into();
|
let txt: String = parser.value()?.to_string_lossy().into();
|
||||||
message.append(&txt);
|
message.append(&txt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Long("no-message") => {
|
Long("no-message") => {
|
||||||
message = Comment::Blank;
|
message = Comment::Blank;
|
||||||
}
|
}
|
||||||
Long("sync") => {
|
Long("sync") => {
|
||||||
sync = true;
|
// By default it is already true, so
|
||||||
|
// the only case where this is false,
|
||||||
|
// is the case where `no-sync` is specified.
|
||||||
}
|
}
|
||||||
Long("no-sync") => {
|
Long("no-sync") => {
|
||||||
sync = false;
|
sync = false;
|
||||||
}
|
}
|
||||||
Long("push") => {
|
Long("push") => {
|
||||||
push = true;
|
// Skip for the same reason as `sync`.
|
||||||
}
|
}
|
||||||
Long("no-push") => {
|
Long("no-push") => {
|
||||||
push = false;
|
push = false;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ impl Args for Options {
|
||||||
let mut verbose = false;
|
let mut verbose = false;
|
||||||
let mut force = false;
|
let mut force = false;
|
||||||
let mut all = false;
|
let mut all = false;
|
||||||
let mut sync = false;
|
let mut sync = None;
|
||||||
let mut set_upstream = false;
|
let mut set_upstream = false;
|
||||||
|
|
||||||
while let Some(arg) = parser.next()? {
|
while let Some(arg) = parser.next()? {
|
||||||
|
|
@ -69,10 +69,14 @@ impl Args for Options {
|
||||||
set_upstream = true;
|
set_upstream = true;
|
||||||
}
|
}
|
||||||
Long("sync") => {
|
Long("sync") => {
|
||||||
sync = true;
|
// Falls back to `--no-sync` in case of ambiguity.
|
||||||
|
// eg. `rad push --no-sync --sync`
|
||||||
|
if sync.is_none() {
|
||||||
|
sync = Some(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Long("no-sync") => {
|
Long("no-sync") => {
|
||||||
sync = false;
|
sync = Some(false);
|
||||||
}
|
}
|
||||||
Long("force") | Short('f') => {
|
Long("force") | Short('f') => {
|
||||||
force = true;
|
force = true;
|
||||||
|
|
@ -88,7 +92,7 @@ impl Args for Options {
|
||||||
force,
|
force,
|
||||||
all,
|
all,
|
||||||
set_upstream,
|
set_upstream,
|
||||||
sync,
|
sync: sync.unwrap_or_default(),
|
||||||
verbose,
|
verbose,
|
||||||
},
|
},
|
||||||
vec![],
|
vec![],
|
||||||
|
|
|
||||||
|
|
@ -80,15 +80,17 @@ impl Args for Options {
|
||||||
revision = Some(id);
|
revision = Some(id);
|
||||||
}
|
}
|
||||||
Long("sync") => {
|
Long("sync") => {
|
||||||
sync = true;
|
// Skipping due the `no-sync` flag precedence.
|
||||||
}
|
}
|
||||||
Long("no-sync") => {
|
Long("no-sync") => {
|
||||||
sync = false;
|
sync = false;
|
||||||
}
|
}
|
||||||
Long("message") | Short('m') => {
|
Long("message") | Short('m') => {
|
||||||
|
if message != Comment::Blank {
|
||||||
let txt: String = parser.value()?.to_string_lossy().into();
|
let txt: String = parser.value()?.to_string_lossy().into();
|
||||||
message.append(&txt);
|
message.append(&txt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Long("no-message") => {
|
Long("no-message") => {
|
||||||
message = Comment::Blank;
|
message = Comment::Blank;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ use radicle::git;
|
||||||
use crate::terminal as term;
|
use crate::terminal as term;
|
||||||
|
|
||||||
/// How a comment is to be supplied by the user for a patch or issue on the terminal.
|
/// How a comment is to be supplied by the user for a patch or issue on the terminal.
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum Comment {
|
pub enum Comment {
|
||||||
/// Prompt user to write comment in editor.
|
/// Prompt user to write comment in editor.
|
||||||
Edit,
|
Edit,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue