Class: Seira::Runner
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, 'node-pools' => Seira::NodePools }.freeze
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#initialize ⇒ Runner
constructor
Pop from beginning repeatedly for the first 4 main args, and then take the remaining back to original order for the remaining args.
- #run ⇒ Object
Methods included from Commands
#gcloud, gcloud, kubectl, #kubectl
Constructor Details
#initialize ⇒ Runner
Pop from beginning repeatedly for the first 4 main args, and then take the remaining back to original order for the remaining args
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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/seira.rb', line 50 def initialize @settings = Seira::Settings.new reversed_args = ARGV.reverse.map(&:chomp) # The cluster, node-pools 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] == 'node-pools' 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 # If cluster is nil, we'll show an error message later on. unless @cluster.nil? unless category == 'setup' @project = @settings.project_for_cluster(@cluster) end end end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
45 46 47 |
# File 'lib/seira.rb', line 45 def action @action end |
#app ⇒ Object (readonly)
Returns the value of attribute app.
45 46 47 |
# File 'lib/seira.rb', line 45 def app @app end |
#args ⇒ Object (readonly)
Returns the value of attribute args.
45 46 47 |
# File 'lib/seira.rb', line 45 def args @args end |
#category ⇒ Object (readonly)
Returns the value of attribute category.
45 46 47 |
# File 'lib/seira.rb', line 45 def category @category end |
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
45 46 47 |
# File 'lib/seira.rb', line 45 def cluster @cluster end |
#project ⇒ Object (readonly)
Returns the value of attribute project.
45 46 47 |
# File 'lib/seira.rb', line 45 def project @project end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
46 47 48 |
# File 'lib/seira.rb', line 46 def settings @settings end |
Instance Method Details
#run ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/seira.rb', line 99 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 == 'node-pools' 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 |