Class: Heroku::Command::Config

Inherits:
Base
  • Object
show all
Defined in:
lib/heroku/command/config.rb

Overview

manage app config vars

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#api, #app, #heroku, #initialize, namespace

Methods included from Helpers

#action, #ask, #confirm, #confirm_billing, #confirm_command, #create_git_remote, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #host_name, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty

Constructor Details

This class inherits a constructor from Heroku::Command::Base

Instance Method Details

#getObject

config:get KEY

display a config value for an app

Examples:

$ pogo config:get A one



94
95
96
97
98
99
100
101
102
103
# File 'lib/heroku/command/config.rb', line 94

def get
  unless key = shift_argument
    error("Usage: pogo 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

#indexObject

config

display the config vars for an app

-s, –shell # output config vars in shell format

Examples:

$ pogo config A: one B: two

$ pogo config –shell A=one B=two



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/heroku/command/config.rb', line 23

def index
  validate_arguments!

  vars = api.get_config_vars(app).body
  if vars.empty?
    display("#{app} has no config vars.")
  else
    vars.each {|key, value| vars[key] = value.to_s}
    if options[:shell]
      vars.keys.sort.each do |key|
        display(%{#{key}=#{vars[key]}})
      end
    else
      styled_header("#{app} Config Vars")
      styled_hash(vars)
    end
  end
end

#setObject

config:set KEY1=VALUE1 [KEY2=VALUE2 …]

set one or more config vars

Example:

$ pogo config:set A=one Setting config vars and restarting example… done, v123 A: one

$ pogo config:set A=one B=two Setting config vars and restarting example… done, v123 A: one B: two



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/heroku/command/config.rb', line 57

def set
  unless args.size > 0 and args.all? { |a| a.include?('=') }
    error("Usage: pogo 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 Heroku::API::Errors::RequestFailed => e
    end
  end

  vars.each {|key, value| vars[key] = value.to_s}
  styled_hash(vars)
end

#unsetObject

config:unset KEY1 [KEY2 …]

unset one or more config vars

$ pogo config:unset A Unsetting A and restarting example… done, v123

$ pogo config:unset A B Unsetting A and restarting example… done, v123 Unsetting B and restarting example… done, v124



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/heroku/command/config.rb', line 116

def unset
  if args.empty?
    error("Usage: pogo 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 Heroku::API::Errors::RequestFailed => e
      end
    end
  end
end