Class: Dapp::Dimg::CLI::Run
- Inherits:
-
Base
show all
- Defined in:
- lib/dapp/dimg/cli/run.rb
Constant Summary
Constants inherited
from CLI
CLI::SUBCOMMANDS
Instance Method Summary
collapse
Methods inherited from Base
#run_method
Methods inherited from CLI::Base
#initialize
Methods inherited from CLI
#initialize
#cli_wrapper, #composite_options, #parse_options, #parse_subcommand, #prepare_subcommand, #required_argument, #run_subcommand
class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs, #search_file_upward
Instance Method Details
#expected_options ⇒ Object
44
45
46
|
# File 'lib/dapp/dimg/cli/run.rb', line 44
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) ⇒ Object
39
40
41
42
|
# File 'lib/dapp/dimg/cli/run.rb', line 39
def find_option(arg)
expected_options.each { |hash| return hash if hash[:formats].any? { |f| f.start_with? arg } }
nil
end
|
#read_cli_options(args) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/dapp/dimg/cli/run.rb', line 22
def read_cli_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_cli_options(args)
end
end
end
|
#run(argv = ARGV) ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/dapp/dimg/cli/run.rb', line 48
def run(argv = ARGV)
filtered_args = read_cli_options(argv)
pattern = 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) || []
::Dapp::Dapp.new(cli_options: config, dimgs_patterns: pattern).run(docker_options, command)
end
|