Class: Seira::Runner

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

Constant Summary collapse

CATEGORIES =
{
  'secrets' => Seira::Secrets,
  'pods' => Seira::Pods,
  'db' => Seira::Db,
  'redis' => Seira::Redis,
  'memcached' => Seira::Memcached,
  'app' => Seira::App,
  'cluster' => Seira::Cluster,
  'proxy' => Seira::Proxy,
  'setup' => Seira::Setup
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRunner

Pop from beginning repeatedly for the first 4 main args, and then take the remaining back to original order for the remaining args



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
# File 'lib/seira.rb', line 39

def initialize
  @settings = Seira::Settings.new

  reversed_args = ARGV.reverse.map(&:chomp)

  # The cluster and proxy command are not specific to any app, so that
  # arg is not in the ARGV array and should be skipped over
  if ARGV[0] == 'help'
    @category = reversed_args.pop
  elsif ARGV[1] == 'cluster'
    cluster = reversed_args.pop
    @category = reversed_args.pop
    @action = reversed_args.pop
    @args = reversed_args.reverse
  elsif ARGV[1] == 'proxy'
    cluster = reversed_args.pop
    @category = reversed_args.pop
  elsif ARGV[0] == 'setup'
    @category = reversed_args.pop
    cluster = reversed_args.pop
  else
    cluster = reversed_args.pop
    @app = reversed_args.pop
    @category = reversed_args.pop
    @action = reversed_args.pop
    @args = reversed_args.reverse
  end

  @cluster = @settings.full_cluster_name_for_shorthand(cluster)
  @project = @settings.project_for_cluster(@cluster)
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



34
35
36
# File 'lib/seira.rb', line 34

def action
  @action
end

#appObject (readonly)

Returns the value of attribute app.



34
35
36
# File 'lib/seira.rb', line 34

def app
  @app
end

#argsObject (readonly)

Returns the value of attribute args.



34
35
36
# File 'lib/seira.rb', line 34

def args
  @args
end

#categoryObject (readonly)

Returns the value of attribute category.



34
35
36
# File 'lib/seira.rb', line 34

def category
  @category
end

#clusterObject (readonly)

Returns the value of attribute cluster.



34
35
36
# File 'lib/seira.rb', line 34

def cluster
  @cluster
end

#projectObject (readonly)

Returns the value of attribute project.



34
35
36
# File 'lib/seira.rb', line 34

def project
  @project
end

#settingsObject (readonly)

Returns the value of attribute settings.



35
36
37
# File 'lib/seira.rb', line 35

def settings
  @settings
end

Instance Method Details

#runObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/seira.rb', line 71

def run
  if category == 'help'
    run_base_help
    exit(0)
  elsif category == 'setup'
    Seira::Setup.new(arg: cluster, settings: settings).run
    exit(0)
  end

  base_validations

  command_class = CATEGORIES[category]

  unless command_class
    puts "Unknown command specified. Usage: 'seira <cluster> <app> <category> <action> <args..>'."
    puts "Valid categories are: #{CATEGORIES.keys.join(', ')}"
    exit(1)
  end

  if category == 'cluster'
    perform_action_validation(klass: command_class, action: action)
    command_class.new(action: action, args: args, context: passed_context, settings: settings).run
  elsif category == 'proxy'
    command_class.new.run
  else
    perform_action_validation(klass: command_class, action: action)
    command_class.new(app: app, action: action, args: args, context: passed_context).run
  end
end