Class: AppRb::Cli

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Cli

Returns a new instance of Cli.



6
7
8
9
# File 'lib/app-rb/cli.rb', line 6

def initialize(args)
  @args = args
  Thread.abort_on_exception = true
end

Instance Method Details

#runObject



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

def run
  if @args.count < 2
    usage
    exit
  end
  if File.exists?(@args[0])
    config_path = @args.shift
  end

  if @args[0] == "--vault" && File.exists?(@args[1])
    @args.shift
    @vault_file = @args.shift
  elsif File.exists?(File.join(Dir.pwd, "vault.key"))
    @vault_file = File.join(Dir.pwd, "vault.key")
  else
    @vault_file = nil
  end

  command = @args.shift
  config = Config.new(read_yaml(config_path)) if config_path

  if config && AppRb::Util.compare_versions(config.tool_version, AppRb::VERSION) > 0
    puts "FATAL: need at least '#{config.tool_version}' tool version but current version is '#{AppRb::VERSION}'"
    exit -1
  end

  if %w[deploy d].index(command)
    Command.new(config).deploy(@args[2])
  elsif %w[status s].index(command)
    Command.new(config).status
  elsif command == "redeploy"
    Command.new(config).redeploy
  elsif command == "clean"
    Command.new(config).clean
  elsif command == "stop"
    Command.new(config).stop
  elsif %w[run r].index(command)
    Command.new(config).run(@args[2..-1].join(" "))
  elsif command == "cd"
    Command.new(config).cd
  elsif %w[encrypt en e].index(command)
    puts encrypt(@args.shift)
  elsif %w[decrypt de].index(command)
    puts decrypt(@args.shift)
  else
    puts "FATAL: unknown command '#{command}'"
    exit -1
  end
end