Sha256: 78e9a0186a630492d8c712a4cb36b2e97caf900573665453acefe5527fc8da10

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

require 'json'

module Loom
	class Config < Hash

		# load a new config option 
		def self.load(path)
			config = Config.new
			config.merge! JSON.parse(File.read(path))
		end

		def save!(path)
			File.open(path , 'w') do |f| 
	      		f.write(JSON.pretty_generate(self)) 
	    	end
		end

	end
end

command :config do |c|

	c.syntax = 'loom config [options]'
	c.summary = 'add, edit and remove configuration options for loomcli'
	c.description = 'add and edit configuration options for loomcli'
	c.option '--global', 'sets the global configuration variable'
	c.example 'set local variable', 'loom config foo bar'
	c.example 'set global variable', 'loom config --global foo bar'

	c.action do |args, options|

		config_path = options.global ? GLOBAL_CONFIG_PATH : CONFIG_PATH

		ensure_configured! unless options.global

		loom_config = Loom::Config.load config_path

		if !(args[0] && args[1])
			say "Invalid number of arguments. Example: loom config foo bar"
      exit 1
		else
	  	loom_config[args[0]] = args[1]
	  	loom_config.save! config_path
		end

	end
  
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
loom-0.0.46 lib/loom/config.rb
loom-0.0.45 lib/loom/config.rb
loom-0.0.43 lib/loom/config.rb