From bd5fd00e6caf59c0ce9bcaa48a09edefd99a5ae0 Mon Sep 17 00:00:00 2001 From: mpeterv Date: Mon, 25 Aug 2014 13:51:08 +0400 Subject: [PATCH] Custom target should not affect usage and help message generation --- spec/help_spec.lua | 4 ++-- spec/integrity_spec.lua | 8 ++++---- spec/usage_spec.lua | 2 +- src/argparse.lua | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/help_spec.lua b/spec/help_spec.lua index ee6956e..7100a8b 100644 --- a/spec/help_spec.lua +++ b/spec/help_spec.lua @@ -85,11 +85,11 @@ describe("tests related to help message generation", function() parser:option "--config" assert.equal(table.concat({ - "Usage: foo [-q] --from [--config ] [-h]", + "Usage: foo [-q] --from [--config ] [-h]", "", "Options: ", " -q, --quiet", - " --from ", + " --from ", " --config ", " -h, --help Show this help message and exit. " }, "\r\n"), parser:get_help()) diff --git a/spec/integrity_spec.lua b/spec/integrity_spec.lua index c8233c1..af4112f 100644 --- a/spec/integrity_spec.lua +++ b/spec/integrity_spec.lua @@ -60,7 +60,7 @@ describe("tests related to CLI behaviour #unsafe", function() it("generates correct error message without arguments in command", function() local handler = io.popen("./spec/script foo install 2>&1", "r") assert.equal(table.concat({ - "Usage: ./spec/script install [-f ] [-h] []", + "Usage: ./spec/script install [-f ] [-h] []", "", "Error: too few arguments", "" @@ -71,7 +71,7 @@ describe("tests related to CLI behaviour #unsafe", function() it("generates correct error message and tip in command", function() local handler = io.popen("./spec/script foo install bar --form=there 2>&1", "r") assert.equal(table.concat({ - "Usage: ./spec/script install [-f ] [-h] []", + "Usage: ./spec/script install [-f ] [-h] []", "", "Error: unknown option '--form'", "Did you mean '--from'?", @@ -106,7 +106,7 @@ describe("tests related to CLI behaviour #unsafe", function() it("generates correct help message for command", function() local handler = io.popen("./spec/script foo install --help 2>&1", "r") assert.equal(table.concat({ - "Usage: ./spec/script install [-f ] [-h] []", + "Usage: ./spec/script install [-f ] [-h] []", "", "Install a rock. ", "", @@ -115,7 +115,7 @@ describe("tests related to CLI behaviour #unsafe", function() " version Version of the rock. ", "", "Options: ", - " -f , --from ", + " -f , --from ", " Fetch the rock from this server. ", " -h, --help Show this help message and exit. ", "", diff --git a/spec/usage_spec.lua b/spec/usage_spec.lua index 40082a5..60ebe62 100644 --- a/spec/usage_spec.lua +++ b/spec/usage_spec.lua @@ -36,7 +36,7 @@ describe("tests related to usage message generation", function() parser:option "--config" assert.equal( - [=[Usage: foo [-q] --from [--config ]]=], + [=[Usage: foo [-q] --from [--config ]]=], parser:get_usage() ) end) diff --git a/src/argparse.lua b/src/argparse.lua index 9f7ccb7..96b000c 100644 --- a/src/argparse.lua +++ b/src/argparse.lua @@ -306,7 +306,7 @@ function Argument:_get_default_argname() end function Option:_get_default_argname() - return "<" .. (self._target or self:_get_default_target()) .. ">" + return "<" .. self:_get_default_target() .. ">" end -- Returns label to be shown in the help message.