Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

Feature: subcommand name without hyphen #115

Open
epage opened this issue Dec 6, 2021 · 5 comments
Open

Feature: subcommand name without hyphen #115

epage opened this issue Dec 6, 2021 · 5 comments

Comments

@epage
Copy link
Owner

epage commented Dec 6, 2021

Issue by chriskrycho
Monday Mar 18, 2019 at 18:49 GMT
Originally opened as clap-rs/clap#1431


Rust Version

  • rustc 1.33.0 (2aa4c46cf 2019-02-28)

Affected Version of clap

  • clap 2.32.0

Bug or Feature Request Summary

Add a flag which supports printing the name of an app subcommand without the hyphen instead of with a hyphen, for apps which do not use external commands.

Expected Behavior Summary

Clap apps can output app subcommand as the name of a subcommand when running app subcommand --help.

Actual Behavior Summary

Clap apps can only output app-subcommand as the name of a subcommand when running app subcommand --help.

Steps to Reproduce the issue

  1. App::new('app').subcommand(Subcommand::with_name('subcommand')).
  2. Run `

Sample Code or Link to Sample Code

notion is an app where we want subcommands to print like notion install not notion-install.

Debug output

Compile clap with cargo features "debug" such as:

[dependencies]
clap = { version = "2", features = ["debug"] }
Debug Output

Paste Debug Output Here

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by rtucker-mozilla
Wednesday Nov 27, 2019 at 13:22 GMT


Is there a way to disable this output alltogether?

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by pickfire
Saturday Mar 14, 2020 at 14:24 GMT


@CreepySkeleton If I want to do this, I just need to add a new global_settings right like Subcommand::DisableHyphen?

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by pksunkara
Saturday Mar 14, 2020 at 14:27 GMT


Unfortunately it's not that simple. We do app._build() before parsing which kind of propagates the app binary name to subcommands and the subcommand binary name becomes this. I have been planning to look at the binary name being used in usage messages for quite a while but it's not a priority for v3.

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by pickfire
Saturday Mar 14, 2020 at 15:04 GMT


@pksunkara But then it was marked is D: easy? I thought it seemed easy but not. T_T

Tests are here:

static ISSUE_1431: &str = "ctest-foo 

USAGE:
    ctest foo

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

#[test]Run Test
fn help_subcommand_without_hyphen() {
    let app = App::new("ctest").subcommand(App::new("foo"));
    assert!(utils::compare_output(
        app,
        "ctest foo -h",
        ISSUE_1431,
        false
    ));
}

It took me some time to find the trailing space that fails the test, ctest-foo . Especially when I cannot see or copy anything correctly:

Click to expand!
...
failures:

---- help_subcommand_without_hyphen stdout ----

--> left
ctest-foo

USAGE:
    ctest foo

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
--> right
ctest-foo

USAGE:
    ctest foo

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information
--
thread 'help_subcommand_without_hyphen' panicked at 'assertion failed: utils::compare_output(app, "ctest foo -h", ISSUE_1431, false)', tests/help.rs:1667:5


failures:
    help_subcommand_without_hyphen

test result: FAILED. 59 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

Comment by pksunkara
Monday Feb 22, 2021 at 09:30 GMT


Related to #1382

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant