Module: EacCli::DocoptRunner::SubcommandsSupport
- Defined in:
- lib/eac_cli/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
97
98
99
100
101
102
103
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 97
def auto_available_subcommands
self.class.constants
.map { |name| self.class.const_get(name) }
.select { |c| c.instance_of? Class }
.select { |c| c < ::EacCli::DocoptRunner }
.map { |c| c.name.demodulize.underscore.dasherize }
end
|
#available_subcommands ⇒ Object
#check_subcommands_arg ⇒ Object
#docopt_options ⇒ Object
69
70
71
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 69
def docopt_options
super.merge(options_first: true)
end
|
#run_with_subcommand ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 37
def run_with_subcommand
if subcommand_name
check_valid_subcommand
subcommand_run
else
run_without_subcommand
end
end
|
#run_without_subcommand ⇒ Object
105
106
107
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 105
def run_without_subcommand
"Method #{__method__} should be overrided in #{self.class.name}"
end
|
#subcommand ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 46
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
77
78
79
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 77
def subcommand_arg_as_list?
setting_value(:subcommand_arg_as_list, false) || false
end
|
#subcommand_args ⇒ Object
81
82
83
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 81
def subcommand_args
options.fetch(SUBCOMMAND_ARGS_ARG)
end
|
#subcommand_class_name(subcommand) ⇒ Object
73
74
75
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 73
def subcommand_class_name(subcommand)
"#{self.class.name}::#{subcommand.underscore.camelize}"
end
|
#subcommand_program ⇒ Object
85
86
87
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 85
def subcommand_program
subcommand_name
end
|
#subcommand_run ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 54
def subcommand_run
if !subcommand.is_a?(::EacCli::DocoptRunner) &&
subcommand.respond_to?(:run_run)
subcommand.run_run
else
subcommand.run
end
end
|
#target_doc ⇒ Object
63
64
65
66
67
|
# File 'lib/eac_cli/docopt_runner/_subcommands.rb', line 63
def target_doc
super.gsub(SUBCOMMANDS_MACRO,
"#{target_doc_subcommand_arg} [#{SUBCOMMAND_ARGS_ARG}...]") +
"\n" + subcommands_target_doc
end
|