Class: Foobara::CommandConnectors::ShCliConnector::Commands::Help

Inherits:
Foobara::Command
  • Object
show all
Defined in:
foobara-sh-cli-connector-0.0.16/src/sh_cli_connector/commands/help.rb

Constant Summary

Constants included from TruncatedInspect

TruncatedInspect::MAX_LENGTH

Instance Attribute Summary

Attributes included from Foobara::CommandPatternImplementation::Concerns::Subcommands

#is_subcommand

Attributes included from Foobara::CommandPatternImplementation::Concerns::Runtime

#exception, #outcome

Attributes included from Foobara::CommandPatternImplementation::Concerns::Errors

#error_collection

Attributes included from Foobara::CommandPatternImplementation::Concerns::Inputs

#inputs, #raw_inputs

Instance Method Summary collapse

Methods inherited from Foobara::Command

install!, reset_all

Methods included from Foobara::Concern

foobara_class_methods_module_for, foobara_concern?, included

Methods included from Foobara::CommandPatternImplementation::Concerns::Reflection

#initialize

Methods included from Foobara::CommandPatternImplementation::Concerns::DomainMappers

#domain_map, #domain_map!, #run_mapped_subcommand!

Methods included from Foobara::CommandPatternImplementation::Concerns::Subcommands

#run_subcommand!, #subcommand?

Methods included from Foobara::CommandPatternImplementation::Concerns::Entities

#load_entities, #load_records

Methods included from Foobara::CommandPatternImplementation::Concerns::Transactions

#auto_detect_current_transactions, #commit_transaction, #open_transaction, #opened_transactions, #relevant_entity_classes, #rollback_transaction, #transactions

Methods included from Foobara::CommandPatternImplementation::Concerns::StateMachine

#state_machine

Methods included from Foobara::CommandPatternImplementation::Concerns::Runtime

#halt!, #run, #run!, #run_execute, #succeed, #success?, #validate, #validate_records

Methods included from Foobara::CommandPatternImplementation::Concerns::Errors

#initialize

Methods included from Foobara::CommandPatternImplementation::Concerns::Inputs

#cast_and_validate_inputs, #initialize, #method_missing, #respond_to_missing?, #respond_to_missing_for_inputs?

Methods included from TruncatedInspect

#inspect, truncating

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Foobara::CommandPatternImplementation::Concerns::Inputs

Instance Method Details

#argumentObject



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

Returns:

  • (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

Returns:

  • (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_classObject



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_connectorObject



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_registryObject



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

#executeObject



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_actionsObject

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

#outputObject



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_stringObject



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


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


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


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


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


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


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


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


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_nameObject



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

Returns:

  • (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

Returns:

  • (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