Class: Dapp::CLI::Run
Overview
CLI run subcommand
Constant Summary
Constants inherited from Dapp::CLI
Instance Method Summary collapse
- #expected_options ⇒ Object
- #find_option(arg) ⇒ Object
- #read_cli_options(args) ⇒ Object
- #run(argv = ARGV) ⇒ Object
Methods inherited from Base
Methods inherited from Dapp::CLI
Methods included from Helper::Cli
#cli_wrapper, #composite_options, #parse_options, #parse_subcommand, #prepare_subcommand, #required_argument, #run_subcommand
Methods included from Helper::Trivia
class_to_lowercase, #class_to_lowercase, #delete_file, #kwargs, #search_file_upward
Constructor Details
This class inherits a constructor from Dapp::CLI::Base
Instance Method Details
#expected_options ⇒ Object
39 40 41 |
# File 'lib/dapp/cli/run.rb', line 39 def @expected_options ||= .values.map { |opt| { formats: [opt[:long], opt[:short]].compact, with_arg: !opt[:long].split.one? } } end |
#find_option(arg) ⇒ Object
34 35 36 37 |
# File 'lib/dapp/cli/run.rb', line 34 def find_option(arg) .each { |hash| return hash if hash[:formats].any? { |f| f.start_with? arg } } nil end |
#read_cli_options(args) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dapp/cli/run.rb', line 17 def (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 (cli_option) return (args) end end end |
#run(argv = ARGV) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/dapp/cli/run.rb', line 43 def run(argv = ARGV) filtered_args = (argv) pattern = filtered_args.any? && !filtered_args.first.start_with?('-') ? [filtered_args.shift] : [] index = filtered_args.index('--') || filtered_args.count = index.nonzero? ? filtered_args.slice(0..index - 1) : [] command = filtered_args.slice(index + 1..-1) || [] Project.new(cli_options: config, dimgs_patterns: pattern).run(, command) end |