rake-commander 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/CHANGELOG.md +18 -3
- data/Gemfile +1 -1
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/rake-commander/options/arguments.rb +1 -1
- data/lib/rake-commander/options.rb +10 -14
- data/lib/rake-commander/rake_task.rb +9 -4
- data/lib/rake-commander/version.rb +1 -1
- data/rake-commander.gemspec +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: 72eaeab3395a3cb86ee6740a4dc90669f673af8ee30f6ba6dc40572a245d3b88
|
4
|
+
data.tar.gz: c75023ec7f58039781627a052e870982af0e546beefc91d2e8a54df2e58383e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 42e24e489d42e44de71162a4faee64dba5f72555afcfcb0742a6506c238f6f0ea480f0185f926a4f65f418005b3d30eb185d3311ca4aacd89e53eea6c31577ad
|
7
|
+
data.tar.gz: f8a70b443fbfd5717595d99faf4c12620a4adcb5f4cd9e4f01259622046de923fef3bc01db75382a17c272b7dbf5738163584f10cd8607aea50c3b92e8efbcca
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,13 +2,28 @@
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
3
3
|
|
4
4
|
## TO DO
|
5
|
+
- Specify what options are REQUIRED in help lines.
|
5
6
|
- Rake task parameters (see: https://stackoverflow.com/a/825832/4352306)
|
6
7
|
- `OptionParser#parse` result (what to do with unknown ARGV `leftovers`)
|
7
8
|
|
8
|
-
## [0.1.
|
9
|
+
## [0.1.5] - 2023-04-xx
|
9
10
|
|
10
11
|
### Added
|
11
|
-
- First commit
|
12
|
-
|
13
12
|
### Fixed
|
14
13
|
### Changed
|
14
|
+
|
15
|
+
## [0.1.4] - 2023-04-20
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
- `rubocop` offenders
|
19
|
+
- Added implicity `exit(0)` when wrapping the `task` block
|
20
|
+
|
21
|
+
## [0.1.3] - 2023-04-20
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
- Reference to repo and gem
|
25
|
+
|
26
|
+
## [0.1.2] - 2023-04-19
|
27
|
+
|
28
|
+
### Added
|
29
|
+
- First commit
|
data/Gemfile
CHANGED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -25,7 +25,7 @@ class RakeCommander
|
|
25
25
|
# @param argv [Array<String>]
|
26
26
|
# @param options [Hash] the defined `RakeCommander::Option` to re-arrange `argv` with.
|
27
27
|
# @return [Array<String>] the re-arranged `argv`
|
28
|
-
def pre_parse_arguments(argv = ARGV, options)
|
28
|
+
def pre_parse_arguments(argv = ARGV, options:)
|
29
29
|
pre_parsed = explicit_argument_options(argv, options)
|
30
30
|
compact_short = ''
|
31
31
|
pre_parsed.each_with_object([]) do |(opt_ref, args), out|
|
@@ -70,21 +70,19 @@ class RakeCommander
|
|
70
70
|
# It builds the `OptionParser` injecting the `middleware` block.
|
71
71
|
# @return [Hash] with `short` option as `key` and final value as `value`.
|
72
72
|
def parse_options(argv = ARGV, leftovers: [], &middleware)
|
73
|
-
left_overs = []
|
74
73
|
options_parser_with_results(middleware) do |options_parser|
|
75
|
-
argv = pre_parse_arguments(argv, options_hash)
|
74
|
+
argv = pre_parse_arguments(argv, options: options_hash)
|
75
|
+
pp argv
|
76
76
|
leftovers.push(*options_parser.parse(argv))
|
77
77
|
rescue OptionParser::MissingArgument => e
|
78
78
|
raise RakeCommander::Options::MissingArgument, e, cause: nil
|
79
79
|
rescue OptionParser::InvalidArgument => e
|
80
80
|
error = RakeCommander::Options::InvalidArgument
|
81
81
|
error = error.new(e)
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
raise error, e, cause: nil
|
87
|
-
end
|
82
|
+
opt = options_hash[error.option_sym]
|
83
|
+
msg = "missing required argument: #{opt&.name_hyphen} (#{opt&.short_hyphen})"
|
84
|
+
raise RakeCommander::Options::MissingArgument, msg, cause: nil if opt&.argument_required?
|
85
|
+
raise error, e, cause: nil
|
88
86
|
end.tap do |results|
|
89
87
|
check_required_presence!(results)
|
90
88
|
end
|
@@ -124,7 +122,7 @@ class RakeCommander
|
|
124
122
|
{}.tap do |res_def|
|
125
123
|
options.select do |opt|
|
126
124
|
(results_with_all_defaults && opt.default?) \
|
127
|
-
||
|
125
|
+
|| (opt.required? && opt.default?)
|
128
126
|
end.each do |opt|
|
129
127
|
res_def[opt.short] = opt.default
|
130
128
|
end
|
@@ -134,12 +132,10 @@ class RakeCommander
|
|
134
132
|
# It throws an exception if any of the required options
|
135
133
|
# is missing in results
|
136
134
|
def check_required_presence!(results)
|
137
|
-
missing = options.select do |opt|
|
138
|
-
opt.required?
|
139
|
-
end.reject do |opt|
|
135
|
+
missing = options.select(&:required?).reject do |opt|
|
140
136
|
results.key?(opt.short) || results.key?(opt.name)
|
141
137
|
end
|
142
|
-
raise RakeCommander::Options::MissingOption
|
138
|
+
raise RakeCommander::Options::MissingOption, missing unless missing.empty?
|
143
139
|
end
|
144
140
|
|
145
141
|
def add_to_options(opt)
|
@@ -158,7 +154,7 @@ class RakeCommander
|
|
158
154
|
end
|
159
155
|
|
160
156
|
def options(argv = ARGV)
|
161
|
-
@options ||= self.class.parse_options(argv, leftovers:
|
157
|
+
@options ||= self.class.parse_options(argv, leftovers: options_leftovers)
|
162
158
|
end
|
163
159
|
|
164
160
|
def options_leftovers
|
@@ -28,7 +28,8 @@ class RakeCommander
|
|
28
28
|
|
29
29
|
# ensure options are parsed before calling task
|
30
30
|
# and that ARGV is only parsed after `--`
|
31
|
-
|
31
|
+
# do an `exit(0)` right at the end
|
32
|
+
task_method = task_context(&task_method) if options?
|
32
33
|
|
33
34
|
if namespaced?
|
34
35
|
namespaced do
|
@@ -95,7 +96,7 @@ class RakeCommander
|
|
95
96
|
# @return [String, NilClass] generic banner for options
|
96
97
|
def task_options_banner
|
97
98
|
str_space = respond_to?(:namespace)? "#{namespace}:" : ''
|
98
|
-
|
99
|
+
respond_to?(:task) ? "Usage: #{str_space}#{task} -- [options]" : nil
|
99
100
|
end
|
100
101
|
|
101
102
|
private
|
@@ -116,9 +117,12 @@ class RakeCommander
|
|
116
117
|
|
117
118
|
# Rake command ends at `--` (`RAKE_END_COMMAND`).
|
118
119
|
# We only want to parse the options that come afterwards
|
119
|
-
# @note
|
120
|
+
# @note
|
121
|
+
# 1. Without `ARGV` cut, it will throw `OptionParser::InvalidOption` error
|
122
|
+
# 2. **Work-around**: We also add an `exit(0)` at the end to prevent `Rake` chaining
|
123
|
+
# option arguments as if they were actual tasks.
|
120
124
|
# @return [Proc]
|
121
|
-
def
|
125
|
+
def task_context(&task_method)
|
122
126
|
object = eval('self', task_method.binding, __FILE__, __LINE__)
|
123
127
|
return task_method unless object.is_a?(self)
|
124
128
|
proc do |*args|
|
@@ -128,6 +132,7 @@ class RakeCommander
|
|
128
132
|
end
|
129
133
|
object.options(argv)
|
130
134
|
task_method.call(*args)
|
135
|
+
exit(0)
|
131
136
|
end
|
132
137
|
end
|
133
138
|
end
|
data/rake-commander.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.email = ["oscar@ecoportal.co.nz"]
|
10
10
|
|
11
11
|
spec.summary = 'The classed version of rake with task options. Create re-usable tasks and samples.'
|
12
|
-
spec.homepage = "https://
|
12
|
+
spec.homepage = "https://github.com/rellampec/rake-commander"
|
13
13
|
spec.licenses = %w[MIT]
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rake-commander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oscar Segura Samper
|
@@ -142,7 +142,7 @@ files:
|
|
142
142
|
- lib/rake-commander/rake_task.rb
|
143
143
|
- lib/rake-commander/version.rb
|
144
144
|
- rake-commander.gemspec
|
145
|
-
homepage: https://
|
145
|
+
homepage: https://github.com/rellampec/rake-commander
|
146
146
|
licenses:
|
147
147
|
- MIT
|
148
148
|
metadata: {}
|