aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2020-08-29 19:37:39 +0200
committerTeddy Wing2020-08-29 20:48:48 +0200
commit760d49ce6f4a8b1f631fec654ae87300474541a9 (patch)
treed67c26b33cbe69ac8dc0fc7ea2a067be45cc177d
parent8706dc07bcf3b4c965de8e9dd050bd8b97ebc693 (diff)
downloadgit-suggestion-760d49ce6f4a8b1f631fec654ae87300474541a9.tar.bz2
diff_options: Remove non-equals argument value handling
Tested out diff arguments with Git, and it turns out that arguments in the following form: $ git diff --word-diff color are not allowed. This error results: fatal: ambiguous argument 'color': unknown revision or path not in the working tree. Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' Thus, option all arguments require the equals character to specify the value of those arguments. We can make the logic much simpler by eliminating handling of space-separated argument values altogether. This fixes the problem of suggestion positional arguments being misinterpreted as `OPT_OPTIONS` argument values.
-rw-r--r--src/diff_options.rs30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/diff_options.rs b/src/diff_options.rs
index fa0af8e..108fc13 100644
--- a/src/diff_options.rs
+++ b/src/diff_options.rs
@@ -198,6 +198,7 @@ pub fn parse(args: &[String]) -> (Vec<&String>, Vec<&String>) {
// TODO: check for "=" and get next arg
// '='
// if no equals, then add next arg
+ // Turns out values are always specified with '='
for option in &ARG_OPTIONS {
if arg.starts_with(option) {
found_args.push(arg);
@@ -217,9 +218,9 @@ pub fn parse(args: &[String]) -> (Vec<&String>, Vec<&String>) {
dbg!(rest.find('=').is_none());
// if arg.len() > option.len()
// && rest.find('=').is_none() {
- if rest.find('=').is_none() {
- add_next_arg = true;
- }
+ // if rest.find('=').is_none() {
+ // add_next_arg = true;
+ // }
continue 'args;
}
@@ -227,15 +228,16 @@ pub fn parse(args: &[String]) -> (Vec<&String>, Vec<&String>) {
// check '='
// If no equals, add next arg if it doesn't begin with '-'
+ // OptOptions are always followed by '=' when specifying values
for option in &OPT_OPTIONS {
if arg.starts_with(option) {
found_args.push(arg);
- let (_option, rest) = arg.split_at(option.len());
-
- if rest.find('=').is_none() {
- add_next_arg = true;
- }
+ // let (_option, rest) = arg.split_at(option.len());
+ //
+ // if rest.find('=').is_none() {
+ // add_next_arg = true;
+ // }
continue 'args;
}
@@ -260,12 +262,10 @@ mod tests {
"MY_TOKEN".to_owned(),
"--diff-filter=A".to_owned(),
"-D".to_owned(),
- "--color".to_owned(),
- "always".to_owned(),
+ "--color=always".to_owned(),
"-U5".to_owned(),
"--patience".to_owned(),
- "--ws-error-highlight".to_owned(),
- "old,new".to_owned(),
+ "--ws-error-highlight=old,new".to_owned(),
"--no-rename-empty".to_owned(),
"--stat=50".to_owned(),
"-M90%".to_owned(),
@@ -277,12 +277,10 @@ mod tests {
assert_eq!(diff_opts, vec![
"--diff-filter=A",
"-D",
- "--color",
- "always",
+ "--color=always",
"-U5",
"--patience",
- "--ws-error-highlight",
- "old,new",
+ "--ws-error-highlight=old,new",
"--no-rename-empty",
"--stat=50",
"-M90%",