Class: Foobara::CommandConnectors::ShCliConnector::Commands::Help
- Inherits:
-
Foobara::Command
- Object
- Foobara::Command
- Foobara::CommandConnectors::ShCliConnector::Commands::Help
show all
- Defined in:
- foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb
Constant Summary
TruncatedInspect::MAX_LENGTH
Instance Attribute Summary
#is_subcommand
#exception, #outcome
#error_collection
#inputs, #raw_inputs
Instance Method Summary
collapse
install!, reset_all
foobara_class_methods_module_for, foobara_concern?, included
#initialize
#domain_map, #domain_map!, #run_mapped_subcommand!
#run_subcommand!, #subcommand?
#load_entities, #load_records
#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions
#state_machine
#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records
#initialize
#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?
#inspect, truncating
Instance Method Details
#argument ⇒ Object
104
105
106
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 104
def argument
request.argument
end
|
#argument_is_action? ⇒ Boolean
126
127
128
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 126
def argument_is_action?
known_actions.include?(argument)
end
|
#argument_is_command? ⇒ Boolean
112
113
114
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 112
def argument_is_command?
!!command_class
end
|
#command_class ⇒ Object
116
117
118
119
120
121
122
123
124
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 116
def command_class
return @command_class if defined?(@command_class)
@command_class = if single_command_mode?
command_registry.all_transformed_command_classes.first
else
argument && command_registry.transformed_command_from_name(argument)
end
end
|
#command_connector ⇒ Object
39
40
41
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 39
def command_connector
request.command_connector
end
|
#command_registry ⇒ Object
100
101
102
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 100
def command_registry
command_connector.command_registry
end
|
#execute ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 12
def execute
print_usage
if single_command_mode?
print_command_description
print_command_input_options
else
if valid_argument?
if argument_is_command?
print_command_description
print_command_input_options
end
else
print_available_actions
print_available_commands
end
print_global_options
end
output_string
end
|
#known_actions ⇒ Object
TODO: maybe move this up the hierarchy?
131
132
133
134
135
136
137
138
139
140
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 131
def known_actions
%w[
run
describe
manifest
ping
query_git_commit_info
help
]
end
|
#output ⇒ Object
92
93
94
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 92
def output
@output ||= StringIO.new
end
|
#output_string ⇒ Object
188
189
190
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 188
def output_string
output.string
end
|
#print_available_actions ⇒ Object
142
143
144
145
146
147
148
149
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 142
def print_available_actions
output.puts
output.puts "Available actions:"
output.puts
output.puts " #{known_actions.join(", ")}"
output.puts
output.puts "Default action: run"
end
|
#print_available_commands ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 151
def print_available_commands
output.puts
output.puts "Available commands:"
output.puts
table = command_registry.all_transformed_command_classes.map do |command_class|
[" #{command_class.full_command_name}", command_class.description]
end
serializer = Serializers::CliTabularSerializer.new(indent: 2)
output.puts serializer.serialize(table)
end
|
#print_bad_argument_warning ⇒ Object
57
58
59
60
61
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 57
def print_bad_argument_warning
output.puts
output.puts "WARNING: Unexpected argument: #{argument}"
output.puts
end
|
#print_command_description ⇒ Object
172
173
174
175
176
177
178
179
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 172
def print_command_description
description = command_class.description
if description
output.puts
output.puts command_class.description
end
end
|
181
182
183
184
185
186
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 181
def print_command_input_options
output.puts
output.puts single_command_mode? ? "Inputs:" : "Command inputs:"
output.puts
output.puts request.inputs_parser_for(command_class).parser.summarize
end
|
#print_global_options ⇒ Object
165
166
167
168
169
170
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 165
def print_global_options
output.puts
output.puts "Global options:"
output.puts
output.puts request.globalish_parser.parser.summarize
end
|
#print_usage ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 43
def print_usage
if argument
if valid_argument?
print_usage_for_argument
else
print_bad_argument_warning
print_usage_without_argument
end
else
print_usage_without_argument
end
"Usage: #{program_name}"
end
|
#print_usage_for_argument ⇒ Object
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 73
def print_usage_for_argument
usage = "Usage: #{program_name} [GLOBAL_OPTIONS] #{argument} "
usage += case argument
when "run"
"COMMAND_NAME [COMMAND_INPUTS]"
when "describe", "manifest"
"COMMAND_OR_TYPE_NAME"
when "ping", "query_git_commit_info"
""
when "help"
"[ACTION_OR_COMMAND]"
else
"[COMMAND_INPUTS]"
end
output.puts usage
end
|
#print_usage_without_argument ⇒ Object
63
64
65
66
67
68
69
70
71
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 63
def print_usage_without_argument
usage = if single_command_mode?
"[INPUTS]"
else
"[GLOBAL_OPTIONS] [ACTION] [COMMAND_OR_TYPE] [COMMAND_INPUTS]"
end
output.puts "Usage: #{program_name} #{usage}"
end
|
#program_name ⇒ Object
96
97
98
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 96
def program_name
command_connector.program_name
end
|
#single_command_mode? ⇒ Boolean
35
36
37
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 35
def single_command_mode?
command_connector.single_command_mode
end
|
#valid_argument? ⇒ Boolean
108
109
110
|
# File 'foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb', line 108
def valid_argument?
argument && (argument_is_action? || argument_is_command?)
end
|