7
7
require_relative "command_loader_options"
8
8
9
9
module GitCommander
10
- # @abstract Wraps domain logic for executing git-cmd commands
10
+ # Wraps domain logic for executing git-cmd Commands
11
11
class Command
12
12
include GitCommander ::CommandLoaderOptions
13
13
@@ -16,20 +16,25 @@ class Command
16
16
17
17
# @param name [String, Symbol] the name of the command
18
18
# @param registry [GitCommander::Registry] (GitCommander::Registry.new) the
19
- # command registry to use lookups
19
+ # command registry to use lookups
20
20
# @param options [Hash] the options to create the command with
21
+ #
21
22
# @option options [String] :description (nil) a short description to use in the
22
- # single line version of the command's help output
23
+ # single line version of the command's help output
23
24
# @option options [String] :summary (nil) the long-form description of the command
24
- # to use in the command's help output
25
+ # to use in the command's help output
25
26
# @option options [IO] :output (STDOUT) the IO object you want to use to
26
- # send outut from the command to
27
+ # send outut from the command to
27
28
# @option options [Array] :arguments an array of hashes describing the
28
- # argument names and default values that can be supplied to the command
29
+ # argument names and default values that can be supplied to the command
29
30
# @option options [Array] :flags an array of hashes describing the
30
- # flags and default values that can be supplied to the command
31
+ # flags and default values that can be supplied to the command
31
32
# @option options [Array] :switches an array of hashes describing the
32
- # switches and default values that can be supplied to the command
33
+ # switches and default values that can be supplied to the command
34
+ #
35
+ # @yieldparam [Array<Option>] run_options an Array of
36
+ # Option instances defined from the above +options+
37
+ #
33
38
def initialize ( name , registry : nil , **options , &block )
34
39
@name = name
35
40
@description = options [ :description ]
@@ -43,16 +48,23 @@ def initialize(name, registry: nil, **options, &block)
43
48
44
49
# Executes the block for the command with the provided run_options.
45
50
#
46
- # @param run_options
51
+ # @param run_options [Array<Option>] an array of Option(s) to pass to the {#block} of this Command
52
+ #
47
53
def run ( run_options = [ ] )
48
54
assign_option_values ( run_options )
49
55
Runner . new ( self ) . run options . map ( &:to_h ) . reduce ( :merge )
50
56
end
51
57
58
+ # Appends the +message+ to the Command's {#output}
59
+ #
60
+ # @param message [String] the string to append to the {#output}
61
+ #
52
62
def say ( message )
53
63
output . puts message
54
64
end
55
65
66
+ # Adds command-line help text to the {#output} of this Command
67
+ #
56
68
def help
57
69
say "NAME"
58
70
say " git-cmd #{ name } – #{ summary } "
@@ -63,10 +75,25 @@ def help
63
75
options_help
64
76
end
65
77
78
+ # Access to a unique Set of this Command's {#arguments}, {#flags}, and {#switches}
79
+ #
80
+ # @return [Set] a unique list of all options this command can accept
81
+ #
66
82
def options
67
83
Set . new ( @arguments + @flags + @switches )
68
84
end
69
85
86
+ # Add to this Command's {#arguments}, {#flags}, or {#switches}
87
+ #
88
+ # @param option_type [String, Symbol] the type of option to add
89
+ # @param options [Hash] the options to create the [Option] with
90
+ #
91
+ # @option options [String, Symbol] :name the name of the option to add
92
+ # @option options [Object] :default (nil) the default value of the Option
93
+ # @option options [String] :description (nil) a description of the Option to use in
94
+ # help text output
95
+ # @option options [Object] :value (nil) the value on of the Option
96
+ #
70
97
def add_option ( option_type , options = { } )
71
98
case option_type . to_sym
72
99
when :argument
0 commit comments