Class: Hako::CLI::Oneshot

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

Defined Under Namespace

Classes: Overrides

Instance Method Summary collapse

Instance Method Details

#parse!(argv) ⇒ Object



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/hako/cli.rb', line 170

def parse!(argv)
  @dry_run = false
  @containers = []
  @env = {}
  @verbose = false
  @no_wait = false
  @overrides = Overrides.new
  parser.parse!(argv)
  @definition_path = argv.shift
  @argv = argv

  if @definition_path.nil? || @argv.empty?
    puts parser.help
    exit 1
  end
end

#parserObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'lib/hako/cli.rb', line 187

def parser
  @parser ||= OptionParser.new do |opts|
    opts.banner = 'hako oneshot [OPTIONS] FILE COMMAND ARG...'
    opts.version = VERSION
    opts.on('-t', '--tag=TAG', 'Specify tag') { |v| @tag = v }
    opts.on('-n', '--dry-run', 'Enable dry-run mode') { @dry_run = true }
    opts.on('-c', '--container=NAME', 'Additional container name to start with the app container') { |v| @containers << v }
    opts.on('-v', '--verbose', 'Enable verbose logging') { @verbose = true }
    opts.on('--no-wait', 'Run Docker container in background and return task information depending on scheduler (experimental)') { @no_wait = true }
    opts.on('-e', '--env=NAME=VAL', 'Add environment variable') do |arg|
      k, v = arg.split('=', 2)
      @env[k] = v
    end
    opts.on('--app-cpu=VAL', Integer, 'Override the default cpu for the app container') { |v| @overrides.app_cpu = v }
    opts.on('--app-memory=VAL', Integer, 'Override the default memory for the app container') { |v| @overrides.app_memory = v }
    opts.on('--app-memory-reservation=VAL', Integer, 'Override the default memory reservation for the app container') { |v| @overrides.app_memory_reservation = v }
  end
end

#run(argv) ⇒ Object



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/hako/cli.rb', line 152

def run(argv)
  parse!(argv)
  require 'hako/application'
  require 'hako/commander'

  if @verbose
    Hako.logger.level = Logger::DEBUG
  end

  options =
    if @dry_run
      { expand_variables: false, ask_keys: true }
    else
      {}
    end
  Commander.new(Application.new(@definition_path, options)).oneshot(@argv, tag: @tag, containers: @containers, env: @env, dry_run: @dry_run, no_wait: @no_wait, overrides: @overrides)
end