optimist 3.0.1 → 3.1.0

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: 1cab432ee3e689f1cfbb1a53a0ef94e3c912cdc54fca85e5c92b2cd0a9b82561
4
- data.tar.gz: 67ec3054aa363ece24f9d0f57f03414581a1d11558c2df913a42ba1394db932f
3
+ metadata.gz: 87e142709336212fa484755022a85b8d833de889579b69a1b2fc35933bac88fd
4
+ data.tar.gz: 4ac2b33acae583f3ce444c105112c144a32affc52a8ab52980ab9772a107f8c3
5
5
  SHA512:
6
- metadata.gz: 1abab08da653806a765f24afc1c838eddefe7461a12a0e75505ddfa6eb86cc9d2f85205d407f71f420ebd61c64600c27159b4b1915d51ba36d02099b7163ce65
7
- data.tar.gz: a3f5fffb9d1e5ee2d479cd66ff8ecfaf2af34e41776be4b135abfb8281f54adcdcf6e23c98e834cf9b8f207c7141d67a3fe1ef2ce50274930a9200da796262a3
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/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.1"
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
 
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
@@ -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.1
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: 2020-04-20 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,8 +79,14 @@ 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
@@ -92,7 +112,7 @@ metadata:
92
112
  changelog_uri: https://github.com/ManageIQ/optimist/blob/master/History.txt
93
113
  source_code_uri: https://github.com/ManageIQ/optimist/
94
114
  bug_tracker_uri: https://github.com/ManageIQ/optimist/issues
95
- post_install_message:
115
+ post_install_message:
96
116
  rdoc_options: []
97
117
  require_paths:
98
118
  - lib
@@ -107,8 +127,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
127
  - !ruby/object:Gem::Version
108
128
  version: '0'
109
129
  requirements: []
110
- rubygems_version: 3.1.2
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,14 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.2
5
- - 2.3
6
- - 2.4
7
- - 2.5
8
- - 2.6
9
- - 2.7
10
- - jruby-head
11
- matrix:
12
- allow_failures:
13
- - rvm: jruby-head
14
- fast_finish: true