-
Notifications
You must be signed in to change notification settings - Fork 392
refactor: rename { => _comp}{_get_first_arg,_count_args}
#1033
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
Conversation
9ec88a4
to
5e2971b
Compare
caf7bf2
to
84b0537
Compare
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.
Looks mostly good to me, but I'd be happier if we had some tests for the changed behavior e.g. regarding -
and --
, as well as the last commit (optarg check fixes).
2dec3ce
to
3696585
Compare
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.
Thanks!
Left some final remarks, pre-approved with them addressed.
72e9c7d
to
ab230e4
Compare
The check that unconditionally accepts a word by a pattern has been added by commits 75ec298 and 3809d95. However, even if the word matches the specified pattern, if the word is an option argument of the previous option, it should not be counted as an argument. This patch changes the behavior so that it does not treat the word matching $3 as an argument when it is an option argument. The current use case of $3 is only by chmod, where $2 is unspecified, so the behavior is unaffected by this change.
Co-authored-by: Ville Skyttä <ville.skytta@iki.fi>
The current interface does not distinguish the case where no argument is found and the case where the first argument is an empty string. This patch returns whether the first argument is found through the exit status. This also modifies the callers so that they use the exit status to check if the first argument is specified.
When the current implementation checks an option argument, it tests whether the previous word matches $2 (i.e., a pattern of options taking an option argument). This implementation has multiple issues: * When the options taking an option argument does not start with `-`, the option is counted as an independent argument. For example, `ssh` completion passes `@(-c|[-+]o)` as $2, but `+o` is counted as an argument with the current implementation. * An option argument that looks like an option taking an option argument can prevent the next word counted as an argument. For example, when `cmd -o -o arg` is processed with $2 being `-o`, the second `-o` should be treated as an option argument and `arg` should be counted as an argument. However, with the current implementation, `arg` is not counted because the previous word `-o` matches the pattern. * When `cmd -o -- -x` is processed with $2 being `-o`, `--` should be treated as an option argument so should lose its special meaning, and `-x` is still treated as an option. However, with the current implementation, `--` does not lose its special meaning, so `-x` is unexpectedly treated as an argument. * Also, with the current implementation, when $2 is not specified, an argument after an empty word is not counted as an argument because $2 matches the empty word, (though Readline usually do not store an empty word in COMP_WORDS). This patch fixes those issues by changing how options taking an option argument are processed.
ab230e4
to
874c503
Compare
No description provided.