cuprum-cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +43 -0
- data/README.md +10 -0
- data/lib/cuprum/cli/argument.rb +2 -2
- data/lib/cuprum/cli/command.rb +2 -4
- data/lib/cuprum/cli/commands/ci/rspec_each_command.rb +34 -8
- data/lib/cuprum/cli/commands/ci.rb +8 -0
- data/lib/cuprum/cli/commands/file/new_command.rb +42 -49
- data/lib/cuprum/cli/commands/file.rb +8 -5
- data/lib/cuprum/cli/dependencies/clock/mock.rb +28 -0
- data/lib/cuprum/cli/dependencies/clock.rb +29 -0
- data/lib/cuprum/cli/dependencies/file_system/mock.rb +150 -18
- data/lib/cuprum/cli/dependencies/file_system.rb +145 -10
- data/lib/cuprum/cli/dependencies.rb +2 -0
- data/lib/cuprum/cli/errors.rb +0 -1
- data/lib/cuprum/cli/{commands/file/generate_file.rb → files/create_file.rb} +6 -48
- data/lib/cuprum/cli/{commands/file → files/engines}/render_erb.rb +6 -6
- data/lib/cuprum/cli/files/engines.rb +76 -0
- data/lib/cuprum/cli/{errors/files → files/errors}/file_not_writeable.rb +3 -3
- data/lib/cuprum/cli/files/errors/generator_error.rb +46 -0
- data/lib/cuprum/cli/{errors/files → files/errors}/missing_parameter.rb +5 -5
- data/lib/cuprum/cli/{errors/files → files/errors}/missing_template.rb +3 -3
- data/lib/cuprum/cli/{errors/files → files/errors}/template_error.rb +3 -3
- data/lib/cuprum/cli/files/errors.rb +19 -0
- data/lib/cuprum/cli/files/generator.rb +431 -0
- data/lib/cuprum/cli/files/generators/basic_generator.rb +15 -0
- data/lib/cuprum/cli/files/generators/rspec_generator.rb +19 -0
- data/lib/cuprum/cli/files/generators/ruby_generator.rb +32 -0
- data/lib/cuprum/cli/files/generators.rb +25 -0
- data/lib/cuprum/cli/files/template.rb +62 -0
- data/lib/cuprum/cli/files/templates/basic_template.rb +39 -0
- data/lib/cuprum/cli/files/templates/file_template.rb +60 -0
- data/lib/cuprum/cli/files/templates/string_template.rb +29 -0
- data/lib/cuprum/cli/files/templates.rb +59 -0
- data/lib/cuprum/cli/files.rb +18 -0
- data/lib/cuprum/cli/integrations/async/commands/rspec_each_command.rb +32 -0
- data/lib/cuprum/cli/integrations/async/commands.rb +11 -0
- data/lib/cuprum/cli/integrations/async.rb +21 -0
- data/lib/cuprum/cli/integrations/thor/registry.rb +7 -29
- data/lib/cuprum/cli/integrations/thor/task.rb +37 -7
- data/lib/cuprum/cli/metadata.rb +54 -5
- data/lib/cuprum/cli/option.rb +10 -4
- data/lib/cuprum/cli/options/class_methods.rb +19 -1
- data/lib/cuprum/cli/registry.rb +131 -55
- data/lib/cuprum/cli/rspec/deferred/dependencies/file_system_examples.rb +1303 -1001
- data/lib/cuprum/cli/rspec/deferred/generators_examples.rb +112 -0
- data/lib/cuprum/cli/rspec/deferred/metadata_examples.rb +300 -0
- data/lib/cuprum/cli/rspec/deferred/options_examples.rb +8 -2
- data/lib/cuprum/cli/rspec/deferred/registry_examples.rb +343 -108
- data/lib/cuprum/cli/rspec/deferred/templates_examples.rb +183 -0
- data/lib/cuprum/cli/version.rb +1 -1
- data/lib/cuprum/cli.rb +1 -0
- metadata +31 -14
- data/lib/cuprum/cli/commands/file/resolve_template.rb +0 -136
- data/lib/cuprum/cli/commands/file/templates.rb +0 -71
- data/lib/cuprum/cli/errors/files/template_not_resolved.rb +0 -54
- data/lib/cuprum/cli/errors/files.rb +0 -19
- /data/lib/cuprum/cli/{commands/file → files}/templates/rspec.rb.erb +0 -0
- /data/lib/cuprum/cli/{commands/file → files}/templates/ruby.rb.erb +0 -0
data/lib/cuprum/cli/registry.rb
CHANGED
|
@@ -19,34 +19,107 @@ module Cuprum::Cli
|
|
|
19
19
|
registered_commands.dup.freeze
|
|
20
20
|
end
|
|
21
21
|
|
|
22
|
-
#
|
|
22
|
+
# @overload register(*commands, **config, &block)
|
|
23
|
+
# Registers the commands with the registry.
|
|
23
24
|
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
25
|
+
# If given a block, transforms the command using the block. This can be
|
|
26
|
+
# used to customize the commands, such as applying a custom prefix or
|
|
27
|
+
# configuration options. If the block instead returns nil, that command
|
|
28
|
+
# will not be registered.
|
|
26
29
|
#
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
# @option config description [String] the description for the command.
|
|
30
|
-
# @option config full_description [String] the full description for the
|
|
31
|
-
# command.
|
|
32
|
-
# @option config full_name [String] the name under which to register the
|
|
33
|
-
# command. Defaults to the value of command.full_name.
|
|
34
|
-
# @option config options [Hash] options to pass to the command on
|
|
35
|
-
# initialization.
|
|
30
|
+
# @param commands [Array<Class>] the command classes to register.
|
|
31
|
+
# @param config [Hash] options for configuring the command.
|
|
36
32
|
#
|
|
37
|
-
#
|
|
33
|
+
# @option config arguments [Array] arguments to pass to the command on
|
|
34
|
+
# initialization.
|
|
35
|
+
# @option config description [String] the description for the command.
|
|
36
|
+
# @option config full_description [String] the full description for the
|
|
37
|
+
# command.
|
|
38
|
+
# @option config full_name [String] the name under which to register the
|
|
39
|
+
# command. Defaults to the value of command.full_name.
|
|
40
|
+
# @option config options [Hash] options to pass to the command on
|
|
41
|
+
# initialization.
|
|
38
42
|
#
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
# @yieldparam command [Class] the original command class.
|
|
44
|
+
#
|
|
45
|
+
# @yieldreturn [Class, nil] the command class to register. If nil is
|
|
46
|
+
# returned instead, nothing will be registered for the input command.
|
|
47
|
+
#
|
|
48
|
+
# @raise [NameError] if a command is already registered with that name.
|
|
49
|
+
#
|
|
50
|
+
# @return [self]
|
|
51
|
+
#
|
|
52
|
+
# @example Register a command
|
|
53
|
+
# registry.register(ExampleCommand)
|
|
54
|
+
#
|
|
55
|
+
# registry.commands.key?('example')
|
|
56
|
+
# #=> true
|
|
57
|
+
#
|
|
58
|
+
# @example Register a command with configuration options
|
|
59
|
+
# registry.register ExampleCommand,
|
|
60
|
+
# full_name: 'scope:custom_command',
|
|
61
|
+
# options: { option: 'value' }
|
|
62
|
+
#
|
|
63
|
+
# registry.commands.key?('example')
|
|
64
|
+
# #=> false
|
|
65
|
+
# registry.commands.key?('scope:custom_command')
|
|
66
|
+
# #=> true
|
|
67
|
+
# registry.commands['scope:example_command'].option_values
|
|
68
|
+
# #=> { option: 'value' }
|
|
69
|
+
#
|
|
70
|
+
# @example Register multiple commands with configuration options
|
|
71
|
+
# registry.register FirstCommand,
|
|
72
|
+
# SecondCommand,
|
|
73
|
+
# ThirdCommand,
|
|
74
|
+
# options: { shared: 'value' }
|
|
75
|
+
#
|
|
76
|
+
# registry.commands.key?('first')
|
|
77
|
+
# #=> true
|
|
78
|
+
# registry.commands.key?('second')
|
|
79
|
+
# #=> true
|
|
80
|
+
# registry.commands.key?('third')
|
|
81
|
+
# #=> true
|
|
82
|
+
# registry.commands['first'].option_values
|
|
83
|
+
# #=> { shared: 'value' }
|
|
84
|
+
#
|
|
85
|
+
# @example Register multiple commands and configure with a block
|
|
86
|
+
# registry.register(FirstCommand, SecondCommand, ThirdCommand) do |command|
|
|
87
|
+
# full_name = "scope:#{command.full_name}"
|
|
88
|
+
#
|
|
89
|
+
# command.with_full_name(full_name)
|
|
90
|
+
# end
|
|
91
|
+
#
|
|
92
|
+
# registry.commands.key?('scope:first')
|
|
93
|
+
# #=> true
|
|
94
|
+
# registry.commands.key?('scope:second')
|
|
95
|
+
# #=> true
|
|
96
|
+
# registry.commands.key?('scope:third')
|
|
97
|
+
# #=> true
|
|
98
|
+
#
|
|
99
|
+
# @example Register multiple commands and filter with a block
|
|
100
|
+
# commands = [OneCommand, TwoCommand, ThreeCommand]
|
|
101
|
+
#
|
|
102
|
+
# registry.register(commands) do |command|
|
|
103
|
+
# next unless command.full_name.start_with?('t')
|
|
104
|
+
#
|
|
105
|
+
# command
|
|
106
|
+
# end
|
|
107
|
+
#
|
|
108
|
+
# registry.commands.key?('one')
|
|
109
|
+
# #=> false
|
|
110
|
+
# registry.commands.key?('two')
|
|
111
|
+
# #=> true
|
|
112
|
+
# registry.commands.key?('three')
|
|
113
|
+
# #=> true
|
|
114
|
+
def register(*commands, **config, &block)
|
|
115
|
+
tools.assertions.validate_presence(commands, as: 'commands')
|
|
116
|
+
|
|
117
|
+
commands
|
|
118
|
+
.flatten
|
|
119
|
+
.each { |command| validate_command(command) }
|
|
120
|
+
.map { |command| build_command(command, **config, &block) }
|
|
121
|
+
.compact
|
|
122
|
+
.each { |command| add_registered_command(command) }
|
|
50
123
|
|
|
51
124
|
self
|
|
52
125
|
end
|
|
@@ -54,38 +127,49 @@ module Cuprum::Cli
|
|
|
54
127
|
|
|
55
128
|
private
|
|
56
129
|
|
|
57
|
-
def
|
|
58
|
-
|
|
130
|
+
def add_registered_command(command)
|
|
131
|
+
validate_name(command.full_name)
|
|
59
132
|
|
|
60
|
-
|
|
133
|
+
registered_commands[command.full_name] = command
|
|
61
134
|
end
|
|
62
135
|
|
|
63
|
-
def
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
options: nil,
|
|
70
|
-
**
|
|
136
|
+
def assign_command_properties( # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
|
|
137
|
+
command_class,
|
|
138
|
+
parent_class,
|
|
139
|
+
arguments: nil,
|
|
140
|
+
options: nil,
|
|
141
|
+
**config
|
|
71
142
|
)
|
|
72
|
-
|
|
73
|
-
|
|
143
|
+
%i[description full_description full_name].each do |property|
|
|
144
|
+
next unless config.key?(property) || parent_class.send(:"#{property}?")
|
|
74
145
|
|
|
75
|
-
|
|
146
|
+
value = config.fetch(property, parent_class.send(property))
|
|
76
147
|
|
|
77
|
-
|
|
78
|
-
command_class.full_description(full_description)
|
|
79
|
-
end
|
|
148
|
+
tools.assertions.validate_presence(value, as: property)
|
|
80
149
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
150
|
+
command_class.send(property, value)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
arguments&.each do |argument|
|
|
154
|
+
command_class.argument_value(argument)
|
|
155
|
+
end
|
|
84
156
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
end
|
|
157
|
+
options&.each do |option, value|
|
|
158
|
+
command_class.option_value(option, value)
|
|
88
159
|
end
|
|
160
|
+
|
|
161
|
+
command_class
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
def build_command(parent_class, **config, &block)
|
|
165
|
+
return parent_class unless block_given? || !config.empty?
|
|
166
|
+
|
|
167
|
+
Class
|
|
168
|
+
.new(parent_class)
|
|
169
|
+
.then do |klass|
|
|
170
|
+
assign_command_properties(klass, parent_class, **config)
|
|
171
|
+
end # rubocop:disable Style/MultilineBlockChain
|
|
172
|
+
.then { |klass| block_given? ? block.call(klass) : klass }
|
|
89
173
|
end
|
|
90
174
|
|
|
91
175
|
def command_name(command)
|
|
@@ -99,14 +183,6 @@ module Cuprum::Cli
|
|
|
99
183
|
'full_name does not match format category:sub_category:do_something'
|
|
100
184
|
end
|
|
101
185
|
|
|
102
|
-
def present?(value)
|
|
103
|
-
return false if value.nil?
|
|
104
|
-
|
|
105
|
-
return false unless value.respond_to?(:empty?) && !value.empty?
|
|
106
|
-
|
|
107
|
-
true
|
|
108
|
-
end
|
|
109
|
-
|
|
110
186
|
def registered_commands = @registered_commands ||= {}
|
|
111
187
|
|
|
112
188
|
def tools = SleepingKingStudios::Tools::Toolbelt.instance
|