Module: Appfront::Command

Defined in:
lib/appfront/command.rb

Defined Under Namespace

Classes: Alias, Auth, Base, Clusters, Config, Deploys, Domains, Help, Logs, Providers, Ps

Class Method Summary collapse

Class Method Details

.run(args, opts) ⇒ Object



8
9
10
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
60
61
62
63
64
65
66
# File 'lib/appfront/command.rb', line 8

def self.run(args, opts)
  cmd  = args.shift

  unless cmd
    Appfront::Command::Help.root_help
    exit 0
  end

  klass, act = cmd.split ':', 2
  klass = klass.downcase

  if klass == 'help'
    m = args.shift || 'root_help'
    m = m.split(':')[0]

    Appfront::Command::Help.send m
    exit 0
  end

  unless (klass == 'login' or cmd == 'auth:login' or klass == 'signup')
    Appfront::Command::Auth.authenticate!
  end

  Appfront::Command::Base.api = Appfront::API.new

  if Appfront::Command::Alias.respond_to? klass
    Appfront::Command::Alias.send klass.downcase, args, opts
    exit 0
  end

  act ||= 'list'

  begin
    klass = "Appfront::Command::#{klass.capitalize}".constantize
  rescue
    unless Appfront::Command::Base.respond_to? cmd
      puts 'Invalid command: ' + cmd
      exit 1
    end

    return Appfront::Command::Base.send cmd
  end

  unless klass.respond_to? act
    puts 'Invalid action ' + act
    exit 1
  end

  method_args = klass.method(act).arity

  case method_args
  when 0
    klass.send act
  when 1
    klass.send act, opts
  when 2
    klass.send act, args, opts
  end
end