Sha256: 795f412c2a05fb5606e778e6c7e4909a593f61b2042a5ac172b67541c374c6e3

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'fileutils'

module Proviso::Command
  class Config < Base

    def list
      display "List Config"
      if File.exists?(yaml_file)
        display open(yaml_file, 'r').read
      else
        error "config does not exists run config:create"
      end
    end
    
    def add
      if @args.length == 3
        modify_config_file
        display "successfully added config setting"
      else
        error "section, key and value pair required. eg. config:add [section] [key] [value]"
      end
    end
    
    def update
      if @args.length == 3
        modify_config_file
        display "successfully updated config setting"
      else
        error "section, key and value pair required. eg. config:update [section] [key] [value]"
      end
    end
    
    def create
      data = { "config" => { "hello" => 'world'}}
      FileUtils.mkdir_p(File.join(home_directory, PROVISO_PATH))
      open(yaml_file, 'w') { |f| f.write data.to_yaml }  
      display "created config file"
    end
    
  private
        
    def modify_config_file
      config_hash = YAML.load_file(yaml_file)
      config_hash[@args[0]].merge!({ @args[1] => @args[2] })
      open(yaml_file, 'w') { |f| f.write config_hash.to_yaml }      
    end
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
proviso-0.2.0.beta3 lib/proviso/commands/config.rb