Class: Convoy::Formatter::Command
- Inherits:
-
Object
- Object
- Convoy::Formatter::Command
- Defined in:
- lib/convoy/formatter/command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#setup ⇒ Object
readonly
Returns the value of attribute setup.
Instance Method Summary collapse
- #aliases ⇒ Object
- #child_commands ⇒ Object
- #description ⇒ Object
- #has_aliases? ⇒ Boolean
- #has_child_commands? ⇒ Boolean
-
#initialize(command_name, setup, context) ⇒ Command
constructor
A new instance of Command.
- #name_with_aliases ⇒ Object
- #outline ⇒ Object
- #requires_arguments? ⇒ Boolean
- #script_name ⇒ Object
- #summary ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(command_name, setup, context) ⇒ Command
Returns a new instance of Command.
6 7 8 9 10 |
# File 'lib/convoy/formatter/command.rb', line 6 def initialize(command_name, setup, context) @setup = setup @context = context @name = command_name.to_sym end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
4 5 6 |
# File 'lib/convoy/formatter/command.rb', line 4 def context @context end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/convoy/formatter/command.rb', line 4 def name @name end |
#setup ⇒ Object (readonly)
Returns the value of attribute setup.
4 5 6 |
# File 'lib/convoy/formatter/command.rb', line 4 def setup @setup end |
Instance Method Details
#aliases ⇒ Object
28 29 30 |
# File 'lib/convoy/formatter/command.rb', line 28 def aliases @aliases ||= setup.command_aliases_for(name, context) end |
#child_commands ⇒ Object
40 41 42 |
# File 'lib/convoy/formatter/command.rb', line 40 def child_commands @child_commands ||= setup.canonical_command_names_for(context) || [] end |
#description ⇒ Object
20 21 22 |
# File 'lib/convoy/formatter/command.rb', line 20 def description @description ||= setup.command_description_for(name, context) || "" end |
#has_aliases? ⇒ Boolean
32 33 34 |
# File 'lib/convoy/formatter/command.rb', line 32 def has_aliases? aliases && aliases.size > 0 ? true : false end |
#has_child_commands? ⇒ Boolean
44 45 46 |
# File 'lib/convoy/formatter/command.rb', line 44 def has_child_commands? child_commands.length > 0 end |
#name_with_aliases ⇒ Object
12 13 14 |
# File 'lib/convoy/formatter/command.rb', line 12 def name_with_aliases [aliases, name].flatten.join(', ') end |
#outline ⇒ Object
16 17 18 |
# File 'lib/convoy/formatter/command.rb', line 16 def outline summary.empty? ? description : summary end |
#requires_arguments? ⇒ Boolean
48 49 50 |
# File 'lib/convoy/formatter/command.rb', line 48 def requires_arguments? @requires_arguments ||= setup.arguments_required_for(context) end |
#script_name ⇒ Object
36 37 38 |
# File 'lib/convoy/formatter/command.rb', line 36 def script_name [canonical_script_name, context].flatten.join(" ") end |
#summary ⇒ Object
24 25 26 |
# File 'lib/convoy/formatter/command.rb', line 24 def summary @summary ||= setup.command_summary_for(name, context) || "" end |
#usage ⇒ Object
52 53 54 |
# 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 |