lib/scparse.rb in antfarm-0.3.0 vs lib/scparse.rb in antfarm-0.4.0
- old
+ new
@@ -64,11 +64,11 @@
@name = name
@execute_prerequisites = execute_prerequisites
end
def add_command(command)
- @commands = CommandHash.new unless @commands
+ @commands ||= CommandHash.new
@commands[command.name] = command
command.parent = self
end
# Return the uber-parent, which is a ScriptCommandParser object.
@@ -88,10 +88,16 @@
parents << cmd
end until cmd.parent.is_a?(ScriptCommandParser)
return parents
end
+ # Does this command have a given subcommand?
+ # Note: returns the command or nil, not true/false.
+ def has_command?(command)
+ return @commands[command]
+ end
+
# Does this command have any subcommands it's a parent to?
def has_commands?
return @commands.nil? ? false : true
end
@@ -264,9 +270,16 @@
end
# Adds a subcommand to the main command object.
def add_command(command)
@main.add_command(command)
+ end
+
+ # Does this application have a command with
+ # the given name?
+ # Note: returns command or nil, not true/false.
+ def has_command?(command)
+ @main.has_command?(command)
end
# Returns any options in the main command object.
def options
@main.options