lib/rubikon/application/dsl_methods.rb in rubikon-0.5.0 vs lib/rubikon/application/dsl_methods.rb in rubikon-0.5.1

- old
+ new

@@ -14,20 +14,42 @@ # @author Sebastian Staudt # @see Application::Base # @since 0.3.0 module DSLMethods - # @return [String] The (first) definition file of the application + # @return [String] The (first) file where the application has been + # defined attr_reader :base_file + # @return [Hash] The active configuration of the application attr_reader :config # @return [String] The absolute path of the application attr_reader :path private + # Checks whether parameter with the given name has been supplied by the + # user on the command-line. + # + # @param [#to_sym] name The name of the parameter to check + # @since 0.2.0 + # + # @example + # flag :status + # command :something do + # print_status if active? :status + # end + def active?(name) + name = name.to_sym + parameter = @global_parameters[name] + parameter = @current_command.parameters[name] if parameter.nil? + return false if parameter.nil? + parameter.send(:active?) + end + alias_method :given?, :active? + # Call another named command with the given arguments # # @param [Symbol] command_name The name of the command to call # @param [Array<String>] args The arguments to pass to the called command # @see Command#run @@ -104,15 +126,15 @@ # executed when this Command is called, i.e. when no command # parameter is given to the application # # @return [Command] The default Command object # @since 0.2.0 - def default(description = nil, &block) - if description.is_a? Symbol - command({ :__default => description }) + def default(arg_count = nil, description = nil, &block) + if arg_count.is_a? Symbol + command({ :__default => arg_count }) else - command(:__default, description, &block) + command(:__default, arg_count, description, &block) end end # Create a new Flag with the given name for the next Command # @@ -137,30 +159,10 @@ else @parameters << Flag.new(self, name, &block) end end - # Checks whether parameter with the given name has been supplied by the - # user on the command-line. - # - # @param [#to_sym] name The name of the parameter to check - # @since 0.2.0 - # - # @example - # flag :status - # command :something do - # print_status if active? :status - # end - def active?(name) - name = name.to_sym - parameter = @global_parameters[name] - parameter = @current_command.parameters[name] if parameter.nil? - return false if parameter.nil? - parameter.send(:active?) - end - alias_method :given?, :active? - # Create a new flag with the given name to be used globally # # Global flags are not bound to any command and can therefore be used # throughout the application with the same result. # @@ -396,10 +398,10 @@ # Output a line of text using +IO#puts+ of the output stream # # @param [String] text The text to write into the output stream # @since 0.2.0 - def puts(text) + def puts(text = nil) ostream.puts text end # Sets an application setting #