parseopt 0.3.1 → 0.3.3

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
2
  SHA256:
3
- metadata.gz: 538791ca72e5a1b4ff32f3823f37c09c5d868b5d5e3b43ef7dadf4f548610c13
4
- data.tar.gz: c15c4e6cf7dfc53fc58bb6f368899c2ae750942bfa06cbc87d387dd9541329f1
3
+ metadata.gz: 8f37b8a20b16da97908c2b875df18a9cf55b5ac2b0496f20f2aac6c15992ed85
4
+ data.tar.gz: ca967511689defe39fc08d76095ca2cf0ebb4ec511ba15a9834bf4777af44a08
5
5
  SHA512:
6
- metadata.gz: f415e04d1ed5f88bb3b816e6010e82dd1044f65c2e962bde14921ca303abad7682a6bc4f83223af097374774a103376eefb0010b6726acdc0311c09122c6263b
7
- data.tar.gz: 54dafee252160772e4f2d0560723cf7304810482353dd4c9bd06ae173e30d6638ee192d75c7cbca7753bf6bf9386483b66a3a6a1894b329b2b8eec7dc5b7d3ab
6
+ metadata.gz: 54b4afb6bf990e36a16e0da7ada4cb98efe95a1db60ff2598a05231fd5e1a7b146f4b95b1b00d153cca813b5b2b10361f81d5777e106f7ba3bf816473e081163
7
+ data.tar.gz: 94ba0e01f56b8d41e146157550a45389cad4fa99b46afabeae9225aaaac9f72cb42aa1320004644ccbd8aa366e75356fdfc748670551f8803a067c31e0a3cce8
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  A very simple option parser.
2
2
 
3
+ It uses as inspiration Git's internal option parser code, and Ruby's
4
+ OptionParser.
5
+
3
6
  ```ruby
4
7
  require 'parseopt'
5
8
 
data/lib/parseopt.rb CHANGED
@@ -78,12 +78,9 @@ class ParseOpt
78
78
  def usage
79
79
  puts 'usage: %s' % @usage
80
80
  @list.values.uniq.each do |opt|
81
- s = ' '
82
- s << ''
83
- s << [opt.short&.prepend('-'), opt.long&.prepend('--')].compact.join(', ')
84
- s << ''
85
- s << '%*s%s' % [26 - s.size, '', opt.help] if opt.help
86
- puts s
81
+ opts = { '-' => opt.short, '--' => opt.long }.compact.map { |p,e| p + e }
82
+ s = ' ' + opts.join(', ')
83
+ puts opt.help ? '%*s%s' % [-26, s, opt.help] : s
87
84
  end
88
85
  end
89
86
 
metadata CHANGED
@@ -1,30 +1,54 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: parseopt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felipe Contreras
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-05-26 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: rake
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '13'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '13'
26
+ - !ruby/object:Gem::Dependency
27
+ name: test-unit
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '3'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3'
14
40
  email: felipe.contreras@gmail.com
15
41
  executables: []
16
42
  extensions: []
17
- extra_rdoc_files: []
43
+ extra_rdoc_files:
44
+ - README.md
18
45
  files:
19
46
  - README.md
20
- - Rakefile
21
47
  - lib/parseopt.rb
22
- - test/test_optparse.rb
23
48
  homepage: https://github.com/felipec/ruby-parseopt
24
49
  licenses:
25
50
  - GPL-2.0-only
26
51
  metadata: {}
27
- post_install_message:
28
52
  rdoc_options: []
29
53
  require_paths:
30
54
  - lib
@@ -32,16 +56,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
32
56
  requirements:
33
57
  - - ">="
34
58
  - !ruby/object:Gem::Version
35
- version: '0'
59
+ version: '3'
36
60
  required_rubygems_version: !ruby/object:Gem::Requirement
37
61
  requirements:
38
62
  - - ">="
39
63
  - !ruby/object:Gem::Version
40
64
  version: '0'
41
65
  requirements: []
42
- rubygems_version: 3.2.15
43
- signing_key:
66
+ rubygems_version: 3.7.1
44
67
  specification_version: 4
45
68
  summary: A very simple option parser.
46
- test_files:
47
- - test/test_optparse.rb
69
+ test_files: []
data/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- require 'rake/testtask'
2
-
3
- task default: :test
4
-
5
- Rake::TestTask.new do |t|
6
- t.libs << 'test'
7
- end
@@ -1,132 +0,0 @@
1
- require 'test/unit'
2
- require 'parseopt'
3
- require 'stringio'
4
-
5
- class ParseOptTest < Test::Unit::TestCase
6
-
7
- def test_bool
8
- bool = false
9
- run_opts('b', %w[-b]) { |v| bool = v }
10
- assert(bool)
11
- end
12
-
13
- def test_empty_bool
14
- bool = false
15
- run_opts('b', []) { |v| bool = v }
16
- assert(!bool)
17
- end
18
-
19
- def test_unknown
20
- run_opts('b', %w[-x], %w[-x])
21
- end
22
-
23
- def test_other
24
- run_opts('b', %w[foo], %w[foo])
25
- end
26
-
27
- def test_other_then_bool
28
- bool = false
29
- run_opts('b', %w[foo -b], %w[foo]) { |v| bool = v }
30
- assert(bool)
31
- end
32
-
33
- def test_double_dash
34
- run_opts('b', %w[-- -b], %w[-b])
35
- end
36
-
37
- def test_value
38
- str = 'default'
39
- run_opts('s', %w[-sfoo]) { |v| str = v }
40
- assert_equal('foo', str)
41
- end
42
-
43
- def test_long
44
- bool = false
45
- run_opts(['b', 'bool'], %w[--bool]) { |v| bool = v }
46
- assert(bool)
47
- end
48
-
49
- def test_long_value
50
- str = 'default'
51
- run_opts(['s', 'string'], %w[--string=foo]) { |v| str = v }
52
- assert_equal('foo', str)
53
- end
54
-
55
- def test_no_long
56
- bool = true
57
- run_opts(['b', 'bool'], %w[--no-bool]) { |v| bool = v }
58
- assert(!bool)
59
- end
60
-
61
- def test_init
62
- bool = false
63
- ParseOpt.new('test script') do |opts|
64
- opts.on('b', 'bool') { |v| bool = v }
65
- end.parse(%w[-b])
66
- assert(bool)
67
- end
68
-
69
- def test_usage
70
- expected = <<~EOF
71
- usage:
72
- -b, --bool
73
- EOF
74
- run_usage(['b', 'bool'], expected) { |opts| opts.usage }
75
- end
76
-
77
- def test_help
78
- expected = <<~EOF
79
- usage:
80
- -b, --bool
81
- EOF
82
- run_usage(['b', 'bool'], expected) do |opts|
83
- begin
84
- opts.parse(%w[-h])
85
- rescue SystemExit
86
- end
87
- end
88
- end
89
-
90
- def test_custom_usage
91
- expected = <<~EOF
92
- usage: test script
93
- -b, --bool
94
- EOF
95
- run_usage(['b', 'bool'], expected) do |opts|
96
- opts.usage = 'test script'
97
- opts.usage
98
- end
99
- end
100
-
101
- def test_option_help
102
- expected = <<~EOF
103
- usage:
104
- -b, --bool Boolean
105
- EOF
106
- run_usage(['b', 'bool', 'Boolean'], expected) { |opts| opts.usage }
107
- end
108
-
109
- private
110
-
111
- def run_opts(opt, args, result = [])
112
- opts = ParseOpt.new
113
- opts.on(*opt) { |v| yield v }
114
- assert_equal(result, opts.parse(args))
115
- end
116
-
117
- def run_usage(opt, expected)
118
- opts = ParseOpt.new
119
- opts.on(*opt)
120
- assert_equal(expected, capture { yield opts })
121
- end
122
-
123
- def capture
124
- stdout_save = $stdout
125
- $stdout = StringIO.new
126
- yield
127
- $stdout.string
128
- ensure
129
- $stdout = stdout_save
130
- end
131
-
132
- end