lib/mercenary/command.rb in mercenary-0.3.1 vs lib/mercenary/command.rb in mercenary-0.3.2

- old
+ new

@@ -7,10 +7,11 @@ attr_accessor :commands attr_accessor :actions attr_reader :map attr_accessor :parent attr_reader :trace + attr_reader :aliases # Public: Creates a new Command # # name - the name of the command # parent - (optional) the instancce of Mercenary::Command which you wish to @@ -23,10 +24,11 @@ @commands = {} @actions = [] @map = {} @parent = parent @trace = false + @aliases = [] end # Public: Sets or gets the command version # # version - the command version (optional) @@ -111,10 +113,11 @@ # cmd_name - the name of the alias # # Returns nothing def alias(cmd_name) logger.debug "adding alias to parent for self: '#{cmd_name}'" + aliases << cmd_name @parent.commands[cmd_name] = self end # Public: Add an action Proc to be executed at runtime # @@ -251,14 +254,21 @@ the_name << parent.full_name if parent && parent.full_name the_name << name the_name.join(" ") end + # Public: Return all the names and aliases for this command. + # + # Returns a comma-separated String list of the name followed by its aliases + def names_and_aliases + ([name.to_s] + aliases).compact.join(", ") + end + # Public: Build a string containing a summary of the command # # Returns a one-line summary of the command. def summarize - " #{name.to_s.ljust(20)} #{description}" + " #{names_and_aliases.ljust(20)} #{description}" end # Public: Build a string containing the command name, options and any subcommands # # Returns the string identifying this command, its options and its subcommands