optimist 3.0.0 → 3.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 335830b11859ca8643cd5fe74d6444f147ab2873
4
- data.tar.gz: 9a483cf4a178eaf83c6093ea177e29cc0cf63c32
2
+ SHA256:
3
+ metadata.gz: 87e142709336212fa484755022a85b8d833de889579b69a1b2fc35933bac88fd
4
+ data.tar.gz: 4ac2b33acae583f3ce444c105112c144a32affc52a8ab52980ab9772a107f8c3
5
5
  SHA512:
6
- metadata.gz: 7f18e81587cb3f617d7dfc26183c1d821a058891a638560c60c85202237fb084e57c77ffdc7b5a245a81e378769852b9e51827e8b41329298c7b7f0a3cb2f395
7
- data.tar.gz: c6f2d0245b46cb58470b4ff6f31ac7df483c8d7f48c1d0da27cdcd3681fef55dced81a2765dc33035b808e7c7ba9519363019bd486f3496a74ebaa11f011f219
6
+ metadata.gz: 7ccadd2b388b3877e3a075e224b7b9f1ed3b48a4dd68a72a6ca7f8ca9120c999a366d0619bf1cfcec0018fd80baeab83fd8e686e35f91109668c4d0210e08ddd
7
+ data.tar.gz: '0312801235dc1952812a79d01d68b71cff4db8187040cbc74f299bb519d926dc01fed15f0c656ca7d09e18dcd18289b1d951917cc31c8a8e1bfaa1377cbcde99'
data/.codeclimate.yml ADDED
@@ -0,0 +1,16 @@
1
+ prepare:
2
+ fetch:
3
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_base.yml
4
+ path: ".rubocop_base.yml"
5
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
6
+ path: ".rubocop_cc_base.yml"
7
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
8
+ path: styles/base.yml
9
+ - url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
10
+ path: styles/cc_base.yml
11
+ plugins:
12
+ rubocop:
13
+ enabled: true
14
+ config: ".rubocop_cc.yml"
15
+ channel: rubocop-0-82
16
+ version: '2'
@@ -0,0 +1,34 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ pull_request:
6
+ schedule:
7
+ - cron: '0 0 * * 0'
8
+
9
+ jobs:
10
+ ci:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ fail-fast: false
14
+ matrix:
15
+ ruby-version:
16
+ - '2.4'
17
+ - '2.5'
18
+ - '2.6'
19
+ - '2.7'
20
+ - '3.0'
21
+ - '3.1'
22
+ - '3.2'
23
+ - jruby-9.3
24
+ - ruby-head
25
+ - jruby-head
26
+ steps:
27
+ - uses: actions/checkout@v2
28
+ - name: Set up Ruby
29
+ uses: ruby/setup-ruby@v1
30
+ with:
31
+ ruby-version: ${{ matrix.ruby-version }}
32
+ bundler-cache: true
33
+ - name: Run tests
34
+ run: bundle exec rake
data/.rubocop.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_gem:
2
+ manageiq-style: ".rubocop_base.yml"
3
+ inherit_from:
4
+ - ".rubocop_local.yml"
data/.rubocop_cc.yml ADDED
@@ -0,0 +1,4 @@
1
+ inherit_from:
2
+ - ".rubocop_base.yml"
3
+ - ".rubocop_cc_base.yml"
4
+ - ".rubocop_local.yml"
File without changes
data/.whitesource ADDED
@@ -0,0 +1,3 @@
1
+ {
2
+ "settingsInheritedFrom": "ManageIQ/whitesource-config@master"
3
+ }
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [3.1.0] - 2023-07-24
8
+ ### Added
9
+ - Implement `either` command ([#130](https://github.com/ManageIQ/optimist/pull/130))
10
+
11
+ [Unreleased]: https://github.com/ManageIQ/optimist/compare/v3.1.0...HEAD
12
+ [3.1.0]: https://github.com/ManageIQ/optimist/compare/v3.0.1...v3.1.0
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == [3.0.1] / 2020-04-20
2
+
3
+ * Add a LICENSE.txt file to the released package
4
+ * Test fixes (thanks @aried3r, @neontapir, @npras)
5
+
1
6
  == [3.0.0] / 2018-08-24
2
7
 
3
8
  * The gem has been officially renamed to optimist
@@ -163,6 +168,8 @@
163
168
  == 1.0 / 2007-01-29
164
169
  * Initial release.
165
170
 
171
+ [3.0.1]: https://github.com/ManageIQ/optimist/compare/v3.0.0...v3.0.1
172
+ [3.0.0]: https://github.com/ManageIQ/optimist/compare/v2.1.3...v3.0.0
166
173
  [2.1.3]: https://github.com/ManageIQ/optimist/compare/v2.1.2...v2.1.3
167
174
  [2.1.2]: https://github.com/ManageIQ/optimist/compare/v2.1.1...v2.1.2
168
175
  [2.1.1]: https://github.com/ManageIQ/optimist/compare/v2.1.0...v2.1.1
data/LICENSE.txt ADDED
@@ -0,0 +1,23 @@
1
+ Copyright (c) 2008-2014 William Morgan
2
+ Copyright (c) 2014 Red Hat, Inc
3
+
4
+ MIT License
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining
7
+ a copy of this software and associated documentation files (the
8
+ "Software"), to deal in the Software without restriction, including
9
+ without limitation the rights to use, copy, modify, merge, publish,
10
+ distribute, sublicense, and/or sell copies of the Software, and to
11
+ permit persons to whom the Software is furnished to do so, subject to
12
+ the following conditions:
13
+
14
+ The above copyright notice and this permission notice shall be
15
+ included in all copies or substantial portions of the Software.
16
+
17
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -3,10 +3,9 @@
3
3
  http://manageiq.github.io/optimist/
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/optimist.svg)](http://badge.fury.io/rb/optimist)
6
- [![Build Status](https://travis-ci.org/ManageIQ/optimist.svg)](https://travis-ci.org/ManageIQ/optimist)
7
- [![Code Climate](https://codeclimate.com/github/ManageIQ/optimist/badges/gpa.svg)](https://codeclimate.com/github/ManageIQ/optimist)
6
+ [![CI](https://github.com/ManageIQ/optimist/actions/workflows/ci.yaml/badge.svg)](https://github.com/ManageIQ/optimist/actions/workflows/ci.yaml)
7
+ [![Code Climate](https://codeclimate.com/github/ManageIQ/optimist.svg)](https://codeclimate.com/github/ManageIQ/optimist)
8
8
  [![Coverage Status](http://img.shields.io/coveralls/ManageIQ/optimist.svg)](https://coveralls.io/r/ManageIQ/optimist)
9
- [![Dependency Status](https://gemnasium.com/ManageIQ/optimist.svg)](https://gemnasium.com/ManageIQ/optimist)
10
9
 
11
10
  ## Documentation
12
11
 
data/lib/optimist.rb CHANGED
@@ -6,9 +6,7 @@
6
6
  require 'date'
7
7
 
8
8
  module Optimist
9
- # note: this is duplicated in gemspec
10
- # please change over there too
11
- VERSION = "3.0.0"
9
+ VERSION = "3.1.0"
12
10
 
13
11
  ## Thrown by Parser in the event of a commandline error. Not needed if
14
12
  ## you're using the Optimist::options entry.
@@ -199,6 +197,13 @@ class Parser
199
197
  @constraints << [:conflicts, syms]
200
198
  end
201
199
 
200
+ ## Marks two (or more!) options as required but mutually exclusive.
201
+ def either(*syms)
202
+ syms.each { |sym| raise ArgumentError, "unknown option '#{sym}'" unless @specs[sym] }
203
+ @constraints << [:conflicts, syms]
204
+ @constraints << [:either, syms]
205
+ end
206
+
202
207
  ## Defines a set of words which cause parsing to terminate when
203
208
  ## encountered, such that any options to the left of the word are
204
209
  ## parsed as usual, and options to the right of the word are left
@@ -298,13 +303,16 @@ class Parser
298
303
  ## check constraint satisfaction
299
304
  @constraints.each do |type, syms|
300
305
  constraint_sym = syms.find { |sym| given_args[sym] }
301
- next unless constraint_sym
302
306
 
303
307
  case type
304
308
  when :depends
309
+ next unless constraint_sym
305
310
  syms.each { |sym| raise CommandlineError, "--#{@specs[constraint_sym].long} requires --#{@specs[sym].long}" unless given_args.include? sym }
306
311
  when :conflicts
312
+ next unless constraint_sym
307
313
  syms.each { |sym| raise CommandlineError, "--#{@specs[constraint_sym].long} conflicts with --#{@specs[sym].long}" if given_args.include?(sym) && (sym != constraint_sym) }
314
+ when :either
315
+ raise CommandlineError, "one of #{syms.map { |sym| "--#{@specs[sym].long}" }.join(', ') } is required" if (syms & given_args.keys).size != 1
308
316
  end
309
317
  end
310
318
 
@@ -590,11 +598,11 @@ class Option
590
598
  @optshash = Hash.new()
591
599
  end
592
600
 
593
- def opts (key)
601
+ def opts(key)
594
602
  @optshash[key]
595
603
  end
596
604
 
597
- def opts= (o)
605
+ def opts=(o)
598
606
  @optshash = o
599
607
  end
600
608
 
@@ -620,7 +628,7 @@ class Option
620
628
 
621
629
  def required? ; opts(:required) ; end
622
630
 
623
- def parse (_paramlist, _neg_given)
631
+ def parse(_paramlist, _neg_given)
624
632
  raise NotImplementedError, "parse must be overridden for newly registered type"
625
633
  end
626
634
 
data/optimist.gemspec CHANGED
@@ -29,7 +29,8 @@ specify."
29
29
 
30
30
  spec.require_paths = ["lib"]
31
31
 
32
- spec.add_development_dependency "minitest", "~> 5.4.3"
33
- spec.add_development_dependency "rake", "~> 10.0"
34
32
  spec.add_development_dependency "chronic"
33
+ spec.add_development_dependency "manageiq-style"
34
+ spec.add_development_dependency "minitest", "~> 5.4.3"
35
+ spec.add_development_dependency "rake", ">= 10.0"
35
36
  end
@@ -253,6 +253,8 @@ class ParserTest < ::MiniTest::Test
253
253
  def test_long_detects_bad_names
254
254
  @p.opt "goodarg", "desc", :long => "none"
255
255
  @p.opt "goodarg2", "desc", :long => "--two"
256
+ @p.opt "goodarg3", "desc", :long => "arg-3"
257
+ @p.opt "goodarg4", "desc", :long => "--good-arg-four"
256
258
  assert_raises(ArgumentError) { @p.opt "badarg", "desc", :long => "" }
257
259
  assert_raises(ArgumentError) { @p.opt "badarg2", "desc", :long => "--" }
258
260
  assert_raises(ArgumentError) { @p.opt "badarg3", "desc", :long => "-one" }
@@ -347,6 +349,14 @@ class ParserTest < ::MiniTest::Test
347
349
  assert_equal true, opts[:defaultfalse]
348
350
  assert_equal true, opts[:defaulttrue]
349
351
 
352
+ ## using short form turns them all on, regardless of default
353
+ #
354
+ # (matches positve "non-no" long form)
355
+ opts = @p.parse %w(-d -e -f)
356
+ assert_equal true, opts[:defaultnone]
357
+ assert_equal true, opts[:defaultfalse]
358
+ assert_equal true, opts[:defaulttrue]
359
+
350
360
  ## using --no- form turns them off, regardless of default
351
361
  opts = @p.parse %w(--no-defaultfalse --no-defaulttrue --no-defaultnone)
352
362
  assert_equal false, opts[:defaultnone]
@@ -378,6 +388,14 @@ class ParserTest < ::MiniTest::Test
378
388
  assert_equal false, opts[:no_default_false]
379
389
  assert_equal false, opts[:no_default_true]
380
390
 
391
+ ## using short form turns them all off, regardless of default
392
+ #
393
+ # (matches positve "non-no" long form)
394
+ opts = @p.parse %w(-n -o -d)
395
+ assert_equal false, opts[:no_default_none]
396
+ assert_equal false, opts[:no_default_false]
397
+ assert_equal false, opts[:no_default_true]
398
+
381
399
  ## disallow double negatives for reasons of sanity preservation
382
400
  assert_raises(CommandlineError) { @p.parse %w(--no-no-default-true) }
383
401
  end
@@ -390,12 +408,12 @@ class ParserTest < ::MiniTest::Test
390
408
  opts = @p.parse %w(-a -b)
391
409
  assert_equal true, opts[:arg1]
392
410
  assert_equal true, opts[:arg2]
393
- assert_equal nil, opts[:arg3]
411
+ assert_nil opts[:arg3]
394
412
 
395
413
  opts = @p.parse %w(-ab)
396
414
  assert_equal true, opts[:arg1]
397
415
  assert_equal true, opts[:arg2]
398
- assert_equal nil, opts[:arg3]
416
+ assert_nil opts[:arg3]
399
417
 
400
418
  opts = @p.parse %w(-ac 4 -b)
401
419
  assert_equal true, opts[:arg1]
@@ -464,7 +482,7 @@ Options:
464
482
  assert_equal 5, opts[:arg]
465
483
  end
466
484
 
467
- def test_integer_formatting
485
+ def test_integer_formatting_default
468
486
  @p.opt :arg, "desc", :type => :integer, :short => "i", :default => 3
469
487
  opts = @p.parse %w(-i)
470
488
  assert_equal 3, opts[:arg]
@@ -745,6 +763,34 @@ Options:
745
763
  assert_raises(CommandlineError) { @p.parse %w(--one --mellow --two --jello) }
746
764
  end
747
765
 
766
+ def test_either
767
+ @p.opt :one
768
+ assert_raises(ArgumentError) { @p.either :one, :two }
769
+ @p.opt :two
770
+ @p.either :one, :two
771
+ @p.parse %w(--one)
772
+ @p.parse %w(--two)
773
+ assert_raises(CommandlineError) { @p.parse %w(--one --two) }
774
+ assert_raises(CommandlineError) { @p.parse %w() }
775
+
776
+ @p.opt :hello
777
+ @p.opt :yellow
778
+ @p.opt :mellow
779
+ @p.opt :jello
780
+ @p.either :hello, :yellow, :mellow, :jello
781
+ assert_raises(CommandlineError) { @p.parse %w(--hello --yellow --mellow --jello) }
782
+ assert_raises(CommandlineError) { @p.parse %w(--hello --mellow --jello) }
783
+ assert_raises(CommandlineError) { @p.parse %w(--hello --jello) }
784
+
785
+ @p.parse %w(--hello --one)
786
+ @p.parse %w(--jello --two)
787
+ @p.parse %w(--mellow --one)
788
+ @p.parse %w(--mellow --two)
789
+
790
+ assert_raises(CommandlineError) { @p.parse %w(--mellow --two --jello) }
791
+ assert_raises(CommandlineError) { @p.parse %w(--one --mellow --two --jello) }
792
+ end
793
+
748
794
  def test_conflict_error_messages
749
795
  @p.opt :one
750
796
  @p.opt "two"
metadata CHANGED
@@ -1,59 +1,73 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optimist
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Morgan
8
8
  - Keenan Brock
9
9
  - Jason Frey
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-08-24 00:00:00.000000000 Z
13
+ date: 2023-07-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: minitest
16
+ name: chronic
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - "~>"
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
- version: 5.4.3
21
+ version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - "~>"
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
- version: 5.4.3
28
+ version: '0'
29
29
  - !ruby/object:Gem::Dependency
30
- name: rake
30
+ name: manageiq-style
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: minitest
31
45
  requirement: !ruby/object:Gem::Requirement
32
46
  requirements:
33
47
  - - "~>"
34
48
  - !ruby/object:Gem::Version
35
- version: '10.0'
49
+ version: 5.4.3
36
50
  type: :development
37
51
  prerelease: false
38
52
  version_requirements: !ruby/object:Gem::Requirement
39
53
  requirements:
40
54
  - - "~>"
41
55
  - !ruby/object:Gem::Version
42
- version: '10.0'
56
+ version: 5.4.3
43
57
  - !ruby/object:Gem::Dependency
44
- name: chronic
58
+ name: rake
45
59
  requirement: !ruby/object:Gem::Requirement
46
60
  requirements:
47
61
  - - ">="
48
62
  - !ruby/object:Gem::Version
49
- version: '0'
63
+ version: '10.0'
50
64
  type: :development
51
65
  prerelease: false
52
66
  version_requirements: !ruby/object:Gem::Requirement
53
67
  requirements:
54
68
  - - ">="
55
69
  - !ruby/object:Gem::Version
56
- version: '0'
70
+ version: '10.0'
57
71
  description: |-
58
72
  Optimist is a commandline option parser for Ruby that just
59
73
  gets out of your way. One line of code per option is all you need to write.
@@ -65,11 +79,18 @@ executables: []
65
79
  extensions: []
66
80
  extra_rdoc_files: []
67
81
  files:
82
+ - ".codeclimate.yml"
83
+ - ".github/workflows/ci.yaml"
68
84
  - ".gitignore"
69
- - ".travis.yml"
85
+ - ".rubocop.yml"
86
+ - ".rubocop_cc.yml"
87
+ - ".rubocop_local.yml"
88
+ - ".whitesource"
89
+ - CHANGELOG.md
70
90
  - FAQ.txt
71
91
  - Gemfile
72
92
  - History.txt
93
+ - LICENSE.txt
73
94
  - README.md
74
95
  - Rakefile
75
96
  - lib/optimist.rb
@@ -91,7 +112,7 @@ metadata:
91
112
  changelog_uri: https://github.com/ManageIQ/optimist/blob/master/History.txt
92
113
  source_code_uri: https://github.com/ManageIQ/optimist/
93
114
  bug_tracker_uri: https://github.com/ManageIQ/optimist/issues
94
- post_install_message:
115
+ post_install_message:
95
116
  rdoc_options: []
96
117
  require_paths:
97
118
  - lib
@@ -106,9 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
127
  - !ruby/object:Gem::Version
107
128
  version: '0'
108
129
  requirements: []
109
- rubyforge_project:
110
- rubygems_version: 2.6.13
111
- signing_key:
130
+ rubygems_version: 3.2.33
131
+ signing_key:
112
132
  specification_version: 4
113
133
  summary: Optimist is a commandline option parser for Ruby that just gets out of your
114
134
  way.
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - "2.2"
5
- - "2.3.4"
6
- - "2.5.1"
7
- - jruby-head
8
- matrix:
9
- allow_failures:
10
- - rvm: jruby-head
11
- fast_finish: true