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
# File 'lib/kong_schema/cli.rb', line 12

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

  version KongSchema::VERSION

  sort_help :manually

  desc 'Apply configuration from a .yml or .json file.'
  arg(:config_file)
  command :up do |c|
    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 |global_options, options, args|
      bail! "Missing path to .yml or .json config file" if args.first.nil?

      up(filepath: args.first, options: options)
    end
  end

  desc 'Reset Kong configuration completely.'
  arg(:config_file)
  command :reset 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 |global_options, options, args|
      bail! "Missing path to .yml or .json config file" if args.first.nil?

      reset(filepath: args.first, options: options)
    end
  end

  super(argv)
end