From 4e478fc80f655c3b90d65e8481a18a5601630ebf Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Thu, 27 Sep 2012 00:04:13 +0200 Subject: [PATCH] feature #1383: Fix DSL-CLI argument check for non-command based tools --- src/cli/command_parser.rb | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/cli/command_parser.rb b/src/cli/command_parser.rb index be6318687f..9d7b4222cd 100644 --- a/src/cli/command_parser.rb +++ b/src/cli/command_parser.rb @@ -90,6 +90,12 @@ module CommandParser @description = str end + # Defines the name of the command + # @param [String] str + def name(str) + @name = str + end + # Defines a block that will be used to parse the arguments # of the command. Formats defined using this method con be used # in the arguments section of the command method, when defining a new @@ -386,12 +392,14 @@ module CommandParser def run comm_name="" + if @main - comm=@main + comm_name = @name + comm = @main elsif if @args[0] && !@args[0].match(/^-/) - comm_name=@args.shift.to_sym - comm=@commands[comm_name] + comm_name = @args.shift.to_sym + comm = @commands[comm_name] end end @@ -470,8 +478,13 @@ module CommandParser end puts puts "Usage:" - print " #{name} " - print_command(@commands[name]) + + if @main + print " #{@usage}\n" + else + print " #{name} " + print_command(@commands[name]) + end exit -1 else id=0