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

Non-hierarchical subcommands / positional subcommands #1407

Closed
andreycizov opened this issue Jan 27, 2019 · 4 comments
Closed

Non-hierarchical subcommands / positional subcommands #1407

andreycizov opened this issue Jan 27, 2019 · 4 comments
Labels
A-builder Area: Builder API A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations S-wont-fix Status: Closed as there is no plan to fix this

Comments

@andreycizov
Copy link

Rust Version

rustc 1.32.0 (9fda7c223 2019-01-16)

Affected Version of clap

2.32.0

Bug or Feature Request Summary

I would like to be able to create a set an argument parsers for an utility that takes a list of commands to specify a list of input formats (let's call them IFs) and the set of commands that specify the output formats (OFs).

Currently, in order to do that I would need to create a whole tree of subcommands independently for each IF and for each OF. It doesn't seem to be an issue, but the output of --help would require to always specify at least one of the IFs in order to see the outputs of duplicated OFs in each of the IFs - that doesn't make for a user-friendly experience.

I come from python where argparse module allows you to do that: instead of specifying subcommands on the root parser - they simply return an instance of SubCommands that allows you to then specify the subcommands for that specific positional subcommand group.

Current Behaviour

Given IFs of xml, csv, txt and OFs of xml, csv, txt, the only way to specify those as subcommands would be (showing the output of the --help)

IFs help

>> convert --help
USAGE:
    convert [SUBCOMMAND]

SUBCOMMANDS:
    xml      desc_a
    csv     desc_b
    txt     desc_c

The going down to OFs:

>> convert xml --help
USAGE:
    convert xml [SUBCOMMAND]

SUBCOMMANDS:
    xml      desc_a
    csv     desc_b
    txt     desc_c

As is shown above, the output of every sub-sub-command would be the same regardless of what had been picked in the sub-command.

Expected Behavior Summary

>> convert --help
USAGE:
    convert [INPUT] [OUTPUT]

INPUT_SUBCOMMANDS:
    xml      desc_a
    csv     desc_b
    txt     desc_c

OUTPUT_SUBCOMMANDS:
    xml      desc_a
    csv     desc_b
    txt     desc_c
@CreepySkeleton CreepySkeleton added C: subcommands E-hard Call for participation: Experience needed to fix: Hard / a lot labels Feb 1, 2020
@epage epage added A-builder Area: Builder API A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations and removed C: subcommands labels Dec 8, 2021
@epage
Copy link
Member

epage commented Dec 9, 2021

I know its been a while since you've posted on this, so sorry about this.

I'm assuming that there are args specific to the input and output subcommands that you want specific ordering for and that is why you need to use subcommands rather than positional arguments with possible_values. Is that correct?

I come from python where argparse module allows you to do that: instead of specifying subcommands on the root parser - they simply return an instance of SubCommands that allows you to then specify the subcommands for that specific positional subcommand group.

Have an example? I've used argparse but not familiar with this functionality. I'm curious to see how other libraries handle this as this adds a certain level of complexity

@epage epage added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed E-hard Call for participation: Experience needed to fix: Hard / a lot labels Dec 9, 2021
@pksunkara
Copy link
Member

Forget to tag this as related to #2222. Maybe even a duplicate?

@epage
Copy link
Member

epage commented Dec 12, 2021

I think they are slightly different.

In #2222, the request is for the following to be equivalent

$ cmd start stop
$ cmd staet && cmd stop

While this would have

$ cmd xml --path ./in.xml xml --path ./out,.xml

If we applied #2222's reasoning, this would run the xml command twice but the request here is for the two xml commands to be different, with different args and behavior.

@epage
Copy link
Member

epage commented Jan 11, 2022

btw if the main concern is the help output, the user can provide that directly. Maintaining that is annoying. #2913 and #2914 would allow custom dynamic help generation.

For now, I'm leaning towards that being our suggested route forward as this seems fairly specialized with a degree of its own complications. If there are concerns about that, let us know!

@epage epage closed this as completed Jan 11, 2022
@epage epage added S-wont-fix Status: Closed as there is no plan to fix this and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-builder Area: Builder API A-parsing Area: Parser's logic and needs it changed somehow. C-enhancement Category: Raise on the bar on expectations S-wont-fix Status: Closed as there is no plan to fix this
Projects
None yet
Development

No branches or pull requests

4 participants