Module: Vaultez::Commands::ConfigCommand

Included in:
Vaultez::CLI
Defined in:
lib/vaultez/commands/config_command.rb

Instance Method Summary collapse

Instance Method Details

#configObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vaultez/commands/config_command.rb', line 4

def config
  if options[:"default-company"]
    client    = Vaultez::Client.new
    companies = client.companies
    company   = companies.find { |company| company["name"] == options[:"default-company"] }

    unless company
      puts "Error: company \"#{options[:"default-company"]}\" not found."
      exit 1
    end

    Vaultez::Config.set("default_company", company["name"])
    puts "Default company set to \"#{company["name"]}\"."
  else
    puts "No config option provided. See `vaultez help config`."
    exit 1
  end
rescue Vaultez::NotAuthenticatedError => error
  puts "Error: #{error.message}"
  exit 1
rescue Vaultez::ApiError => error
  puts "Error: #{error.message}"
  exit 1
end