Class: Pebbles::Command::Config
- Defined in:
- lib/pebbles/command/config.rb
Overview
manage app config vars
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#get ⇒ Object
config:get KEY.
-
#index ⇒ Object
config.
-
#set ⇒ Object
config:set KEY1=VALUE1 [KEY2=VALUE2 …].
-
#unset ⇒ Object
config:unset KEY1 [KEY2 …].
Methods inherited from Base
#api, #app, #initialize, namespace
Methods included from Helpers
#action, #ask, #confirm_command, #create_git_remote, #debug, #debugging?, #display, #error, error_with_failure, error_with_failure=, #flatten_hash, #format_bytes, #format_error, #format_with_bang, #git, #has_git?, #has_git_remote?, #has_http_git_entry_in_netrc, #home_directory, #hputs, #json_decode, #launchy, #line_formatter, #longest, #output_with_bang, #running_on_a_mac?, #running_on_windows?, #styled_array, #styled_error, #styled_hash, #styled_header, #update_git_remote, #with_tty
Constructor Details
This class inherits a constructor from Pebbles::Command::Base
Instance Method Details
#get ⇒ Object
config:get KEY
display a config value for an app
Examples:
$ pebbles config:get A one
104 105 106 107 108 109 110 111 112 113 |
# File 'lib/pebbles/command/config.rb', line 104 def get unless key = shift_argument error("Usage: pebbles config:get KEY\nMust specify KEY.") end validate_arguments! vars = api.get_config_vars(app).body key, value = vars.detect {|k,v| k == key} display(value.to_s) end |
#index ⇒ Object
config
display the config vars for an app
-s, –shell # output config vars in shell format
Examples:
$ pebbles config A: one B: two
$ pebbles config –shell A=one B=two
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pebbles/command/config.rb', line 23 def index validate_arguments! vars = if [:shell] api.get_config_vars(app).body else api.request( :expects => 200, :method => :get, :path => "/apps/#{app}/config_vars", :query => { "symbolic" => true } ).body end if vars.empty? display("#{app} has no config vars.") else vars.each {|key, value| vars[key] = value.to_s} if [:shell] vars.keys.sort.each do |key| display(%{#{key}=#{vars[key]}}) end else styled_header("#{app} Config Vars") styled_hash(vars) end end end |
#set ⇒ Object
config:set KEY1=VALUE1 [KEY2=VALUE2 …]
set one or more config vars
Example:
$ pebbles config:set A=one Setting config vars and restarting example… done, v123 A: one
$ pebbles config:set A=one B=two Setting config vars and restarting example… done, v123 A: one B: two
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/pebbles/command/config.rb', line 67 def set unless args.size > 0 and args.all? { |a| a.include?('=') } error("Usage: pebbles config:set KEY1=VALUE1 [KEY2=VALUE2 ...]\nMust specify KEY and VALUE to set.") end vars = args.inject({}) do |vars, arg| key, value = arg.split('=', 2) vars[key] = value vars end action("Setting config vars and restarting #{app}") do api.put_config_vars(app, vars) @status = begin if release = api.get_release(app, 'current').body release['name'] end rescue Pebbles::API::Errors::RequestFailed => e end end vars.each {|key, value| vars[key] = value.to_s} styled_hash(vars) end |
#unset ⇒ Object
config:unset KEY1 [KEY2 …]
unset one or more config vars
$ pebbles config:unset A Unsetting A and restarting example… done, v123
$ pebbles config:unset A B Unsetting A and restarting example… done, v123 Unsetting B and restarting example… done, v124
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/pebbles/command/config.rb', line 126 def unset if args.empty? error("Usage: pebbles config:unset KEY1 [KEY2 ...]\nMust specify KEY to unset.") end args.each do |key| action("Unsetting #{key} and restarting #{app}") do api.delete_config_var(app, key) @status = begin if release = api.get_release(app, 'current').body release['name'] end rescue Pebbles::API::Errors::RequestFailed => e end end end end |