Class: PartitionGardener::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/partition_gardener/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/partition_gardener/cli.rb', line 10

def initialize(argv)
  @argv = argv.dup
  @options = {
    pretty: false,
    rails: false,
    registry: nil,
    table: nil,
    all: false,
    confirm: false
  }
end

Class Method Details

.start(argv = ARGV) ⇒ Object



6
7
8
# File 'lib/partition_gardener/cli.rb', line 6

def self.start(argv = ARGV)
  new(argv).run
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/partition_gardener/cli.rb', line 22

def run
  parse_options!
  command = @argv.shift || "help"
  @options[:table] ||= @argv.first

  case command
  when "plan"
    load_context!
    print_json(plan_output)
  when "audit"
    load_context!
    print_json(audit_output)
  when "apply"
    abort_with_help("apply requires --confirm (mutates the database)") unless @options[:confirm]
    load_context!
    print_json(apply_output)
  when "help", "-h", "--help"
    print_help
  else
    abort_with_help("unknown command: #{command}")
  end
end