Sha256: ba4b8cc8a9a7fd4f4968eb6106848cf379722495ee676cbfa77dacea5a90d59b

Contents?: true

Size: 1.26 KB

Versions: 7

Compression:

Stored size: 1.26 KB

Contents

module Relish
  module Command
    class Config < Base
      
      class Option
        VALID_OPTIONS = %w(project)
        
        def initialize(param)
          @option, @value = param.split(':')
          validate_option
        end
        
        def validate_option
          unless VALID_OPTIONS.include?(@option)
            Relish::Helpers.error "'#{@option}' is not a valid option." +
                                  " Valid options: #{VALID_OPTIONS.join(', ')}"
          end
        end
        
        def to_hash
          {@option => @value}
        end
      end

      desc    'display the contents of your options file'
      command :default do
        puts(if File.exists?(Relish.local_options_file)
          IO.read(Relish.local_options_file)
        else
          "No #{Relish.local_options_file} file exists"
        end)
      end
      
      usage   'config:add <option>:<value>'
      desc    ['add a configuration option to your options file',
               'example: relish config:add project:rspec-core',
               "valid configuration options: #{Option::VALID_OPTIONS.join(', ')}"]
      command :add do
        option = Option.new(@param)
        OptionsFile.new(Relish.local_options_file).store(option.to_hash)
      end
      
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
relish-0.2.0 lib/relish/commands/config.rb
relish-0.1.6 lib/relish/commands/config.rb
relish-0.1.5 lib/relish/commands/config.rb
relish-0.1.4 lib/relish/commands/config.rb
relish-0.1.3 lib/relish/commands/config.rb
relish-0.1.2 lib/relish/commands/config.rb
relish-0.1.1 lib/relish/commands/config.rb