Sha256: b579b25b46ccb77e96ecb6dc5b53cde2280882ecf70b34c93b4daee8912fff7c
Contents?: true
Size: 1.61 KB
Versions: 1
Compression:
Stored size: 1.61 KB
Contents
require "spring_standalone/version" module SpringStandalone module Client class Help < Command attr_reader :spring_commands, :application_commands def self.description "Print available commands." end def self.call(args) require "spring_standalone/commands" super end def initialize(args, spring_commands = nil, application_commands = nil) super args @spring_commands = spring_commands || SpringStandalone::Client::COMMANDS.dup @application_commands = application_commands || SpringStandalone.commands.dup @spring_commands.delete_if { |k, v| k.start_with?("-") } # @application_commands["rails"] = @spring_commands.delete("rails") end def call puts formatted_help end def formatted_help ["Version: #{env.version}\n", "Usage: spring_sa COMMAND [ARGS]\n", *command_help("SpringStandalone itself", spring_commands), '', *command_help("your application", application_commands)].join("\n") end def command_help(subject, commands) ["Commands for #{subject}:\n", *commands.sort_by(&:first).map { |name, command| display(name, command) }.compact] end private def all_commands spring_commands.merge application_commands end def display(name, command) if command.description " #{name.ljust(max_name_width)} #{command.description}" end end def max_name_width @max_name_width ||= all_commands.keys.map(&:length).max end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
spring_standalone-0.1.13 | lib/spring_standalone/client/help.rb |