Class: S3Config::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/s3_config/cli.rb

Instance Method Summary collapse

Instance Method Details

#environmentsObject



87
88
89
90
91
92
93
# File 'lib/s3_config/cli.rb', line 87

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



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/s3_config/cli.rb', line 57

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.each do |k,v|
    say "#{k}=#{v}"
  end
end

#set(environment = nil, key_value = "") ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/s3_config/cli.rb', line 34

def set(environment=nil, key_value="")
  return unless validate_installed!
  return error "Environment required. eg: config set production KEY=value" if environment.nil?
  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 = S3Config.adapter.new environment: environment
  version = @application.latest_version
  @application.write key, value
  say "Set #{key}=#{value} (#{environment})"
  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 = nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/s3_config/cli.rb', line 70

def unset(environment=nil, key=nil)
  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.nil?
  key = key.upcase
  @application = S3Config.adapter.new environment: environment
  version = @application.latest_version
  @application.delete key
  say "Removed #{key} (#{environment})"
  say "====="
  if @application.latest_version != version
    say "New version: v#{@application.latest_version}"
  end
  say "Use version: v#{@application.latest_version}"
end