Class: Mortar::Command::Config
- Defined in:
- lib/mortar/command/config.rb
Overview
manage project config variables
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, #ask_public, #config_parameters, #get_error_message_context, #git, #initialize, #initialize_embedded_project, #luigi_parameters, namespace, #pig_parameters, #project, #register_api_call, #register_do, #register_project, #spark_script_arguments, #validate_project_name, #validate_project_structure
Methods included from Helpers
#action, #ask, #confirm, #copy_if_not_present_at_dest, #default_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #display_with_indent, #download_to_file, #ensure_dir_exists, #error, error_with_failure, error_with_failure=, extended, extended_into, #format_bytes, #format_date, #format_with_bang, #full_host, #get_terminal_environment, #home_directory, #host, #hprint, #hputs, included, included_into, #installed_with_omnibus?, #json_decode, #json_encode, #line_formatter, #longest, #output_with_bang, #pending_github_team_state_message, #quantify, #redisplay, #retry_on_exception, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #test_name, #ticking, #time_ago, #truncate, #warning, #with_tty, #write_to_file
Constructor Details
This class inherits a constructor from Mortar::Command::Base
Instance Method Details
#get ⇒ Object
config:get KEY
display a config var for a project
Examples:
$ mortar config:get MY_CONFIG_VAR one
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mortar/command/config.rb', line 81 def get unless key = shift_argument error("Usage: mortar config:get KEY\nMust specify KEY.") end validate_arguments! project_name = [:project] || project.name vars = api.get_config_vars(project_name).body['config'] key_name, value = vars.detect {|k,v| k == key} unless key_name error("Config var #{key} is not defined for project #{project_name}.") end display(value.to_s) end |
#index ⇒ Object
config
Display the config vars for a project.
-s, –shell # output config vars in shell format.
$ mortar config A: one B: three
Project config settings overriden by user config
B: two
$ mortar config –shell A=one B=three
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/mortar/command/config.rb', line 45 def index validate_arguments! project_name = [:project] || project.name config_body = api.get_config_vars(project_name).body vars = config_body['config'] shadow_vars = config_body['shadow_config'] || {} if vars.empty? display("#{project_name} 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("#{project_name} Config Vars") styled_hash(vars) unless shadow_vars.empty? shadow_vars.each {|key, value| shadow_vars[key] = value.to_s} display("\n") styled_header("Project config settings overriden by user config") styled_hash(shadow_vars) end end end end |
#set ⇒ Object
config:set KEY1=VALUE1 [KEY2=VALUE2 …]
Set one or more config vars
-u, –user # Set the config value for your user. Only visible to your user
# and will apply to all projects. Will overwrite a project config
# variable with the same key.
Example:
$ mortar config:set A=one Setting config vars… done. A: one
$ mortar config:set A=one B=two Setting config vars… done. A: one B: two
$ mortar config:set B=three -u Setting config vars… done. A: one B: three
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/mortar/command/config.rb', line 121 def set unless args.size > 0 and args.all? { |a| a.include?('=') } error("Usage: mortar 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 if [:user] action("Setting config vars for your user") do api.put_user_config_vars(vars) end else project_name = [:project] || project.name action("Setting config vars for project #{project_name}") do api.put_config_vars(project_name, vars) 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
-u, –user # Unset the config value for your user. Only affecsts your user
# and will apply to all projects.
$ mortar config:unset A Unsetting A… done
$ mortar config:unset A B Unsetting A… done Unsetting B… done
$ mortar config:unset A B -u Unsetting A… done Unsetting B… done
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/mortar/command/config.rb', line 168 def unset if args.empty? error("Usage: mortar config:unset KEY1 [KEY2 ...]\nMust specify KEY to unset.") end if [:user] args.each do |key| action("Unsetting #{key} for your user") do api.delete_user_config_var(key) end end else project_name = [:project] || project.name args.each do |key| action("Unsetting #{key} for project #{project_name}") do api.delete_config_var(project_name, key) end end end end |