Module: EacRubyUtils::Console::DocoptRunner::SubcommandsSupport
- Defined in:
- lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb
Defined Under Namespace
Modules: SubcommandArgAsArg, SubcommandArgAsList
Constant Summary
collapse
- EXTRA_AVAILABLE_SUBCOMMANDS_METHOD_NAME =
:extra_available_subcommands
Instance Method Summary
collapse
Instance Method Details
#auto_available_subcommands ⇒ Object
89
90
91
92
93
94
95
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 89
def auto_available_subcommands
self.class.constants
.map { |name| self.class.const_get(name) }
.select { |c| c.instance_of? Class }
.select { |c| c < ::EacRubyUtils::Console::DocoptRunner }
.map { |c| c.name.demodulize.underscore.dasherize }
end
|
#available_subcommands ⇒ Object
#check_subcommands_arg ⇒ Object
#docopt_options ⇒ Object
61
62
63
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 61
def docopt_options
super.merge(options_first: true)
end
|
#run_with_subcommand ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 38
def run_with_subcommand
if subcommand_name
check_valid_subcommand
subcommand.run
else
run_without_subcommand
end
end
|
#run_without_subcommand ⇒ Object
97
98
99
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 97
def run_without_subcommand
"Method #{__method__} should be overrided in #{self.class.name}"
end
|
#subcommand ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 47
def subcommand
@subcommand ||= subcommand_class_name(subcommand_name).constantize.create(
argv: subcommand_args,
program_name: subcommand_program,
parent: self
)
end
|
#subcommand_arg_as_list? ⇒ Boolean
69
70
71
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 69
def subcommand_arg_as_list?
setting_value(:subcommand_arg_as_list, false) || false
end
|
#subcommand_args ⇒ Object
73
74
75
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 73
def subcommand_args
options.fetch(SUBCOMMAND_ARGS_ARG)
end
|
#subcommand_class_name(subcommand) ⇒ Object
65
66
67
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 65
def subcommand_class_name(subcommand)
"#{self.class.name}::#{subcommand.underscore.camelize}"
end
|
#subcommand_program ⇒ Object
77
78
79
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 77
def subcommand_program
subcommand_name
end
|
#target_doc ⇒ Object
55
56
57
58
59
|
# File 'lib/eac_ruby_utils/console/docopt_runner/_subcommands.rb', line 55
def target_doc
super.gsub(SUBCOMMANDS_MACRO,
"#{target_doc_subcommand_arg} [#{SUBCOMMAND_ARGS_ARG}...]") +
"\n" + subcommands_target_doc
end
|