Skip to content
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

Support CommandWithArguments hint for #3266

Open
2 tasks done
tmccombs opened this issue Jan 7, 2022 · 5 comments
Open
2 tasks done

Support CommandWithArguments hint for #3266

tmccombs opened this issue Jan 7, 2022 · 5 comments
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations S-triage Status: New; needs maintainer attention.

Comments

@tmccombs
Copy link
Contributor

tmccombs commented Jan 7, 2022

Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

Clap Version

3.0.5

Describe your use case

I have an argument like:

            Arg::new("exec-batch")
                .long("exec-batch")
                .short('X')
                .min_values(1)
                .allow_hyphen_values(true)
                .value_terminator(";")
                .value_name("cmd")

Ideally, I would be able to use .value_hint(ValueHint::CommandWithArguments) for this, but since it isn't a positional argument, I can't.

Describe the solution you'd like

Allow using ValueHint::CommandWithArguments for non-positional arguments, as long as:

  1. It accepts multiple values
  2. there is a value_terminator supplied

Alternatives, if applicable

possibly have a seperate hint type for this use case?

Additional Context

No response

@tmccombs tmccombs added the C-enhancement Category: Raise on the bar on expectations label Jan 7, 2022
@epage
Copy link
Member

epage commented Jan 7, 2022

In what way are you not seeing this supported?

@epage epage added A-completion Area: completion generator S-triage Status: New; needs maintainer attention. labels Jan 7, 2022
@tmccombs
Copy link
Contributor Author

tmccombs commented Jan 8, 2022

If I add .value_hint(ValueHint::CommandWithArguments) I get:

thread 'main' panicked at 'App fd: Argument 'exec-batch' has hint CommandWithArguments and must be positional.', /home/thayne/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-3.0.5/src/build/app/debug_asserts.rs:210:13

There is a debug_assert that requires the argument to be positional if it has the CommandWithArguments hint.
This is also mentioned in the documentation:

the argument must be a positional argument and have .multiple_values(true) and App must use AppSettings::TrailingVarArg

@tmccombs
Copy link
Contributor Author

tmccombs commented Jan 8, 2022

I believe in this case the zsh completion would need to be different. Instead of using _cmdambivalent it would need to use something like:

" _command_names -e:*{}::args: _normal" where {} is replaced with the escaped value of the terminator.

That is, the first value is completed as a command name, and then every value after up to and including the value that matches the terminator are completed using _normal but using excluding the command up to the first value passed to the option.

See

ValueHint::CommandWithArguments => "_cmdambivalent",

@epage
Copy link
Member

epage commented Jan 11, 2022

Sorry, I somehow had missed that part of the code when searching

I believe in this case the zsh completion would need to be different. Instead of using _cmdambivalent it would need to use something like:

" _command_names -e:*{}::args: _normal" where {} is replaced with the escaped value of the terminator.

That is, the first value is completed as a command name, and then every value after up to and including the value that matches the terminator are completed using _normal but using excluding the command up to the first value passed to the option.

See

ValueHint::CommandWithArguments => "_cmdambivalent",

Sounds like loosening CommandWithArguments won't help unless we manually implement the handling.

As an alternative, would per-value ValueHints help with this (something brought up in #2683)? The first value would be _cmdambivalent with the next being _normal. That being the last value hint, we'd then repeat it for all future value hints in that occurrence.

@tmccombs
Copy link
Contributor Author

As an alternative, would per-value ValueHints help with this (something brought up in #2683)? The first value would be _cmdambivalent with the next being _normal. That being the last value hint, we'd then repeat it for all future value hints in that occurrence.

I'm guessing you ment _command_names - not _cmdambivalent?

That would probably be tricky to do. The arguments that use _normal should use the command name argument in order to determine completion. In the example I gave above that is accomplished by using the double colon form. It would also need to be aware of the terminator in order to know when to stop accepting arguments.

davvid added a commit to davvid/clap that referenced this issue Jan 9, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

	$ my-app <TAB>
	_arguments:comparguments:325: doubled rest argument definition:
	*::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 9, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

	$ my-app <TAB>
	_arguments:comparguments:325: doubled rest argument definition:
	*::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 9, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

	$ my-app <TAB>
	_arguments:comparguments:325: doubled rest argument definition:
	*::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 9, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

	$ my-app <TAB>
	_arguments:comparguments:325: doubled rest argument definition:
	*::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 9, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

	$ my-app <TAB>
	_arguments:comparguments:325: doubled rest argument definition:
	*::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 9, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

	$ my-app <TAB>
	_arguments:comparguments:325: doubled rest argument definition:
	*::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 9, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 9, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 10, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 10, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 10, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 10, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 10, 2023
Emit the value_terminator into the zsh completion pattern when
completing multi-length arguments on zsh to avoid doubled
rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

Follow the suggestion from
clap-rs#3266 (comment)
by including the value terminator in order to resolve the ambiguity.

Closes clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
davvid added a commit to davvid/clap that referenced this issue Jan 10, 2023
Emit the user-defined value terminator into the zsh completion pattern
to avoid doubled rest-arguments definitions:

    $ my-app <TAB>
    _arguments:comparguments:325: doubled rest argument definition:
    *::second -- second set of of multi-length arguments:

clap-rs#3266 (comment)
noted that including the value terminator is one step towards a
robust solution for handling multiple multi-valued arguments.

This change does not yet handle automatically detecting when a value
terminator is needed, but it does add tests to ensure that
user-specified value terminators are used on zsh.

Related-to: clap-rs#3022
Signed-off-by: David Aguilar <davvid@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations S-triage Status: New; needs maintainer attention.
Projects
None yet
Development

No branches or pull requests

2 participants