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
25
26
# 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

  @spring_commands.delete_if { |k, v| k.start_with?("-") }

  @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



28
29
30
# File 'lib/spring/client/help.rb', line 28

def call
  puts formatted_help
end

#command_help(subject, commands) ⇒ Object



40
41
42
43
# File 'lib/spring/client/help.rb', line 40

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

#formatted_helpObject



32
33
34
35
36
37
38
# File 'lib/spring/client/help.rb', line 32

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