Method: Forj::Settings.account_set

Defined in:
lib/forj-settings.rb

.account_set(account_name, *p) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/forj-settings.rb', line 151

def self.(, *p)
  config = Lorj::Account.new

  b_dirty = false

  config.ac_load 
  Forj::CloudConnection.connect(config)

  p.flatten!
  p.each do |key_val|
    mkey_val = valid_key_value?(key_val)

    key_to_set = mkey_val[1]
    key_value = mkey_val[2]

    (config, , key_to_set)

    section, key_to_set = Lorj.data.first_section(key_to_set)
    full_key = format('%s/%s', section, key_to_set)

    old_value = config.get(key_to_set)
    s_bef = format_old_key(config, old_value, key_to_set)

    if old_value == key_value
      puts format('%-25s: No update', full_key)
      next
    end
    b_dirty = true

    if key_value == ''
      config.del(key_to_set, :name => 'account')
    else
      config.set(key_to_set, key_value, :name => 'account')
    end

    s_aft = format_new_key(config, key_to_set)

    puts format(
      '%-25s: %s => %s',
      full_key,
      s_bef,
      ANSI.bold + s_aft + ANSI.clear
    )
  end
  config.ac_save if b_dirty
end