Class: CommandKit::Commands::Subcommand Private

Inherits:
Object
  • Object
show all
Defined in:
lib/command_kit/commands/subcommand.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a registered subcommand.

Direct Known Subclasses

AutoLoad::Subcommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, summary: self.class.summary(command), aliases: []) ⇒ Subcommand

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the subcommand.

Parameters:

  • command (Class)

    The command class.

  • summary (String, nil) (defaults to: self.class.summary(command))

    A short summary for the subcommand. Defaults to the first sentence of the command.

  • aliases (Array<String>) (defaults to: [])

    Optional alias names for the subcommand.



40
41
42
43
44
45
# File 'lib/command_kit/commands/subcommand.rb', line 40

def initialize(command, summary: self.class.summary(command),
                        aliases: [])
  @command = command
  @summary = summary
  @aliases = aliases.map(&:to_s)
end

Instance Attribute Details

#aliasesArray<String> (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Optional alias names for the subcommand.

Returns:

  • (Array<String>)


25
26
27
# File 'lib/command_kit/commands/subcommand.rb', line 25

def aliases
  @aliases
end

#commandClass (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The command class.

Returns:

  • (Class)


15
16
17
# File 'lib/command_kit/commands/subcommand.rb', line 15

def command
  @command
end

#summaryString? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A short summary for the subcommand.

Returns:

  • (String, nil)


20
21
22
# File 'lib/command_kit/commands/subcommand.rb', line 20

def summary
  @summary
end

Class Method Details

.summary(command) ⇒ String?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Derives a summary from the command's description.

Parameters:

  • command (Class)

    The command class.

Returns:

  • (String, nil)

    If the command responds to a #description method, the first sentence of the description will be returned. Otherwise nil is returned.



57
58
59
60
61
62
63
64
# File 'lib/command_kit/commands/subcommand.rb', line 57

def self.summary(command)
  if command.respond_to?(:description)
    if (desc = command.description)
      # extract the first sentence
      desc[/^[^\.]+/]
    end
  end
end