Sha256: c94515031b8d1531ca9936862a013dd04728ae314f292f28c5eb32cf81008708
Contents?: true
Size: 1.57 KB
Versions: 6
Compression:
Stored size: 1.57 KB
Contents
module CommandKit module Commands # # Represents a registered subcommand. # # @api private # class Subcommand # The command class. # # @return [Class] attr_reader :command # A short summary for the subcommand. # # @return [String, nil] attr_reader :summary # Optional alias names for the subcommand. # # @return [Array<String>] attr_reader :aliases # # 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. # def initialize(command, summary: self.class.summary(command), aliases: []) @command = command @summary = summary @aliases = aliases.map(&:to_s) end # # 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. # def self.summary(command) if command.respond_to?(:description) if (desc = command.description) # extract the first sentence desc[/^[^\.]+/] end end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems