Class: Spring::Client::Help

Inherits:
Command
  • Object
show all
Defined in:
lib/spring/client/help.rb

Instance Attribute Summary collapse

Attributes inherited from Command

#args, #env

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, spring_commands = nil, application_commands = nil) ⇒ Help

Returns a new instance of Help.



17
18
19
20
21
22
23
24
# File 'lib/spring/client/help.rb', line 17

def initialize(args, spring_commands = nil, application_commands = nil)
  super args

  @spring_commands      = spring_commands      || Spring::Client::COMMANDS.dup
  @application_commands = application_commands || Spring.commands.dup

  @application_commands["rails"] = @spring_commands.delete("rails")
end

Instance Attribute Details

#application_commandsObject (readonly)

Returns the value of attribute application_commands.



6
7
8
# File 'lib/spring/client/help.rb', line 6

def application_commands
  @application_commands
end

#spring_commandsObject (readonly)

Returns the value of attribute spring_commands.



6
7
8
# File 'lib/spring/client/help.rb', line 6

def spring_commands
  @spring_commands
end

Class Method Details

.call(args) ⇒ Object



12
13
14
15
# File 'lib/spring/client/help.rb', line 12

def self.call(args)
  require "spring/commands"
  super
end

.descriptionObject



8
9
10
# File 'lib/spring/client/help.rb', line 8

def self.description
  "Print available commands."
end

Instance Method Details

#callObject



26
27
28
# File 'lib/spring/client/help.rb', line 26

def call
  puts formatted_help
end

#command_help(subject, commands) ⇒ Object



37
38
39
40
# File 'lib/spring/client/help.rb', line 37

def command_help(subject, commands)
  ["Commands for #{subject}:\n",
  *commands.sort_by(&:first).map { |name, command| display(name, command) }.compact]
end

#formatted_helpObject



30
31
32
33
34
35
# File 'lib/spring/client/help.rb', line 30

def formatted_help
  ["Usage: spring COMMAND [ARGS]\n",
   *command_help("spring itself", spring_commands),
   '',
   *command_help("your application", application_commands)].join("\n")
end