Class: S3Config::CLI
- Inherits:
-
Thor
- Object
- Thor
- S3Config::CLI
- Defined in:
- lib/s3_config/cli.rb
Instance Method Summary collapse
- #environments ⇒ Object
- #get(environment = nil, key = nil) ⇒ Object
- #list(environment = nil) ⇒ Object
- #set(environment = nil, *key_values) ⇒ Object
- #unset(environment = nil, *key_values) ⇒ Object
Instance Method Details
#environments ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/s3_config/cli.rb', line 91 def environments return unless validate_installed! @application = S3Config.adapter.new say "Configured Environments" say "=====" @application.environments.each{ |e| puts "- #{e}" } end |
#get(environment = nil, key = nil) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/s3_config/cli.rb', line 59 def get(environment=nil, key=nil) return unless validate_installed! return error "Environment required. eg: config get production KEY" if environment.nil? return error "Key required. eg: config get production KEY" if key.nil? key = key.upcase @application = S3Config.adapter.new environment: environment value = @application.read key say "#{key} (#{environment})" say "=====" say value end |
#list(environment = nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/s3_config/cli.rb', line 21 def list(environment=nil) return unless validate_installed! return error "Environment required. eg: config list production" if environment.nil? @application = S3Config.adapter.new environment: environment version = @application.latest_version say "#{environment} (v#{version})" say "=====" @application.sort.each do |k,v| say "#{k}=#{v}" end end |
#set(environment = nil, *key_values) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/s3_config/cli.rb', line 34 def set(environment=nil, *key_values) return unless validate_installed! return error "Environment required. eg: config set production KEY=value" if environment.nil? @application = S3Config.adapter.new environment: environment version = @application.latest_version key_values.each do |key_value| key, value = key_value.split '=' return error "Key required. eg: config set production KEY=value" if key.nil? key.upcase! if value.nil? error "Value required. eg: config set production KEY=value" say "Use `config unset` to delete a key" return end @application.write key, value say "Set #{key}=#{value} (#{environment})" end say "=====" if @application.latest_version != version say "New version: v#{@application.latest_version}" end say "Use version: v#{@application.latest_version}" end |
#unset(environment = nil, *key_values) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/s3_config/cli.rb', line 72 def unset(environment=nil, *key_values) return unless validate_installed! return error "Environment required. eg: config unset production KEY" if environment.nil? return error "Key required. eg: config unset production KEY" if key_values.empty? @application = S3Config.adapter.new environment: environment version = @application.latest_version key_values.each do |key| key = key.upcase @application.delete key say "Removed #{key} (#{environment})" end say "=====" if @application.latest_version != version say "New version: v#{@application.latest_version}" end say "Use version: v#{@application.latest_version}" end |