-
-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix check option #79
Fix check option #79
Conversation
I'm confused about how the args.check_args should split.
for arg_variants in [
(config.check_version).then(|| &args[0]),
(config.check_help && args.len() >= 2).then(|| &args[1]),
] so we have to make a special case if the user used the |
Hmm, it seems like a quite a bit of a thought experiment. I don't think we will allow things like
Yup, if necessary. |
Then we'll still have the ignoring behavior issue + this would be a breaking change
I don't see any other solution at this moment. in this case, I have two possible ways to solve this:
I prefer the second way 'cause it simpler |
Implement the second suggestion that's mentioned in <orhun#79 (comment)> and set the first element in the `config.check_args` array to an empty array if the user passed the --check option and use this as our condition in the `get_args_help` we check on this and test all the arrays elements
@orhun I can't figure out what makes |
for arg_variants in if args[0].is_empty() { | ||
[(args.len() > 1).then(|| &args[1..]), None] | ||
} else { | ||
[ | ||
(config.check_version).then(|| &args[..1]), | ||
(config.check_help && args.len() >= 2).then(|| &args[1..]), | ||
] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test_check_help_args
test fail because this statement returns [None, None]
which means no argument is checked.
(config.check_help && args.len() >= 2).then(|| &args[1]), | ||
] | ||
for arg_variants in if args[0].is_empty() { | ||
[(args.len() > 1).then(|| &args[1..]), None] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this can be simplified. It is very hard to understand what this is doing at first glance 💫
args: ArgsIter, | ||
arg: &str, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was the design choice behind removing the iterator and using a str here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'cause I moved the iteration loop to the get_args_help
so I can have more control over when to stop and when to continue
/// Error that might if the argument is not found. | ||
#[error("Argument not found.")] | ||
ArgumentNotFoundError, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't need this type of error so far, why do we have it now?
// Sets the first element to an empty vector to indicate that the all arguments should be checked. | ||
args.push(Vec::new()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, is there a better way to handle this?
if args[0].is_empty() { | ||
// If the user uses the `--check` option then we check all the arguments. | ||
arg_variants.iter().flatten().for_each(|arg| { | ||
let _ = check_arg(cmd, arg, verbose, output); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the result is ignored?
Btw, I'm still not entirely sure why do we need all of these changes. Isn't this the only thing that we need: diff --git a/src/cli.rs b/src/cli.rs
index cd1ae29..d5a37c6 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -70,6 +70,9 @@ impl CliArgs {
pub fn update_config(&self, config: &mut Config) {
config.check_help = !self.no_help;
config.check_version = !self.no_version;
+ if let Some(check_args) = &self.check_args {
+ config.check_args = Some(check_args.iter().map(|v| vec![v.to_string()]).collect());
+ }
if let Some(CliCommands::Plz {
ref man_cmd,
ref cheat_sh_url,
Examples in README.md work just fine with this: $ cargo run -- --check "\--silent" zps
(°ロ°) checking 'zps --silent'
\(^ヮ^)/ success '--silent' argument found! $ cargo run -- --check "help" --check "test" menyoki
(°ロ°) checking 'menyoki help'
\(^ヮ^)/ success 'help' argument found!
---
---
(°ロ°) checking 'menyoki test'
(×﹏×) fail 'test' argument not found. |
hmmmmm, I guess I unintentionally overcomplicated the problem.
if this simply works then let's close this PR and open another PR or if u want to commit it on the main branch |
I think you can submit another PR 🐻 I haven't tested that approach thoroughly so feel free to add some tests if needed. |
ok, i'll do that |
it didn't work with this example:
|
That's now how it is supposed to be used though. It should be individual arguments such as |
I don't think it is working. $ halp --check "\-H,help,\-\-help" ls
(°ロ°) checking 'ls -H,help,--help'
(×﹏×) fail '-H,help,--help' argument not found. Can you remove the default config file and try again? |
Oh, I completely forget about the config file issue and I didn't notice that |
81: fix(cli): fix the check option r=orhun a=0x61nas <!--- Thank you for contributing to halp! 🐙 --> ## Description Add the missing code to override the check args in the config instance with the `--check` CLI option ## Motivation and Context - Fix the issue that's introduced in #62 ## How Has This Been Tested? - I trayed to pass `--check="-h"` and it worked as expected - I trayed to pass ` --check='-h' --check='-V'` and it worked as expected also ## Types of Changes - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation (no code change) - [ ] Refactor (refactoring production code) - [ ] Other <!--- (provide information) --> ## Checklist: - [x] My code follows the code style of this project. - [x] I have updated the documentation accordingly. - [x] I have formatted the code with [rustfmt](https://github.com/rust-lang/rustfmt). - [x] I checked the lints with [clippy](https://github.com/rust-lang/rust-clippy). - [x] I have added tests to cover my changes. - [x] All new and existing tests passed. > This's an alternative to #79 Co-authored-by: Anas Elgarhy <anas.elgarhy.dev@gmail.com>
Description
Add the missing code to override the check args in the config instance with the
--check
CLI optionMotivation and Context
How Has This Been Tested?
Types of Changes
Checklist: