Sha256: 29a8b08fbd28e4b003b60bb66c3ae73a5b41cb6a344871933868a168d304ce92

Contents?: true

Size: 1.19 KB

Versions: 21

Compression:

Stored size: 1.19 KB

Contents

module Relish
  module Command
    module Dsl
      class HelpText
        
        class << self
          attr_accessor :current_command, :next_usage, :next_description
        
          def add(name, command)
            self.current_command = name
            commands[command] = [] unless commands.key?(command)
            commands[command].push(get_next_usage => get_next_description)
            reset_accessors
          end
        
          def get_next_usage
            next_usage or current_command.to_s
          end
        
          def get_next_description
            next_description || raise(
              "please set a description for #{current_command.inspect}"
            )
          end
        
          def commands
            @commands ||= {}
          end
        
          def reset_accessors
            self.current_command = self.next_usage = self.next_description = nil
          end
          
          def clear_commands
            @commands = {}
          end
          
          def max_usage_length
            commands.values.map {|v|
              v.map {|v| v.keys.to_s.length }.max
            }.max
          end
        end
        
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
relish-0.7.1 lib/relish/commands/dsl/help_text.rb
relish-0.7 lib/relish/commands/dsl/help_text.rb
relish-0.6 lib/relish/commands/dsl/help_text.rb
relish-0.5.3 lib/relish/commands/dsl/help_text.rb
relish-0.5.2 lib/relish/commands/dsl/help_text.rb
relish-0.5.1 lib/relish/commands/dsl/help_text.rb
relish-0.5.0 lib/relish/commands/dsl/help_text.rb
relish-0.4.0 lib/relish/commands/dsl/help_text.rb
relish-0.3.0 lib/relish/commands/dsl/help_text.rb
relish-0.3.0.pre lib/relish/commands/dsl/help_text.rb
relish-0.2.3 lib/relish/commands/dsl/help_text.rb
relish-0.2.2 lib/relish/commands/dsl/help_text.rb
relish-0.2.1 lib/relish/commands/dsl/help_text.rb
relish-0.2.0 lib/relish/commands/dsl/help_text.rb
relish-0.1.6 lib/relish/commands/dsl/help_text.rb
relish-0.1.5 lib/relish/commands/dsl/help_text.rb
relish-0.1.4 lib/relish/commands/dsl/help_text.rb
relish-0.1.3 lib/relish/commands/dsl/help_text.rb
relish-0.1.2 lib/relish/commands/dsl/help_text.rb
relish-0.1.1 lib/relish/commands/dsl/help_text.rb