Skip to content

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

Merged
merged 14 commits into from
Sep 1, 2023

Conversation

akinomyoga
Copy link
Collaborator

No description provided.

Copy link
Owner

@scop scop left a 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).

@akinomyoga akinomyoga force-pushed the refactor-api-2 branch 2 times, most recently from 2dec3ce to 3696585 Compare August 31, 2023 23:04
@akinomyoga
Copy link
Collaborator Author

There were no tests for _get_first_arg at all, so I added basic tests (87fee4e). Then, I added tests in commits 37f458d, 443d0a2, and 3696585.

Copy link
Owner

@scop scop left a 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.

akinomyoga and others added 8 commits September 1, 2023 20:30
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.
@scop scop merged commit 1e4315a into scop:master Sep 1, 2023
@akinomyoga akinomyoga deleted the refactor-api-2 branch September 1, 2023 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants