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

Show usage of subcommand in global help #962

Closed
pitkley opened this issue May 16, 2017 · 7 comments
Closed

Show usage of subcommand in global help #962

pitkley opened this issue May 16, 2017 · 7 comments
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations E-medium Call for participation: Experience needed to fix: Medium / intermediate S-wont-fix Status: Closed as there is no plan to fix this

Comments

@pitkley
Copy link

pitkley commented May 16, 2017

I don't know if this feature exists, if so, I have not found it yet. What I'm looking for is a way to see the usage of a subcommand in the help shown by the help subcommand or the global --help flag. Compare the actual behavior to the expected behavior for an example.


Rust Version

rustc 1.17.0 (56124baa9 2017-04-24)

Affected Version of clap

2.24.1

Actual Behavior Summary

$ ./test --help
test 

USAGE:
    test [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    help          Prints this message or the help of the given subcommand(s)
    subcommand    subcommand help

The SUBCOMMANDS: section only shows the subcommands that exist, not what parameters they require.

One has to ask for the specific help:

$ ./test subcommand --help
test-subcommand 

USAGE:
    test subcommand <PARAM>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <test>

Expected Behavior Summary

$ ./test --help
test 

USAGE:
    test [SUBCOMMAND]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

SUBCOMMANDS:
    help
                  Prints this message or the help of the given subcommand(s)
    subcommand <PARAM>
                  subcommand help

Instead of having to look at every individual help output, the SUBCOMMANDS: section shows the USAGE: section of the subcommands.

Sample Code

extern crate clap;
use clap::{Arg, App, SubCommand};

fn main() {
    let matches = App::new("test")
        .subcommand(SubCommand::with_name("subcommand")
                        .about("subcommand help")
                        .arg(Arg::with_name("PARAM").required(true)))
        .get_matches();
}

Debug output

I can supply this at a later time if required.

@kbknapp
Copy link
Member

kbknapp commented May 19, 2017

Thanks for the suggestion and all the details! 👍

This feature doesn't exist (yet) could be added as an AppSettings variant, although my only concern is recursively following that chain with multiple nested subcommands.

Since I'm actively working on 3x I think this is something I'll try to add then, because the code clean ups I've done so far would make this far easier to implement, and/or people to contribute to. However, if someone wants this done immediately I'd be willing to assist in mentoring or answering questions on how this could be done.

@kbknapp kbknapp added C: help pages gen E-medium Call for participation: Experience needed to fix: Medium / intermediate C-enhancement Category: Raise on the bar on expectations labels May 19, 2017
@pitkley
Copy link
Author

pitkley commented May 19, 2017

Thanks for the reply.

  1. Regarding your concerns on recursion: I personally think that the first usage level "down" would be enough, I wouldn't even be sure how to print another level without the output getting crowded or illegible.

    I.e. for this code:

    extern crate clap;
    use clap::{Arg, App, SubCommand};
    
    fn main() {
        let matches = App::new("test")
            .subcommand(SubCommand::with_name("subcommand")
                            .about("subcommand help")
                            .arg(Arg::with_name("PARAM").required(true))
                            .subcommand(SubCommand::with_name("nested")
                                            .arg(Arg::with_name("NESTED").required(true)))
            .get_matches();
    }

    I would simply expect the usage on subcommand to gain [SUBCOMMAND]:

    $ ./test --help
    test 
    
    USAGE:
        test [SUBCOMMAND]
    
    FLAGS:
        -h, --help       Prints help information
        -V, --version    Prints version information
    
    SUBCOMMANDS:
        help
                      Prints this message or the help of the given subcommand(s)
        subcommand <PARAM> [SUBCOMMAND]
                      subcommand help

    But if you could think of a way to cleanly print even those subcommands, it might be worth while implementing too.

  2. Regarding an implementation for 2.x: while I would try and take a stab at it, especially since you offered your assistance, I personally can wait for 3.x to either have that feature or help with an implementation once 3.x is ready for contributions.

@kbknapp
Copy link
Member

kbknapp commented Jul 22, 2018

I'm going to close this for the time being, but may re-address it once 3.x is out

@CreepySkeleton
Copy link
Contributor

Leaving it closed for the time being

@pksunkara pksunkara reopened this May 26, 2021
@pksunkara pksunkara removed the W: 3.x label Aug 13, 2021
@epage epage added A-help Area: documentation, including docs.rs, readme, examples, etc... and removed C: subcommands labels Dec 8, 2021
@epage epage added S-waiting-on-mentor Status: Needs elaboration on the details before doing a 'Call for participation' and removed P4: nice to have labels Dec 9, 2021
@buck-ross
Copy link

Has there been any update on this? I see the issue has been re-opened, but there doesn't seem to be any follow-up that I can see.

@epage
Copy link
Member

epage commented Feb 9, 2022

No updates. A lot of our focus right now is in other areas like API clean up, shrinking binary size, fixing bugs, etc.

I am curious if the solution proposed in #1334 might be a viable alternative to meet the same needs. If we can find more common solutions to problems, it can help us meet our goal of keeping binary sizes and compile times down,.

@epage
Copy link
Member

epage commented Nov 8, 2022

I lean in favor of #1334 instead and am closing in favor of that as usually someone is either caring about one command at a time or with them flattened and the build-time / binary size cost of supporting both wouldn't be great.

If people make the case for this being needed, I'm ok with re-opening this.

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2022
@epage epage added S-wont-fix Status: Closed as there is no plan to fix this and removed S-waiting-on-mentor Status: Needs elaboration on the details before doing a 'Call for participation' labels Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-help Area: documentation, including docs.rs, readme, examples, etc... C-enhancement Category: Raise on the bar on expectations E-medium Call for participation: Experience needed to fix: Medium / intermediate S-wont-fix Status: Closed as there is no plan to fix this
Projects
None yet
Development

No branches or pull requests

6 participants