On 01/11/2012 08:32 PM, Matt Wagner wrote:
On Wed, Jan 11, 2012 at 10:14:54AM +0000, mtaylor(a)redhat.com wrote:
> From: Martyn Taylor<mtaylor(a)redhat.com>
>
> ---
> lib/aeolus_cli/command/config_parser.rb | 8 ++++----
> 1 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/lib/aeolus_cli/command/config_parser.rb
b/lib/aeolus_cli/command/config_parser.rb
> index e74401d..cb804eb 100644
> --- a/lib/aeolus_cli/command/config_parser.rb
> +++ b/lib/aeolus_cli/command/config_parser.rb
> @@ -51,11 +51,11 @@ module Aeolus
> def parse(opts)
> begin
> opts.parse(@args)
> - rescue OptionParser::InvalidOption => io
> - puts "Warning, " + io.message + "\n\tSee `aeolus-image
" + @command + " -h` for usage information."
> + rescue OptionParser::ParseError => e
> + puts "Warning, " + e.message + "\n\tSee `aeolus-image
" + @command + " -h` for usage information."
> exit(1)
> - rescue OptionParser::MissingArgument => e
> - puts "Warning, #{e.message}" + "\n\tSee `aeolus-image
" + @command + " -h` for usage information."
> + rescue
> + puts "An error occurred: See `aeolus-image " + @command + "
-h` for usage information."
> exit(1)
> end
> end
> --
I couldn't reproduce the problem in the BZ before or after applying this
patch. I get:
$ aeolus-image push --account ec2 -image foo
ERROR: ImageNotFound => Could not find Image mage
It seems to be parsing the "-image" as a valid "-i" flag with an
argument of "mage".
This is neither an ACK nor a NACK, as I'm not sure I'm testing properly.
The code looks sound, but it doesn't appear to fix the problem for me.
-- Matt
Matt,
So this is default behaviour by option parser (i.e. it does not need a
space between option and value, well at least that seems to be the case)
However, this BZ is really a separate issue. Though the code to
reproduce listed in the BZ doesn't seem to do the job.
To explain what is happening here. OptionParser has an autocomplete
function, so that you can partially type in an option i.e.
aeolus-image push --ima 1234-xxxx --accou mock-account
It will autocomplete the partial options to:
aeolus-image push --image 1234-xxxx --account mock-account
The problem arises when the partial options are matched against more
than 1 options. For example:
aeolus-image list --targ
could mean:
aeolus-image list --targetimages
aeolus-image list --targets
This is when an ambiguous option exception is thrown. When one of these
was thrown previously we got a load of garbase printed out to the user.
What this patch does is catch any option parser exception (as opposed to
just InvalidOption/MissingArgument exception) and display a user
friendly message. i.e. you haven't entered proper usage.
Cheers
Martyn