class Convoy::Formatter::Command
Attributes
context[R]
name[R]
setup[R]
Public Class Methods
new(command_name, setup, context)
click to toggle source
# File lib/convoy/formatter/command.rb, line 6 def initialize(command_name, setup, context) @setup = setup @context = context @name = command_name.to_sym end
Public Instance Methods
aliases()
click to toggle source
# File lib/convoy/formatter/command.rb, line 28 def aliases @aliases ||= setup.command_aliases_for(name, context) end
child_commands()
click to toggle source
# File lib/convoy/formatter/command.rb, line 40 def child_commands @child_commands ||= setup.canonical_command_names_for(context) || [] end
description()
click to toggle source
# File lib/convoy/formatter/command.rb, line 20 def description @description ||= setup.command_description_for(name, context) || "" end
has_aliases?()
click to toggle source
# File lib/convoy/formatter/command.rb, line 32 def has_aliases? aliases && aliases.size > 0 ? true : false end
has_child_commands?()
click to toggle source
# File lib/convoy/formatter/command.rb, line 44 def has_child_commands? child_commands.length > 0 end
name_with_aliases()
click to toggle source
# File lib/convoy/formatter/command.rb, line 12 def name_with_aliases [aliases, name].flatten.join(', ') end
outline()
click to toggle source
# File lib/convoy/formatter/command.rb, line 16 def outline summary.empty? ? description : summary end
requires_arguments?()
click to toggle source
# File lib/convoy/formatter/command.rb, line 48 def requires_arguments? @requires_arguments ||= setup.arguments_required_for(context) end
script_name()
click to toggle source
# File lib/convoy/formatter/command.rb, line 36 def script_name [canonical_script_name, context].flatten.join(" ") end
summary()
click to toggle source
# File lib/convoy/formatter/command.rb, line 24 def summary @summary ||= setup.command_summary_for(name, context) || "" end
usage()
click to toggle source
# File lib/convoy/formatter/command.rb, line 52 def usage [script_name_usage_string, parent_commands_usage_string, child_command_usage_string, arguments_usage_string].flatten.reject(&:empty?).join(" ") end
Private Instance Methods
alias_string()
click to toggle source
# File lib/convoy/formatter/command.rb, line 82 def alias_string @alias_string ||= aliases.join(", ") if has_aliases? end
arguments_usage_string()
click to toggle source
# File lib/convoy/formatter/command.rb, line 70 def arguments_usage_string requires_arguments? ? "arguments" : "[arguments]" end
canonical_script_name()
click to toggle source
# File lib/convoy/formatter/command.rb, line 78 def canonical_script_name File.basename($0) end
child_command_usage_string()
click to toggle source
# File lib/convoy/formatter/command.rb, line 66 def child_command_usage_string has_child_commands? ? "command [command_options]" : "" end
command_with_options(command_name)
click to toggle source
# File lib/convoy/formatter/command.rb, line 74 def command_with_options(command_name) "#{command_name} [#{command_name}_options]" end
parent_commands_usage_string()
click to toggle source
# File lib/convoy/formatter/command.rb, line 62 def parent_commands_usage_string context.map { |command_name| command_with_options(command_name) }.join(" ") end
script_name_usage_string()
click to toggle source
# File lib/convoy/formatter/command.rb, line 58 def script_name_usage_string "#{canonical_script_name} [options]" end