Class: Cyclid::Cli::Config

Inherits:
Thor
  • Object
show all
Defined in:
lib/cyclid/cli/organization/config.rb

Overview

Commands for managing per. organization configuration

Instance Method Summary collapse

Instance Method Details

#edit(type, plugin) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/cyclid/cli/organization/config.rb', line 70

def edit(type, plugin)
  plugin_data = client.org_config_get(client.config.organization, type, plugin)

  # Inject the schema description into each config item
  schema = plugin_data['schema']
  config = plugin_data['config'].each do |k, v|
    description = ''
    schema.each do |item|
      description = item['description'] if item['name'] == k
    end
    { k => v, 'description' => description }
  end

  # Open a text editor on the configuration
  config = invoke_editor(config)

  # Submit it to the server
  client.org_config_set(client.config.organization, type, plugin, config)
rescue StandardError => ex
  abort "Failed to update plugin configuration: #{ex}"
end

#show(type, plugin) ⇒ Object



22
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cyclid/cli/organization/config.rb', line 22

def show(type, plugin)
  plugin_data = client.org_config_get(client.config.organization, type, plugin)

  config = plugin_data['config']
  schema = plugin_data['schema']
  schema.each do |setting|
    name = setting['name']
    type = setting['type']

    case type
    when 'string', 'integer'
      data = config[name] || 'Not set'
      Formatter.colorize setting['description'], data
    when 'password'
      data = config[name] ? '*' * config[name].length : 'Not set'
      Formatter.colorize setting['description'], data
    when 'boolean'
      data = config[name] || 'Not set'
      Formatter.colorize setting['description'], (data ? 'true' : 'false')
    when 'list'
      Formatter.colorize setting['description']
      data = config[name]
      if data.empty?
        Formatter.puts "\tNone"
      else
        data.each do |item|
          Formatter.puts "\t#{item}"
        end
      end
    when 'hash-list'
      Formatter.colorize setting['description']
      data = config[name]
      if data.empty?
        Formatter.puts "\tNone"
      else
        data.each do |item|
          item.each do |k, v|
            Formatter.puts "\t#{k}: #{v}"
          end
        end
      end
    end
  end
rescue StandardError => ex
  abort "Failed to get plugin configuration: #{ex}"
end