rake-commander 0.3.3 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b93ede4d58a5bc19446930380b5f9a785f7bcc404a93c1db63360dff78da2fd
4
- data.tar.gz: 8113a37d4d4301b7028923aaab04734dfa38c8e3979a272750d0e0b35fb649bd
3
+ metadata.gz: f671966099a385b76b7e0535fb3a0e584072a5996265c5c56adb26f047bd6fa2
4
+ data.tar.gz: 32617c52c0773ca1aeff4b8665c197cc765c9e879866eb684310bf62523709f4
5
5
  SHA512:
6
- metadata.gz: 1255ab72c7599bc831aa08ca375c4b9c4563698c9e91223184b4348c7ace025b67f0f7b11e6c9818b83774d58099c8cb14be9173f67665b96b228c22a421ad70
7
- data.tar.gz: 2bac8657f4b0b43523f5343617067fb371e1a4b5ea36d0aea32679e46b523cbf497e7a0af7ef7abaaf1b3fa02c89dd0cdd8f492df2dab5ef0e1150059b4aabd0
6
+ metadata.gz: 2d114f3fd737cc41f659b00d5a539c110057b9371335688e94d4777853a0082c86c2473beabc5a4ed1fdbe5595879028f6bd11683ba1fccf97b86551e7d70471
7
+ data.tar.gz: c2afd435a3f70f2fdf7af647eb7facb2dbe89593ff668af6453d766f8f4346d87ccd25a555572873f1c74d6fd748a218b290f2150f22addfc8b9ee8501cfffe4
data/CHANGELOG.md CHANGED
@@ -2,6 +2,7 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
4
  ## TO DO
5
+ - Think if [`binstubs`](https://github.com/rbenv/rbenv/wiki/Understanding-binstubs) would offer a neater patch right on `Rake::Application#init`
5
6
  - `option_reopen` -> upsert should be optional (add `upsert: false` as default an raise missing option if not found)
6
7
  - The error on missing short pops up where it's not clear the short was missed in the option_reopen call.
7
8
  - Option results
@@ -28,17 +29,35 @@ All notable changes to this project will be documented in this file.
28
29
  * Example: `on_options(:t, :s, present: true) {|options| do-stuff}` <- block to be called only when the option `:t` and `:s` are both present in the parsed `options` result.
29
30
  - Once this has been done, think about it being a hash-alike object with methods for the option names (i.e. `options.debug?`)
30
31
 
31
- ## DISCARDED IMPROVENTS
32
- - Option to globally enable/disable the 2nd patch?
33
- * That would make this gem completely useless.
34
32
 
35
- ## [0.3.2] - 2023-05-xx
33
+ ## [0.3.7] - 2023-05-xx
36
34
 
37
35
  ### Added
38
36
  ### Fixed
39
37
  ### Changed
40
38
 
41
- ## [0.3.2] - 2023-05-01
39
+ ## [0.3.6] - 2023-05-15
40
+
41
+ ### Fixed
42
+ - `RakeCommander::Options` inheritance of options in `options_hash` was NOT doing a `dup`
43
+
44
+ ### Changed
45
+ - `RakeCommander::Options#options_hash` made public method
46
+
47
+ ## [0.3.5] - 2023-05-08
48
+
49
+ ### Fixed
50
+ - `RakeCommander::Options#option_reopen` using name to reopen should not redefine if passed as Symbol.
51
+
52
+ ## [0.3.4] - 2023-05-08
53
+
54
+ ### Fixed
55
+ - `RakeCommand::Option#name` boolean form (`[no-]`) should not be part of the name.
56
+
57
+ ### Changed
58
+ - Slight refactor to the patch
59
+
60
+ ## [0.3.3] - 2023-05-01
42
61
 
43
62
  ### Changed
44
63
  - Replaced the patching method, so the `Rake` application doesn't need re-launch.
data/README.md CHANGED
@@ -121,10 +121,6 @@ The double dash ` -- ` delimiter allows to modify the `ARGV` parsing behaviour o
121
121
 
122
122
  Work has been done with the aim of providing a full patch on `rake`, provided that the main invocation command remains as `rake`.
123
123
 
124
- To preserve `rake` as invocation command, though, the patch needs to relaunch the rake application when it has already started. The reason is that `rake` has already pre-parsed `ARGV` when `rake-commander` is loaded (i.e. from a `Rakefile`) and has identified as tasks things that are part of the task options.
125
-
126
- * For compatibility with tasks declared using `RakeCommander`, the rake application is always relaunched. Anything that does not belong to task options should not be feed to rake tasks declared with rake commander classes.
127
-
128
124
  ### Patching `Rake`
129
125
 
130
126
  There is only one patch onto [`Rake::Application#top_level` method](https://github.com/ruby/rake/blob/48e798484babf725b0562cc417986da513e5d0ae/lib/rake/application.rb#L131), [`collect_command_line_tasks`](https://github.com/ruby/rake/blob/48e798484babf725b0562cc417986da513e5d0ae/lib/rake/application.rb#L782) is recalled with the arguments cut (so it does not interpret task option arguments as tasks).
@@ -32,9 +32,9 @@ class RakeCommander
32
32
 
33
33
  # Creates a new option, result of merging this `opt` with this option,
34
34
  # @return [RakeCommander::Option] where opt has been merged
35
- def merge(opt)
35
+ def merge(opt, **kargs)
36
36
  raise "Expecting RakeCommander::Option. Given: #{opt.class}" unless opt.is_a?(RakeCommander::Option)
37
- dup(**opt.dup_key_arguments, &opt.original_block)
37
+ dup(**opt.dup_key_arguments.merge(kargs), &opt.original_block)
38
38
  end
39
39
 
40
40
  # @return [Boolean] whether this option is required.
@@ -127,9 +127,8 @@ class RakeCommander
127
127
  # @see #name_sym
128
128
  # @return [Symbol, NilClass]
129
129
  def name_word_sym(value)
130
- return nil unless value = name_sym(value)
131
130
  value = value.to_s.gsub(BOOLEAN_TOKEN, '')
132
-
131
+ return nil unless value = name_sym(value)
133
132
  return nil unless value = name_words(value).first
134
133
  value.downcase.to_sym
135
134
  end
@@ -16,7 +16,7 @@ class RakeCommander
16
16
  base.attr_inheritable :banner
17
17
  base.attr_inheritable(:options_hash) do |value, subclass|
18
18
  next nil unless value
19
- value.values.uniq.each {|opt| subclass.send :add_to_options, opt}
19
+ value.values.uniq.each {|opt| subclass.send :add_to_options, opt.dup}
20
20
  subclass.send(:options_hash)
21
21
  end
22
22
  base.class_resolver :option_class, RakeCommander::Option
@@ -44,6 +44,8 @@ class RakeCommander
44
44
  end
45
45
 
46
46
  # It re-opens an option for edition. If it does not exist, it **upserts** it.
47
+ # @note To allow reopen using the name without modifying the argument, use a Symbol
48
+ # Example: `option_reopen :opt_with_arg` will keep the argument of 'opt_with_arg'
47
49
  # @note
48
50
  # 1. If `override` is `false, it will fail to change the `name` or the `short`
49
51
  # when they are already taken by some other option.
@@ -54,7 +56,10 @@ class RakeCommander
54
56
  aux = option_class.new(*args, **kargs, sample: true, &block)
55
57
  opt = options_hash.values_at(aux.name, aux.short).compact.first
56
58
  return option(*args, **kargs, &block) unless opt
57
- replace_in_options(opt, opt.merge(aux), override: override)
59
+ mod = {}.tap do |mkargs|
60
+ mkargs.merge!(name: opt.name_full) if aux.name_full.is_a?(Symbol)
61
+ end
62
+ replace_in_options(opt, opt.merge(aux, **mod), override: override)
58
63
  end
59
64
 
60
65
  # Removes options with short or name `keys` from options
@@ -91,6 +96,16 @@ class RakeCommander
91
96
  options_parser(&middleware).send(method, argv)
92
97
  end
93
98
 
99
+ # The options indexed by the short and the name (so doubled up in the hash).
100
+ # @param with_implicit [Boolean] whether free implicit shorts of declared options should be included
101
+ # among the keys (pointing to the specific option that has it implicit).
102
+ # @return [Hash] with Symbol name and shorts as keys, and `RakeCommander::Option` as values.
103
+ def options_hash(with_implicit: false)
104
+ @options_hash ||= {}
105
+ return @options_hash unless with_implicit
106
+ @options_hash.merge(implicit_shorts)
107
+ end
108
+
94
109
  # List of configured options
95
110
  # @return [Array<RakeCommander::Option>]
96
111
  def options
@@ -143,16 +158,6 @@ class RakeCommander
143
158
  OptionParser.new(&block)
144
159
  end
145
160
 
146
- # The options indexed by the short and the name (so doubled up in the hash).
147
- # @param with_implicit [Boolean] whether free implicit shorts of declared options should be included
148
- # among the keys (pointing to the specific option that has it implicit).
149
- # @return [Hash] with Symbol name and shorts as keys, and `RakeCommander::Option` as values.
150
- def options_hash(with_implicit: false)
151
- @options_hash ||= {}
152
- return @options_hash unless with_implicit
153
- @options_hash.merge(implicit_shorts)
154
- end
155
-
156
161
  # This covers the gap where `OptionParser` auto-generates shorts out of option names.
157
162
  # @note `OptionParser` implicitly generates a short for the option name. When defining
158
163
  # an option that uses this short, the short gets overriden/reused by the explicit option.
@@ -26,10 +26,21 @@ class RakeCommander
26
26
  # when `Rake::Application` requires the `Rakefile` that loads `rake-commander`,
27
27
  # we technically only need to fix the `top_level_tasks` that have been detected.
28
28
  def top_level
29
+ RakeCommander.rectify_rake_application
30
+ super
31
+ end
32
+ end
33
+
34
+ module ClassMethods
35
+ include RakeCommander::Patcher::Debug
36
+
37
+ # Reloading `Rakefile` has drawbacks around `require` only being launched once per
38
+ # dependency. Apparently some tasks of some gems are installed at `require` run-time.
39
+ # This requires to keep known tasks when we switch the application.
40
+ def rectify_rake_application
29
41
  RakeCommander.self_load_reset
30
42
  argv = RakeCommander.argv_rake_native_arguments(ARGV)
31
43
  Rake.application.send(:collect_command_line_tasks, argv)
32
- super
33
44
  end
34
45
  end
35
46
  end
@@ -1,3 +1,3 @@
1
1
  class RakeCommander
2
- VERSION = '0.3.3'.freeze
2
+ VERSION = '0.3.5'.freeze
3
3
  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.3.3
4
+ version: 0.3.5
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-05-01 00:00:00.000000000 Z
11
+ date: 2023-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -228,7 +228,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
228
  - !ruby/object:Gem::Version
229
229
  version: '0'
230
230
  requirements: []
231
- rubygems_version: 3.1.4
231
+ rubygems_version: 3.4.12
232
232
  signing_key:
233
233
  specification_version: 4
234
234
  summary: Classing rake tasks with options. Creating re-usable tasks, options and samples