diff --git a/src/build/app/mod.rs b/src/build/app/mod.rs index 72286a3e..0284579e 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -1920,8 +1920,17 @@ impl<'help> App<'help> { self._render_version(true) } - /// @TODO-v3-alpha @docs @p2: write docs - pub fn generate_usage(&mut self) -> String { + /// Returns the usage statement + /// + /// ### Examples + /// + /// ```rust + /// # use clap::App; + /// use std::io; + /// let mut app = App::new("myprog"); + /// println!("{}", app.render_usage()); + /// ``` + pub fn render_usage(&mut self) -> String { // If there are global arguments, or settings we need to propagate them down to subcommands // before parsing incase we run into a subcommand self._build(); diff --git a/tests/positionals.rs b/tests/positionals.rs index 96f66ad6..74736d69 100644 --- a/tests/positionals.rs +++ b/tests/positionals.rs @@ -189,13 +189,13 @@ fn positional_hyphen_does_not_panic() { #[test] fn single_positional_usage_string() { let mut app = App::new("test").arg("[FILE] 'some file'"); - assert_eq!(app.generate_usage(), "USAGE:\n test [FILE]"); + assert_eq!(app.render_usage(), "USAGE:\n test [FILE]"); } #[test] fn single_positional_multiple_usage_string() { let mut app = App::new("test").arg("[FILE]... 'some file'"); - assert_eq!(app.generate_usage(), "USAGE:\n test [FILE]..."); + assert_eq!(app.render_usage(), "USAGE:\n test [FILE]..."); } #[test] @@ -203,7 +203,7 @@ fn multiple_positional_usage_string() { let mut app = App::new("test") .arg("[FILE] 'some file'") .arg("[FILES]... 'some file'"); - assert_eq!(app.generate_usage(), "USAGE:\n test [ARGS]"); + assert_eq!(app.render_usage(), "USAGE:\n test [ARGS]"); } #[test] @@ -211,13 +211,13 @@ fn multiple_positional_one_required_usage_string() { let mut app = App::new("test") .arg(" 'some file'") .arg("[FILES]... 'some file'"); - assert_eq!(app.generate_usage(), "USAGE:\n test [FILES]..."); + assert_eq!(app.render_usage(), "USAGE:\n test [FILES]..."); } #[test] fn single_positional_required_usage_string() { let mut app = App::new("test").arg(" 'some file'"); - assert_eq!(app.generate_usage(), "USAGE:\n test "); + assert_eq!(app.render_usage(), "USAGE:\n test "); } // This tests a programmer error and will only succeed with debug_assertions diff --git a/tests/subcommands.rs b/tests/subcommands.rs index e479f8a7..1f3220df 100644 --- a/tests/subcommands.rs +++ b/tests/subcommands.rs @@ -423,10 +423,7 @@ fn subcommand_placeholder_test() { .subcommand(App::new("subcommand")) .subcommand_placeholder("TEST_PLACEHOLDER", "TEST_HEADER"); - assert_eq!( - &app.generate_usage(), - "USAGE:\n myprog [TEST_PLACEHOLDER]" - ); + assert_eq!(&app.render_usage(), "USAGE:\n myprog [TEST_PLACEHOLDER]"); let mut help_text = Vec::new(); app.write_help(&mut help_text)