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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 79568da769a6523e7024fa641eb8d792b2fd4dfcc600f11f0cbf56e6bb1f45d9
4
- data.tar.gz: e8e55e77085b67e37fd9befdb1b0b77cd0f8403ff1c0ab939160c3659c0cd67f
3
+ metadata.gz: 72eaeab3395a3cb86ee6740a4dc90669f673af8ee30f6ba6dc40572a245d3b88
4
+ data.tar.gz: c75023ec7f58039781627a052e870982af0e546beefc91d2e8a54df2e58383e9
5
5
  SHA512:
6
- metadata.gz: fe77e58170a2e2bed3c9d52202e8deaa039422bda0ded1284f0d8fb316c83a6609fffb6753d2387d573b0ed70c7d5a2c74b5d868e8a89f5ba96dfa2d472b8587
7
- data.tar.gz: f75fa6017995dd942cd37cc6494db0a0c9d5273eb28e1b9ef9fe7d909fa39abffc25b6aa681c05ba1dce868b2265fb0bf54f01c55a31fd4298aaf6f70f3b435c
6
+ metadata.gz: 42e24e489d42e44de71162a4faee64dba5f72555afcfcb0742a6506c238f6f0ea480f0185f926a4f65f418005b3d30eb185d3311ca4aacd89e53eea6c31577ad
7
+ data.tar.gz: f8a70b443fbfd5717595d99faf4c12620a4adcb5f4cd9e4f01259622046de923fef3bc01db75382a17c272b7dbf5738163584f10cd8607aea50c3b92e8efbcca
data/.rubocop.yml CHANGED
@@ -17,6 +17,8 @@ Metrics/MethodLength:
17
17
  Max: 50
18
18
  Metrics/ClassLength:
19
19
  Max: 200
20
+ Metrics/ModuleLength:
21
+ Max: 200
20
22
  Metrics/AbcSize:
21
23
  Max: 50
22
24
  Metrics/CyclomaticComplexity:
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.2] - 2023-04-19
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
@@ -2,5 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
- # Specify your gem's dependencies in ecoportal-api.gemspec
5
+ # Specify your gem's dependencies in rake-commander.gemspec
6
6
  gemspec
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ecoportal::API
1
+ # RakeCommander
2
2
 
3
3
  Another way to define re-usable rake tasks and samples.
4
4
 
data/Rakefile CHANGED
@@ -23,7 +23,7 @@ YARD::Rake::YardocTask.new(:doc) do |t|
23
23
  end
24
24
 
25
25
  desc "Examples: Run examples (rake examples[basic] -- -h)"
26
- task :examples, [:sample] do |t, args|
26
+ task :examples, [:sample] do |_t, args|
27
27
  require_relative "examples/#{args[:sample]}"
28
28
  end
29
29
 
@@ -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
- if (opt = options_hash[error.option_sym]) && opt.argument_required?
83
- msg = "missing required argument: #{opt.name_hyphen} (#{opt.short_hyphen})"
84
- raise RakeCommander::Options::MissingArgument, msg, cause: nil
85
- else
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
- || (opt.required? && opt.default?)
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.new(missing) unless missing.empty?
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: self.options_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
- task_method = invoke_options_before_task(&task_method) if options?
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
- str_task = respond_to?(:task) ? "Usage: #{str_space}#{task} -- [options]" : nil
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 without this approach, it will throw `OptionParser::InvalidOption` error
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 invoke_options_before_task(&task_method)
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
@@ -1,3 +1,3 @@
1
1
  class RakeCommander
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.1.4'.freeze
3
3
  end
@@ -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://www.ecoportal.com"
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.2
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://www.ecoportal.com
145
+ homepage: https://github.com/rellampec/rake-commander
146
146
  licenses:
147
147
  - MIT
148
148
  metadata: {}