rake-commander 0.2.0 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +24 -3
- data/README.md +10 -9
- data/examples/02_a_chainer_example.rb +6 -0
- data/examples/02_b_chained_example.rb +1 -0
- data/lib/rake-commander/base/class_auto_loader.rb +1 -1
- data/lib/rake-commander/option.rb +7 -6
- data/lib/rake-commander/options/result.rb +10 -4
- data/lib/rake-commander/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcd5bb7ca707d1e8e6cf543712c447cbd63061e7bbe8cfdc6e3c0c0755c338e5
|
4
|
+
data.tar.gz: 7b02270fbe937b0b50b6e8c4b1001005ba377c69f7a799ce97823fea42356893
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00d05400483297153797a08d02c32fb5bde4510a829cdb158121324d1d034d62dafa3560c2a56daa6893b6bc35ee9a46a832493e2b37403a34eb949f10082fc4
|
7
|
+
data.tar.gz: 01c09729261196848948383dfeb356c1463086f858e4365bcfb20a043e98e521284fe45b20cf8f39ef0ab139a37fa26ce381e433974fad48c860d6ea9c377476
|
data/CHANGELOG.md
CHANGED
@@ -2,11 +2,13 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
4
|
## TO DO
|
5
|
+
- `option_reopen` -> upsert should be optional (add `upsert: false` as default an raise missing option if not found)
|
6
|
+
- The error on missing short pops up where it's not clear the short was missed in the option_reopen call.
|
5
7
|
- Option results
|
6
8
|
- Include the symbol name keys (configurable). Note that dash will be replaced by underscore.
|
7
|
-
- Type
|
9
|
+
- Type Coercions
|
8
10
|
- Add a way to define/redefine a set and use them.
|
9
|
-
- Add more supported
|
11
|
+
- Add more supported type_coercions as native to the gem (i.e. `Symbol`)
|
10
12
|
- Add support [for `ActiveRecord::Enum`](https://apidock.com/rails/ActiveRecord/Enum)
|
11
13
|
- Option definitions
|
12
14
|
- Order: `where: [:tail, :top]` and `[after, before]: :option_name`
|
@@ -30,12 +32,31 @@ All notable changes to this project will be documented in this file.
|
|
30
32
|
- Option to globally enable/disable the 2nd patch?
|
31
33
|
* That would make this gem completely useless.
|
32
34
|
|
33
|
-
## [0.2.
|
35
|
+
## [0.2.4] - 2023-04-xx
|
34
36
|
|
35
37
|
### Added
|
36
38
|
### Fixed
|
37
39
|
### Changed
|
38
40
|
|
41
|
+
## [0.2.3] - 2023-04-29
|
42
|
+
|
43
|
+
### Added
|
44
|
+
- Include Symbol option names in the parsed option results.
|
45
|
+
|
46
|
+
### Fixed
|
47
|
+
### Changed
|
48
|
+
|
49
|
+
## [0.2.2] - 2023-04-29
|
50
|
+
|
51
|
+
### Fixed
|
52
|
+
- Typo in `RakeCommander::Base::ClassAutoLoader`
|
53
|
+
|
54
|
+
## [0.2.1] - 2023-04-29
|
55
|
+
|
56
|
+
### Fixed
|
57
|
+
- `RakeCommander::Option` type coercion was not being inherited
|
58
|
+
- Typo on `coertion`: writes `coercion`
|
59
|
+
|
39
60
|
|
40
61
|
## [0.2.0] - 2023-04-28
|
41
62
|
|
data/README.md
CHANGED
@@ -9,12 +9,12 @@ Rake commander is a way to declare **rake tasks** with re-usable classes. It enh
|
|
9
9
|
Although the `OptionParser` ruby native class is used for parsing the options, the declaration of options, additionally to the ones of `OptionParser` comes with some **opinionated improvements** and amendments:
|
10
10
|
|
11
11
|
1. It is possible to declare options as `required`
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
12
|
+
* This is additional to required option arguments.
|
13
|
+
* Options are inheritable (they get a custom `deep_dup`)
|
14
|
+
1. An option can have a `default` value.
|
15
|
+
* Which can optionally be automatically used when the option accepts or requires an argument.
|
16
|
+
1. Options parsing raises specific option errors. For a given task/class, each error type can have its own handler or preferred action.
|
17
|
+
* Defined error handling is inheritable and can be redefined.
|
18
18
|
|
19
19
|
## Installation
|
20
20
|
|
@@ -74,10 +74,11 @@ rspec logging and results
|
|
74
74
|
It supports most of options syntax of the native `OptionParser` but for a couple of exceptions perhaps:
|
75
75
|
1. It does **NOT** support definitions or parsing of shortcuts with **embedded argument** (i.e. `-nNAME`).
|
76
76
|
2. It does **NOT** support definitions that include equal sign (i.e. `name=NAME`, `n=NAME`)
|
77
|
+
3. Currently, declaring a short and a name for the option is compulsory.
|
77
78
|
|
78
|
-
An argument should be explicitly declared in the `name` part:
|
79
|
+
An argument of an option should be explicitly declared in the `name` part:
|
79
80
|
|
80
|
-
```
|
81
|
+
```ruby
|
81
82
|
option :n, '--name NAME'
|
82
83
|
```
|
83
84
|
|
@@ -89,7 +90,7 @@ Although it is planned to extend the syntax, the current version shares the opti
|
|
89
90
|
rake [rake-options] task1 task2 -- [shared-task-options]
|
90
91
|
```
|
91
92
|
|
92
|
-
The double dash ` -- ` delimiter allows to modify the `ARGV` parsing behaviour of `rake`, giving room for **opinionated enhanced syntax**. Anything that comes before the double dash is
|
93
|
+
The double dash ` -- ` delimiter allows to modify the `ARGV` parsing behaviour of `rake`, giving room for **opinionated enhanced syntax**. Anything that comes before the double dash is fed to standard `rake`, and anything after `--` are parsed as option tasks via `rake commander`.
|
93
94
|
|
94
95
|
```
|
95
96
|
<rake part> -- [tasks options part]
|
@@ -24,6 +24,7 @@ class RakeCommander::Custom::Chainer < RakeCommander
|
|
24
24
|
option '-m', 'method [METHOD]', default: 'system', desc: str_desc
|
25
25
|
|
26
26
|
def task(*_args)
|
27
|
+
print_options if options[:b]
|
27
28
|
if options[:c]
|
28
29
|
cmd = "#{subcommand_base} -- #{subcommand_arguments.join(' ')}"
|
29
30
|
puts "Calling --> '#{cmd}'"
|
@@ -51,6 +52,11 @@ class RakeCommander::Custom::Chainer < RakeCommander
|
|
51
52
|
|
52
53
|
private
|
53
54
|
|
55
|
+
def print_options
|
56
|
+
puts "These are the options received:"
|
57
|
+
pp options
|
58
|
+
end
|
59
|
+
|
54
60
|
def puts(str)
|
55
61
|
return super unless options[:b]
|
56
62
|
super "#{app_id} #{str} #{thread_id}"
|
@@ -41,7 +41,7 @@ class RakeCommander
|
|
41
41
|
autoloaded_namespaces(type).tap do |target|
|
42
42
|
next if namespaces.empty?
|
43
43
|
other_type = type == :include ? :ignore : :include
|
44
|
-
namespaces.each {|nm_sp|
|
44
|
+
namespaces.each {|nm_sp| autoloaded_namespaces(other_type).delete(nm_sp)}
|
45
45
|
target.concat(namespaces)
|
46
46
|
end
|
47
47
|
end
|
@@ -16,7 +16,7 @@ class RakeCommander
|
|
16
16
|
@default = kargs[:default] if kargs.key?(:default)
|
17
17
|
@desc = kargs[:desc] if kargs.key?(:desc)
|
18
18
|
@required = kargs[:required] if kargs.key?(:required)
|
19
|
-
@
|
19
|
+
@type_coercion = kargs[:type] if kargs.key?(:type)
|
20
20
|
@other_args = args
|
21
21
|
@original_block = block
|
22
22
|
configure_other
|
@@ -91,8 +91,8 @@ class RakeCommander
|
|
91
91
|
end
|
92
92
|
|
93
93
|
# @return [Class, NilClass]
|
94
|
-
def
|
95
|
-
@
|
94
|
+
def type_coercion
|
95
|
+
@type_coercion || (default? && default.class)
|
96
96
|
end
|
97
97
|
|
98
98
|
# @return [Boolean]
|
@@ -130,6 +130,7 @@ class RakeCommander
|
|
130
130
|
kargs.merge!(name: name_full.dup.freeze) if name_full
|
131
131
|
kargs.merge!(desc: desc.dup) if desc
|
132
132
|
kargs.merge!(default: default.dup) if default?
|
133
|
+
kargs.merge!(type: @type_coercion) if @type_coercion.is_a?(Class)
|
133
134
|
kargs.merge!(required: required?)
|
134
135
|
end
|
135
136
|
end
|
@@ -139,7 +140,7 @@ class RakeCommander
|
|
139
140
|
configure_other
|
140
141
|
args = [short_hyphen, name_hyphen]
|
141
142
|
args.push(*switch_desc(implicit_short: implicit_short))
|
142
|
-
args <<
|
143
|
+
args << type_coercion if type_coercion
|
143
144
|
args
|
144
145
|
end
|
145
146
|
|
@@ -147,7 +148,7 @@ class RakeCommander
|
|
147
148
|
|
148
149
|
# Called on parse runtime
|
149
150
|
def option_block(&middleware)
|
150
|
-
block_extra_args = [default, short, name]
|
151
|
+
block_extra_args = [default, short, name, self]
|
151
152
|
proc do |value|
|
152
153
|
args = block_extra_args.dup.unshift(value)
|
153
154
|
original_block&.call(*args)
|
@@ -228,7 +229,7 @@ class RakeCommander
|
|
228
229
|
# It consumes `other_args`, to prevent direct overrides to be overriden by it.
|
229
230
|
def configure_other
|
230
231
|
if type = other_args.find {|arg| arg.is_a?(Class)}
|
231
|
-
@
|
232
|
+
@type_coercion = type
|
232
233
|
other_args.delete(type)
|
233
234
|
end
|
234
235
|
if value = other_args.find {|arg| arg.is_a?(String)}
|
@@ -24,6 +24,12 @@ class RakeCommander
|
|
24
24
|
# It **re-opens** the method and adds a middleware to gather and return
|
25
25
|
# the results of the parsing (including the `leftovers`)
|
26
26
|
# @note this extends the method parameters and changes the returned value.
|
27
|
+
# @yield [value, default, short, name, option] do somethin with parsed `value` for `option`
|
28
|
+
# @yieldparam value [] the resulting parsed value
|
29
|
+
# @yieldparam default [] the default value of the option
|
30
|
+
# @yieldparam short [Symbol] the symbol short of the option
|
31
|
+
# @yieldparam name [Symbol] the symbol name of the option
|
32
|
+
# @yieldparam option [RakeCommander::Option] the option that is being parsed
|
27
33
|
# @param leftovers [Array<String>] see RakeCommander::Options#parse_options`
|
28
34
|
# @param results [Hash] with `short` option as `key` and final value as `value`.
|
29
35
|
# @see `RakeCommander::Options#parse_options`
|
@@ -66,9 +72,9 @@ class RakeCommander
|
|
66
72
|
# @return [Proc] the results collector that wraps the middleware.
|
67
73
|
def results_collector(results, &middleware)
|
68
74
|
results = result_defaults(results)
|
69
|
-
proc do |value, default, short, name|
|
70
|
-
middleware&.call(value, default, short, name)
|
71
|
-
results[short] = value.nil?? default : value
|
75
|
+
proc do |value, default, short, name, opt|
|
76
|
+
middleware&.call(value, default, short, name, opt)
|
77
|
+
results[name] = results[short] = value.nil?? default : value
|
72
78
|
end
|
73
79
|
end
|
74
80
|
|
@@ -79,7 +85,7 @@ class RakeCommander
|
|
79
85
|
(options_with_defaults && opt.default?) \
|
80
86
|
|| (opt.required? && opt.default?)
|
81
87
|
end.each do |opt|
|
82
|
-
res_def[opt.short] = opt.default
|
88
|
+
res_def[opt.name] = res_def[opt.short] = opt.default
|
83
89
|
end
|
84
90
|
end
|
85
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura Samper
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-04-
|
11
|
+
date: 2023-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|