Class: Escort::Formatter::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/escort/formatter/command.rb

Direct Known Subclasses

GlobalCommand

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_name, setup, context) ⇒ Command


6
7
8
9
10
# File 'lib/escort/formatter/command.rb', line 6

def initialize(command_name, setup, context)
  @setup = setup
  @context = context
  @name = command_name.to_sym
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context


4
5
6
# File 'lib/escort/formatter/command.rb', line 4

def context
  @context
end

#nameObject (readonly)

Returns the value of attribute name


4
5
6
# File 'lib/escort/formatter/command.rb', line 4

def name
  @name
end

#setupObject (readonly)

Returns the value of attribute setup


4
5
6
# File 'lib/escort/formatter/command.rb', line 4

def setup
  @setup
end

Instance Method Details

#aliasesObject


28
29
30
# File 'lib/escort/formatter/command.rb', line 28

def aliases
  @aliases ||= setup.command_aliases_for(name, context)
end

#child_commandsObject


40
41
42
# File 'lib/escort/formatter/command.rb', line 40

def child_commands
  @child_commands ||= setup.canonical_command_names_for(context) || []
end

#descriptionObject


20
21
22
# File 'lib/escort/formatter/command.rb', line 20

def description
  @description ||= setup.command_description_for(name, context) || ""
end

#has_aliases?Boolean


32
33
34
# File 'lib/escort/formatter/command.rb', line 32

def has_aliases?
  aliases && aliases.size > 0 ? true : false
end

#has_child_commands?Boolean


44
45
46
# File 'lib/escort/formatter/command.rb', line 44

def has_child_commands?
  child_commands.length > 0
end

#name_with_aliasesObject


12
13
14
# File 'lib/escort/formatter/command.rb', line 12

def name_with_aliases
  [name, aliases].flatten.join(", ")
end

#outlineObject


16
17
18
# File 'lib/escort/formatter/command.rb', line 16

def outline
  summary.empty? ? description : summary
end

#requires_arguments?Boolean


48
49
50
# File 'lib/escort/formatter/command.rb', line 48

def requires_arguments?
  @requires_arguments ||= setup.arguments_required_for(context)
end

#script_nameObject


36
37
38
# File 'lib/escort/formatter/command.rb', line 36

def script_name
  [canonical_script_name, context].flatten.join(" ")
end

#summaryObject


24
25
26
# File 'lib/escort/formatter/command.rb', line 24

def summary
  @summary ||= setup.command_summary_for(name, context) || ""
end

#usageObject


52
53
54
# File 'lib/escort/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