Class: Seira::Runner

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

Constant Summary collapse

CATEGORIES =
{
  'secrets' => Seira::Secrets,
  'pods' => Seira::Pods,
  'jobs' => Seira::Jobs,
  '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



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
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/seira.rb', line 43

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
    @args = reversed_args.reverse
  else
    cluster = reversed_args.pop
    @app = reversed_args.pop
    @category = reversed_args.pop
    @action = reversed_args.pop
    @args = reversed_args.reverse
  end

  @cluster =
    if category == 'setup'
      cluster
    else
      @settings.full_cluster_name_for_shorthand(cluster)
    end

  unless category == 'setup'
    @project = @settings.project_for_cluster(@cluster)
  end
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



38
39
40
# File 'lib/seira.rb', line 38

def action
  @action
end

#appObject (readonly)

Returns the value of attribute app.



38
39
40
# File 'lib/seira.rb', line 38

def app
  @app
end

#argsObject (readonly)

Returns the value of attribute args.



38
39
40
# File 'lib/seira.rb', line 38

def args
  @args
end

#categoryObject (readonly)

Returns the value of attribute category.



38
39
40
# File 'lib/seira.rb', line 38

def category
  @category
end

#clusterObject (readonly)

Returns the value of attribute cluster.



38
39
40
# File 'lib/seira.rb', line 38

def cluster
  @cluster
end

#projectObject (readonly)

Returns the value of attribute project.



38
39
40
# File 'lib/seira.rb', line 38

def project
  @project
end

#settingsObject (readonly)

Returns the value of attribute settings.



39
40
41
# File 'lib/seira.rb', line 39

def settings
  @settings
end

Instance Method Details

#runObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/seira.rb', line 84

def run
  if category == 'help'
    run_base_help
    exit(0)
  elsif category == 'setup'
    Seira::Setup.new(target: cluster, args: args, 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