Module: Simple::CLI::Helper
- Extended by:
- Helper
- Included in:
- Helper
- Defined in:
- lib/simple/cli/helper.rb,
lib/simple/cli/helper/help.rb,
lib/simple/cli/helper/short_help.rb,
lib/simple/cli/helper/help_on_command.rb
Instance Method Summary collapse
- #help!(service, verbose:) ⇒ Object
- #help_on_command!(service, command, verbose:) ⇒ Object
- #short_help!(service) ⇒ Object
Instance Method Details
#help!(service, verbose:) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/simple/cli/helper/help.rb', line 3 def help!(service, verbose:) STDERR.puts <<~MSG #{H.binary_name} <command> [ options... ] Commands: #{format_usages usages(service, verbose: verbose), prefix: " "} Default options and commands include: #{format_usages default_usages(service, verbose: verbose), prefix: " "} MSG exit 2 end |
#help_on_command!(service, command, verbose:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/simple/cli/helper/help_on_command.rb', line 7 def help_on_command!(service, command, verbose:) action = H.action_for_command(service, command) parts = [ action.short_description, action_usage(action), action.full_description, ].compact STDERR.puts <<~MSG #{parts.join("\n\n")} MSG exit 2 end |
#short_help!(service) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/simple/cli/helper/short_help.rb', line 3 def short_help!(service) # We check if we have only a few number of actions. In that case we just show the full help instead. actions = ::Simple::Service.actions(service).values actions, hidden_actions = actions.partition(&:short_description) STDERR.puts <<~MSG #{H.binary_name} <command> [ options... ] MSG subcommands = actions.map { |action| "'" + H.action_to_command(action.name) + "'" } msg = "Subcommands include #{subcommands.sort.join(", ")}" msg += " (and an additional #{hidden_actions.count} internal commands)" STDERR.puts <<~MSG #{msg}. Default options and commands include: #{format_usages default_usages(service, verbose: false), prefix: " "} MSG exit 2 end |