Class: KongSchema::CLI

Inherits:
Object
  • Object
show all
Includes:
GLI::App
Defined in:
lib/kong_schema/cli.rb

Instance Method Summary collapse

Instance Method Details

#run(argv) ⇒ Object



12
13
14
15
16
17
18
19
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/kong_schema/cli.rb', line 12

def run(argv)
  program_desc 'Configure Kong from file.'

  version KongSchema::VERSION

  sort_help :manually

  flag([ 'c', 'config' ], {
    desc: 'Path to the configuration file (in place of the first argument.)',
    arg_name: 'FILE'
  })

  desc 'Apply configuration from a .yml or .json file.'
  arg(:config_file)
  command :up do |c|
    c.flag([ 'c', 'config' ], {
      desc: 'Path to the configuration file (in place of the first argument.)',
      arg_name: 'FILE'
    })

    c.flag([ 'k', 'key' ], {
      default_value: 'kong',
      desc: 'The root configuration property key.',
      arg_name: 'NAME'
    })

    c.flag([ 'f', 'format' ], {
      default_value: 'json',
      desc: 'Format to use for reporting objects. Either "json" or "yaml".',
      long_desc: 'Available formats: "json" or "yaml".',
      arg_name: 'FORMAT',
      must_match: %w(json yaml)
    })

    c.switch([ 'confirm' ], {
      default_value: true,
      desc: 'Prompt for confirmation before applying changes.'
    })

    c.action do |globals, options, args|
      filepath = resolve_config_file!(args: args, globals: globals, options: options)

      up(filepath: filepath, options: options)
    end
  end

  desc 'Reset Kong configuration completely.'
  arg(:config_file)
  command :down do |c|
    c.flag([ 'k', 'key' ], {
      default_value: 'kong',
      desc: 'The root configuration property key.',
      arg_name: 'NAME'
    })

    c.switch([ 'confirm' ], {
      default_value: true,
      desc: 'Prompt for confirmation before applying changes.'
    })

    c.action do |globals, options, args|
      filepath = resolve_config_file!(args: args, globals: globals, options: options)

      down(filepath: filepath, options: options)
    end
  end

  super(argv)
end