class Dapp::Dimg::CLI::Command::Dimg::Run

Public Instance Methods

expected_options() click to toggle source
# File lib/dapp/dimg/cli/command/dimg/run.rb, line 45
def expected_options
  @expected_options ||= options.values.map { |opt| { formats: [opt[:long], opt[:short]].compact, with_arg: !opt[:long].split.one? } }
end
find_option(arg) click to toggle source
# File lib/dapp/dimg/cli/command/dimg/run.rb, line 40
def find_option(arg)
  expected_options.each { |hash| return hash if hash[:formats].any? { |f| f.start_with? arg } }
  nil
end
log_running_time() click to toggle source
# File lib/dapp/dimg/cli/command/dimg/run.rb, line 68
def log_running_time
  false
end
read_options(args) click to toggle source
# File lib/dapp/dimg/cli/command/dimg/run.rb, line 23
def read_options(args)
  self.class.cli_wrapper(self) do
    args.each_with_index do |arg, i|
      next if arg == '--'
      next if (key = find_option(arg)).nil?
      cli_option = []
      cli_option << args.slice!(i)
      if key[:with_arg]
        raise OptionParser::InvalidOption if args.count < i + 1
        cli_option << args.slice!(i)
      end
      parse_options(cli_option)
      return read_options(args)
    end
  end
end
run(argv = ARGV) click to toggle source
# File lib/dapp/dimg/cli/command/dimg/run.rb, line 49
def run(argv = ARGV)
  filtered_args = read_options(argv)
  patterns = filtered_args.any? && !filtered_args.first.start_with?('-') ? [filtered_args.shift] : []
  index = filtered_args.index('--') || filtered_args.count
  docker_options = index.nonzero? ? filtered_args.slice(0..index - 1) : []
  command = filtered_args.slice(index + 1..-1) || []

  if docker_options.empty? && command.empty?
    docker_options = %w(-ti --rm)
    command = %w(/bin/bash)
  end

  stage_name = config.delete(:stage)

  run_dapp_command(nil, options: cli_options(dimgs_patterns: patterns)) do |dapp|
    dapp.run(stage_name, docker_options, command)
  end
end