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



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

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



20
21
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
# File 'lib/cyclid/cli/organization/config.rb', line 20

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'
      puts "#{setting['description']}: ".colorize(:cyan) + data
    when 'boolean'
      data = config[name] || 'Not set'
      puts "#{setting['description']}: ".colorize(:cyan) + (data ? 'true' : 'false')
    when 'list'
      puts setting['description'].colorize(:cyan)
      data = config[name]
      if data.empty?
        puts "\tNone"
      else
        data.each do |item|
          puts "\t#{item}"
        end
      end
    when 'hash-list'
      puts setting['description'].colorize(:cyan)
      data = config[name]
      if data.empty?
        puts "\tNone"
      else
        data.each do |item|
          item.each do |k, v|
            puts "\t#{k}: #{v}"
          end
        end
      end
    else
      raise "unknown schema type #{type}"
    end
  end
rescue StandardError => ex
  abort "Failed to get plugin configuration: #{ex}"
end