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

Inconsistent help-related behavior around subcommands #184

Open
LunarTulip opened this issue Jan 26, 2024 · 0 comments
Open

Inconsistent help-related behavior around subcommands #184

LunarTulip opened this issue Jan 26, 2024 · 0 comments

Comments

@LunarTulip
Copy link

Consider a basic minimal bit of argh code centered on subcommands, something like this:

use argh::FromArgs;

#[derive(FromArgs)]
/// Example
struct Args {
    #[argh(subcommand)]
    subcommand: Subcommand,
}

#[derive(FromArgs)]
#[argh(subcommand)]
enum Subcommand {
    One(SubcommandOption1),
    Two(SubcommandOption2),
}

#[derive(FromArgs)]
#[argh(subcommand, name = "one")]
/// First subcommand
struct SubcommandOption1 {}

#[derive(FromArgs)]
#[argh(subcommand, name = "two")]
/// Second subcommand
struct SubcommandOption2 {}

fn main() {
    let _args: Args = argh::from_env();
}

If the executable compiled from this code is run directly, without any args passed—cargo run or ./target/debug/text.exe—the following help text is displayed:

One of the following subcommands must be present:
    help
    one
    two

Run test.exe --help for more information.

This is somewhat inconsistent. On the one hand it supposedly needs one of those subcommands; on the other hand the recommendation-for-more-information is to run it without one of those subcommands, with only the --help flag.

Moreover, if one in fact follows either half of that advice—running it either with the help subcommand or the --help flag (which are, as far as I can tell, in practice synonymous)—then one will get this readout:

Usage: test.exe <command> [<args>]

Example

Options:
  --help            display usage information

Commands:
  one               First subcommand
  two               Second subcommand 

...wherein, suddenly, there's no help subcommand listed, while the --help flag is suddenly listed more centrally / less as-an-afterthought.

So, overall, it seems like there's some inconsistent behavior going on here. It doesn't seem like argh is quite sure whether it wants its help-menu-access to be primarily via subcommand (with the flag as a nondefault option for those who particularly need it) or whether it wants its help-menu-access to be primarily via flag (with the subcommand as a nondefault option for those who particularly need it). And I suspect that it would be better if argh were more committed in one direction or the other, rather than split halfway between the two as it currently is.

(All example code here was compiled and run on Windows 10, using argh 0.1.12.)

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

No branches or pull requests

1 participant