class CommandKit::Commands::Subcommand
Represents a registered subcommand.
@api private
Attributes
aliases[R]
Optional alias names for the subcommand.
@return [Array<String>]
command[R]
The command class.
@return [Class]
summary[R]
A short summary for the subcommand.
@return [String, nil]
Public Class Methods
new(command, summary: self.class.summary(command), aliases: [])
click to toggle source
Initializes the subcommand.
@param [Class] command
The command class.
@param [String, nil] summary
A short summary for the subcommand. Defaults to the first sentence of the command.
@param [Array<String>] aliases
Optional alias names for the subcommand.
# File lib/command_kit/commands/subcommand.rb, line 38 def initialize(command, summary: self.class.summary(command), aliases: []) @command = command @summary = summary @aliases = aliases.map(&:to_s) end
summary(command)
click to toggle source
Derives a summary from the command's description.
@param [Class] command
The command class.
@return [String, nil]
If the command responds to a `#description` method, the first sentence of the description will be returned. Otherwise `nil` is returned.
# File lib/command_kit/commands/subcommand.rb, line 55 def self.summary(command) if command.respond_to?(:description) if (desc = command.description) # extract the first sentence desc[/^[^\.]+/] end end end