diff --git a/spec/help_spec.lua b/spec/help_spec.lua index e6fe228..5f0db13 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -77,13 +77,13 @@ Options: parser:option "--config" assert.equal([[ -Usage: foo [-q] --from [--config ] [-h] +Usage: foo [-h] [-q] --from [--config ] Options: + -h, --help Show this help message and exit. -q, --quiet --from - --config - -h, --help Show this help message and exit.]], parser:get_help()) + --config ]], parser:get_help()) end) it("adds margin for multiline descriptions", function() @@ -97,13 +97,13 @@ Sets verbosity level. -vv: Report all debugging information.]] assert.equal([[ -Usage: foo [-v] [-h] +Usage: foo [-h] [-v] Options: + -h, --help Show this help message and exit. -v Sets verbosity level. -v: Report all warnings. - -vv: Report all debugging information. - -h, --help Show this help message and exit.]], parser:get_help()) + -vv: Report all debugging information.]], parser:get_help()) end) it("puts different aliases on different lines if there are arguments", function() @@ -112,12 +112,12 @@ Options: parser:option "-o --output" assert.equal([[ -Usage: foo [-o ] [-h] +Usage: foo [-h] [-o ] Options: + -h, --help Show this help message and exit. -o , - --output - -h, --help Show this help message and exit.]], parser:get_help()) + --output ]], parser:get_help()) end) it("handles description with more lines than usage", function() @@ -131,13 +131,13 @@ If '-' is passed, output to stdount. ]] assert.equal([[ -Usage: foo [-o ] [-h] +Usage: foo [-h] [-o ] Options: + -h, --help Show this help message and exit. -o , Sets output file. --output If missing, 'a.out' is used by default. - If '-' is passed, output to stdount. - -h, --help Show this help message and exit.]], parser:get_help()) + If '-' is passed, output to stdount.]], parser:get_help()) end) it("handles description with less lines than usage", function() @@ -147,12 +147,12 @@ Options: :description "Sets output file." assert.equal([[ -Usage: foo [-o ] [-h] +Usage: foo [-h] [-o ] Options: + -h, --help Show this help message and exit. -o , Sets output file. - --output - -h, --help Show this help message and exit.]], parser:get_help()) + --output ]], parser:get_help()) end) it("handles very long argument lists", function() @@ -167,10 +167,10 @@ Options: Usage: foo [-h] [-t ...] Options: + -h, --help Show this help message and exit. -t ..., --at-least-three ... - Sometimes argument lists are really long. - -h, --help Show this help message and exit.]], parser:get_help()) + Sometimes argument lists are really long.]], parser:get_help()) end) it("shows default values", function() @@ -182,12 +182,12 @@ Options: :description "Port." assert.equal([[ -Usage: foo [-o ] [-p

] [-h] +Usage: foo [-h] [-o ] [-p

] Options: + -h, --help Show this help message and exit. -o default: a.out - -p

Port. (default: 8080) - -h, --help Show this help message and exit.]], parser:get_help()) + -p

Port. (default: 8080)]], parser:get_help()) end) it("does not show default value when show_default == false", function() @@ -201,12 +201,12 @@ Options: :description "Port." assert.equal([[ -Usage: foo [-o ] [-p

] [-h] +Usage: foo [-h] [-o ] [-p

] Options: + -h, --help Show this help message and exit. -o - -p

Port. - -h, --help Show this help message and exit.]], parser:get_help()) + -p

Port.]], parser:get_help()) end) it("creates correct help message for commands", function() @@ -217,11 +217,11 @@ Options: run:option "--where" assert.equal([[ -Usage: foo [-q] [-h] ... +Usage: foo [-h] [-q] ... Options: - -q, --quiet -h, --help Show this help message and exit. + -q, --quiet Commands: run Run! ]], parser:get_help()) @@ -234,11 +234,11 @@ Commands: run:option "--where" assert.equal([[ -Usage: foo run [--where ] [-h] +Usage: foo run [-h] [--where ] Options: - --where - -h, --help Show this help message and exit.]], run:get_help()) + -h, --help Show this help message and exit. + --where ]], run:get_help()) end) it("uses message provided by user", function() @@ -265,14 +265,14 @@ I don't like your format of help messages]], parser:get_help()) :hidden(true) assert.equal([[ -Usage: foo [--feature] [-h] ... +Usage: foo [-h] [--feature] ... Arguments: normal Options: - --feature -h, --help Show this help message and exit. + --feature Commands: good @@ -359,8 +359,8 @@ Options for setting style: parser:command "another-command" assert.equal([[ -Usage: foo [--use-default-args] [--something] [--test ] - [--version] [-h] [] ... +Usage: foo [-h] [--use-default-args] [--something] [--test ] + [--version] [] ... Main arguments: foo @@ -375,8 +375,8 @@ Main options: --test Other options: - --version -h, --help Show this help message and exit. + --version Some commands: foo @@ -404,7 +404,7 @@ Because it has lots of complex behaviour. That needs documenting.]] assert.equal([[ -Usage: foo [-p] [-f ] [-h] +Usage: foo [-h] [-p] [-f ] Arguments: @@ -414,13 +414,13 @@ Arguments: Options: + -h, --help Show this help message and exit. + -p This is a thing. -f , And this things uses many lines. --foo Because it has lots of complex behaviour. - That needs documenting. - - -h, --help Show this help message and exit.]], parser:get_help()) + That needs documenting.]], parser:get_help()) end) it("inherits help_vertical_space in commands", function() @@ -439,29 +439,29 @@ Options: cmd2:flag("-d", "Do d thing.") assert.equal([[ -Usage: foo cmd1 [-a] [-b] [-h] +Usage: foo cmd1 [-h] [-a] [-b] Options: + -h, --help Show this help message and exit. + + -a Do a thing. - -b Do b thing. - - - -h, --help Show this help message and exit.]], cmd1:get_help()) + -b Do b thing.]], cmd1:get_help()) assert.equal([[ -Usage: foo cmd2 [-c] [-d] [-h] +Usage: foo cmd2 [-h] [-c] [-d] Options: + -h, --help Show this help message and exit. + -c Do c thing. - -d Do d thing. - - -h, --help Show this help message and exit.]], cmd2:get_help()) + -d Do d thing.]], cmd2:get_help()) end) it("allows configuring margins using help_usage_margin and help_description_margin", function() @@ -483,18 +483,18 @@ Because it has lots of complex behaviour. That needs documenting.]] assert.equal([[ -Usage: foo [-p] [-f ] [-h] +Usage: foo [-h] [-p] [-f ] Arguments: arg1 Argument number one. arg2 Argument number two. Options: + -h, --help Show this help message and exit. -p This is a thing. -f , And this things uses many lines. --foo Because it has lots of complex behaviour. - That needs documenting. - -h, --help Show this help message and exit.]], parser:get_help()) + That needs documenting.]], parser:get_help()) end) describe("autowrap", function() @@ -512,9 +512,10 @@ Options: :description "See above." assert.equal([[ -Usage: foo [-f ] [-b ] [-h] +Usage: foo [-h] [-f ] [-b ] Options: + -h, --help Show this help message and exit. -f , Lorem ipsum dolor sit amet, consectetur adipiscing --foo elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis @@ -525,8 +526,7 @@ Options: cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. -b , See above. - --bar - -h, --help Show this help message and exit.]], parser:get_help()) + --bar ]], parser:get_help()) end) it("preserves existing line breaks", function() @@ -542,16 +542,16 @@ Another one. parser:option "-b --bar" assert.equal([[ -Usage: foo [-f ] [-b ] [-h] +Usage: foo [-h] [-f ] [-b ] Options: + -h, --help Show this help message and exit. -f , This is a long line, it should be broken down into --foo several lines. It just keeps going and going. This should always be a new line. Another one. -b , - --bar - -h, --help Show this help message and exit.]], parser:get_help()) + --bar ]], parser:get_help()) end) it("preserves indentation", function() @@ -565,17 +565,17 @@ Options: " That was an empty line there, preserve it.") assert.equal([[ -Usage: foo [-f ] [-h] +Usage: foo [-h] [-f ] Options: + -h, --help Show this help message and exit. -f , This is a long line, it should be broken down into --foo several lines. This paragraph is indented with three spaces, so when it gets broken down into several lines, they will be, too. - That was an empty line there, preserve it. - -h, --help Show this help message and exit.]], parser:get_help()) + That was an empty line there, preserve it.]], parser:get_help()) end) it("preserves indentation of list items", function() @@ -591,9 +591,10 @@ Options: assert.equal([[ -Usage: foo [-f ] [-h] +Usage: foo [-h] [-f ] Options: + -h, --help Show this help message and exit. -f , Let's start a list: --foo * Here is a list item. @@ -602,8 +603,7 @@ Options: + Here is a nested list item. Word. Word. Word. Word. Word. Bird. Word. Bird. Bird. Bird. * Back to normal list, this one uses several spaces - after the list item mark. Bird. Bird. Bird. - -h, --help Show this help message and exit.]], parser:get_help()) + after the list item mark. Bird. Bird. Bird.]], parser:get_help()) end) it("preserves multiple spaces between words", function() @@ -614,12 +614,12 @@ Options: :description("This is a long line with two spaces between words, it should be broken down.") assert.equal([[ -Usage: foo [-f ] [-h] +Usage: foo [-h] [-f ] Options: + -h, --help Show this help message and exit. -f , This is a long line with two spaces between - --foo words, it should be broken down. - -h, --help Show this help message and exit.]], parser:get_help()) + --foo words, it should be broken down.]], parser:get_help()) end) it("autowraps description and epilog", function() diff --git a/spec/integrity_spec.lua b/spec/integrity_spec.lua index 632c451..6ce3431 100644 --- a/spec/integrity_spec.lua +++ b/spec/integrity_spec.lua @@ -18,7 +18,7 @@ describe("tests related to CLI behaviour #unsafe", function() describe("error messages", function() it("generates correct error message without arguments", function() assert.equal([[ -Usage: ]]..script..[[ [-v] [-h] [] ... +Usage: ]]..script..[[ [-h] [-v] [] ... Error: missing argument 'input' ]], get_output("")) @@ -26,7 +26,7 @@ Error: missing argument 'input' it("generates correct error message with too many arguments", function() assert.equal([[ -Usage: ]]..script..[[ [-v] [-h] [] ... +Usage: ]]..script..[[ [-h] [-v] [] ... Error: unknown command 'bar' ]], get_output("foo bar")) @@ -34,7 +34,7 @@ Error: unknown command 'bar' it("generates correct error message with unexpected argument", function() assert.equal([[ -Usage: ]]..script..[[ [-v] [-h] [] ... +Usage: ]]..script..[[ [-h] [-v] [] ... Error: option '--verbose' does not take arguments ]], get_output("--verbose=true")) @@ -42,7 +42,7 @@ Error: option '--verbose' does not take arguments it("generates correct error message with unexpected option", function() assert.equal([[ -Usage: ]]..script..[[ [-v] [-h] [] ... +Usage: ]]..script..[[ [-h] [-v] [] ... Error: unknown option '-q' Did you mean one of these: '-h' '-v'? @@ -51,7 +51,7 @@ Did you mean one of these: '-h' '-v'? it("generates correct error message and tip with unexpected command", function() assert.equal([[ -Usage: ]]..script..[[ [-v] [-h] [] ... +Usage: ]]..script..[[ [-h] [-v] [] ... Error: unknown command 'nstall' Did you mean 'install'? @@ -60,7 +60,7 @@ Did you mean 'install'? it("generates correct error message without arguments in command", function() assert.equal([[ -Usage: ]]..script..[[ install [-f ] [-h] [] +Usage: ]]..script..[[ install [-h] [-f ] [] Error: missing argument 'rock' ]], get_output("foo install")) @@ -68,7 +68,7 @@ Error: missing argument 'rock' it("generates correct error message and tip in command", function() assert.equal([[ -Usage: ]]..script..[[ install [-f ] [-h] [] +Usage: ]]..script..[[ install [-h] [-f ] [] Error: unknown option '--form' Did you mean '--from'? @@ -79,7 +79,7 @@ Did you mean '--from'? describe("help messages", function() it("generates correct help message", function() assert.equal([[ -Usage: ]]..script..[[ [-v] [-h] [] ... +Usage: ]]..script..[[ [-h] [-v] [] ... A testing program. @@ -87,8 +87,8 @@ Arguments: input Options: - -v, --verbose Sets verbosity level. -h, --help Show this help message and exit. + -v, --verbose Sets verbosity level. Commands: install Install a rock. @@ -97,7 +97,7 @@ Commands: it("generates correct help message for command", function() assert.equal([[ -Usage: ]]..script..[[ install [-f ] [-h] [] +Usage: ]]..script..[[ install [-h] [-f ] [] Install a rock. @@ -106,9 +106,9 @@ Arguments: version Version of the rock. Options: + -h, --help Show this help message and exit. -f , Fetch the rock from this server. --from - -h, --help Show this help message and exit. ]], get_output("foo install --help")) end) end) diff --git a/spec/usage_spec.lua b/spec/usage_spec.lua index 3d93f10..072980d 100644 --- a/spec/usage_spec.lua +++ b/spec/usage_spec.lua @@ -320,7 +320,7 @@ Usage: foo ([--opt1 ] | [--opt3 ] | [--opt5 ]) :args "*" assert.equals([=[ -Usage: foo [--set-important-property ] [-h] +Usage: foo [-h] [--set-important-property ] [--include [] ...]]=], parser:get_usage()) end) @@ -336,9 +336,9 @@ Usage: foo [--set-important-property ] [-h] :args "*" assert.equals([=[ -Usage: foo +Usage: foo [-h] [--set-important-property ] - [-h] + [--include [] ...]]=], parser:get_usage()) end) end)