cmd-optparse.rb 0.5.0 → 0.5.2

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: 9cf82f634b0577123de20738385e9b15fbe0f62652ac8af58397d0226c928fdf
4
- data.tar.gz: a4831214ac1b1534d13309826f186e2d34087a7613111901e276c056f055e38d
3
+ metadata.gz: 2a992ee2e03576f3ca4f11a6973c4b00a1783f180032023e35233935c9d56cf8
4
+ data.tar.gz: 5efb1143314b76ef665b8809f9dccd98ddb600f9e7bd762dfdabe452930a003b
5
5
  SHA512:
6
- metadata.gz: 9683268f5c6a7e983a85e6018672c2448f080cf61c425f04666e58f38fca9f05735043355e02aeefae8cc45e0f7bb201024b0f94448762f27853fcee9958b9a2
7
- data.tar.gz: 4f117eae64d9fb5f18d38c7121dbc74dae9c565335ac0d520a10b690bcd421e0498846d052a0af2aa4049596cfdd14a6b7673bf11e7af35ce166a093ccf3375d
6
+ metadata.gz: 0e1f4eebc3ec6a6b7e8260f5f4829a6bd813cb8a810fd9b5c785494cf60481b0121daeb420a139b8e7154ebcb5b797ab052abddd483d07e27e7b3d10e55e6d85
7
+ data.tar.gz: e0a7957f80e7200d4ff6e35a0a7b5b9103fb10326bf1aa8ecf0847a4daf2110b494e7341e4b9aa120130f72c55633a4a0ebb1d773f21f3b11221ec122a463936
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  require "./lib/cmd-optparse"
3
-
4
3
  Gem::Specification.new do |spec|
5
4
  spec.name = File.basename(__FILE__, ".gemspec")
6
- spec.version = OptionParser::VERSION
5
+ spec.version = Cmd::OptionParser::VERSION
7
6
  spec.authors = ["0x1eef", "Nobu Nakada"]
8
7
  spec.email = ["0x1eef@protonmail.com"]
9
8
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: false
2
- class OptionParser::AC < OptionParser
2
+ class Cmd::OptionParser::AC < Cmd::OptionParser
3
3
  private
4
4
 
5
5
  def _check_ac_args(name, block)
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: false
2
2
  require 'date'
3
- OptionParser.accept(DateTime) do |s,|
3
+ Cmd::OptionParser.accept(DateTime) do |s,|
4
4
  begin
5
5
  DateTime.parse(s) if s
6
6
  rescue ArgumentError
7
- raise OptionParser::InvalidArgument, s
7
+ raise Cmd::OptionParser::InvalidArgument, s
8
8
  end
9
9
  end
10
- OptionParser.accept(Date) do |s,|
10
+ Cmd::OptionParser.accept(Date) do |s,|
11
11
  begin
12
12
  Date.parse(s) if s
13
13
  rescue ArgumentError
14
- raise OptionParser::InvalidArgument, s
14
+ raise Cmd::OptionParser::InvalidArgument, s
15
15
  end
16
16
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class OptionParser
3
+ class Cmd::OptionParser
4
4
  # :call-seq:
5
5
  # define_by_keywords(options, method, **params)
6
6
  #
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: false
2
2
  # -*- ruby -*-
3
3
  require 'shellwords'
4
- OptionParser.accept(Shellwords) {|s,| Shellwords.shellwords(s)}
4
+ Cmd::OptionParser.accept(Shellwords) {|s,| Shellwords.shellwords(s)}
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: false
2
2
  require 'time'
3
- OptionParser.accept(Time) do |s,|
3
+ Cmd::OptionParser.accept(Time) do |s,|
4
4
  begin
5
5
  (Time.httpdate(s) rescue Time.parse(s)) if s
6
6
  rescue
7
- raise OptionParser::InvalidArgument, s
7
+ raise Cmd::OptionParser::InvalidArgument, s
8
8
  end
9
9
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: false
2
2
  # -*- ruby -*-
3
3
  require 'uri'
4
- OptionParser.accept(URI) {|s,| URI.parse(s) if s}
4
+ Cmd::OptionParser.accept(URI) {|s,| URI.parse(s) if s}
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  # OptionParser internal utility
3
3
 
4
- class << OptionParser
4
+ class << Cmd::OptionParser
5
5
  def show_version(*pkgs)
6
6
  progname = ARGV.options.program_name
7
7
  result = false
data/lib/cmd/optparse.rb CHANGED
@@ -8,7 +8,6 @@
8
8
  # See OptionParser for documentation.
9
9
  #
10
10
 
11
-
12
11
  #--
13
12
  # == Developer Documentation (not for RDoc output)
14
13
  #
@@ -424,8 +423,8 @@
424
423
  # should be enough to learn how to use this class.
425
424
  # If you have any questions, file a ticket at http://bugs.ruby-lang.org.
426
425
  #
427
- class OptionParser
428
- VERSION = "0.5.0"
426
+ class Cmd::OptionParser
427
+ VERSION = "0.5.2"
429
428
 
430
429
  # :stopdoc:
431
430
  NoArgument = [NO_ARGUMENT = :NONE, nil].freeze
@@ -2333,9 +2332,9 @@ XXX
2333
2332
  # and DecimalNumeric. See Acceptable argument classes (in source code).
2334
2333
  #
2335
2334
  module Acceptables
2336
- const_set(:DecimalInteger, OptionParser::DecimalInteger)
2337
- const_set(:OctalInteger, OptionParser::OctalInteger)
2338
- const_set(:DecimalNumeric, OptionParser::DecimalNumeric)
2335
+ const_set(:DecimalInteger, DecimalInteger)
2336
+ const_set(:OctalInteger, OctalInteger)
2337
+ const_set(:DecimalNumeric, DecimalNumeric)
2339
2338
  end
2340
2339
 
2341
2340
  require_relative "option_parser/ac"
@@ -2345,10 +2344,7 @@ XXX
2345
2344
  require_relative "option_parser/shellwords"
2346
2345
  require_relative "option_parser/uri"
2347
2346
  require_relative "option_parser/version"
2348
- end
2349
2347
 
2350
- # ARGV is arguable by OptionParser
2351
- ARGV.extend(OptionParser::Arguable)
2352
-
2353
- # An alias for OptionParser.
2354
- OptParse = OptionParser # :nodoc:
2348
+ # ARGV is arguable by OptionParser
2349
+ ARGV.extend(Arguable)
2350
+ end
data/lib/cmd-optparse.rb CHANGED
@@ -1 +1,3 @@
1
- require_relative "cmd/optparse"
1
+ class Cmd
2
+ require_relative "cmd/optparse"
3
+ end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  require_relative 'test_optparse'
3
3
 
4
- class TestOptionParserAcceptable < TestOptionParser
4
+ class ::OptionParserAcceptable < ::OptionParser
5
5
 
6
6
  def setup
7
7
  super
@@ -10,11 +10,11 @@ class TestOptionParserAcceptable < TestOptionParser
10
10
  @opt.def_option("--numeric VAL", Numeric) { |v| @numeric = v }
11
11
 
12
12
  @opt.def_option("--decimal-integer VAL",
13
- OptionParser::DecimalInteger) { |i| @decimal_integer = i }
13
+ Cmd::OptionParser::DecimalInteger) { |i| @decimal_integer = i }
14
14
  @opt.def_option("--octal-integer VAL",
15
- OptionParser::OctalInteger) { |i| @octal_integer = i }
15
+ Cmd::OptionParser::OctalInteger) { |i| @octal_integer = i }
16
16
  @opt.def_option("--decimal-numeric VAL",
17
- OptionParser::DecimalNumeric) { |i| @decimal_numeric = i }
17
+ Cmd::OptionParser::DecimalNumeric) { |i| @decimal_numeric = i }
18
18
  end
19
19
 
20
20
  def test_integer
@@ -33,19 +33,19 @@ class TestOptionParserAcceptable < TestOptionParser
33
33
  assert_equal(%w"", no_error {@opt.parse!(%w"--integer 0x3")})
34
34
  assert_equal(3, @integer)
35
35
 
36
- assert_raise(OptionParser::InvalidArgument) do
36
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
37
37
  @opt.parse!(%w"--integer 0b")
38
38
  end
39
39
 
40
- assert_raise(OptionParser::InvalidArgument) do
40
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
41
41
  @opt.parse!(%w"--integer 09")
42
42
  end
43
43
 
44
- assert_raise(OptionParser::InvalidArgument) do
44
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
45
45
  @opt.parse!(%w"--integer 0x")
46
46
  end
47
47
 
48
- assert_raise(OptionParser::InvalidArgument) do
48
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
49
49
  @opt.parse!(%w"--integer 1234xyz")
50
50
  end
51
51
  end
@@ -66,11 +66,11 @@ class TestOptionParserAcceptable < TestOptionParser
66
66
  assert_equal(%w"", no_error {@opt.parse!(%w"--float 1E-2")})
67
67
  assert_in_epsilon(0.01, @float)
68
68
 
69
- assert_raise(OptionParser::InvalidArgument) do
69
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
70
70
  @opt.parse!(%w"--float 0e")
71
71
  end
72
72
 
73
- assert_raise(OptionParser::InvalidArgument) do
73
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
74
74
  @opt.parse!(%w"--float 1.234xyz")
75
75
  end
76
76
  end
@@ -91,15 +91,15 @@ class TestOptionParserAcceptable < TestOptionParser
91
91
  assert_equal(%w"", no_error {@opt.parse!(%w"--numeric 1.2/2.3")})
92
92
  assert_equal(Rational(12, 23), @numeric)
93
93
 
94
- assert_raise(OptionParser::InvalidArgument) do
94
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
95
95
  @opt.parse!(%w"--numeric 1/")
96
96
  end
97
97
 
98
- assert_raise(OptionParser::InvalidArgument) do
98
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
99
99
  @opt.parse!(%w"--numeric 12/34xyz")
100
100
  end
101
101
 
102
- assert_raise(OptionParser::InvalidArgument) do
102
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
103
103
  @opt.parse!(%w"--numeric 12x/34yz")
104
104
  end
105
105
  end
@@ -117,15 +117,15 @@ class TestOptionParserAcceptable < TestOptionParser
117
117
  assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-integer 09")})
118
118
  assert_equal(9, @decimal_integer)
119
119
 
120
- assert_raise(OptionParser::InvalidArgument) do
120
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
121
121
  @opt.parse!(%w"--decimal-integer 0b1")
122
122
  end
123
123
 
124
- assert_raise(OptionParser::InvalidArgument) do
124
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
125
125
  @opt.parse!(%w"--decimal-integer x")
126
126
  end
127
127
 
128
- assert_raise(OptionParser::InvalidArgument) do
128
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
129
129
  @opt.parse!(%w"--decimal-integer 1234xyz")
130
130
  end
131
131
  end
@@ -146,19 +146,19 @@ class TestOptionParserAcceptable < TestOptionParser
146
146
  assert_equal(%w"", no_error {@opt.parse!(%w"--octal-integer 011")})
147
147
  assert_equal(9, @octal_integer)
148
148
 
149
- assert_raise(OptionParser::InvalidArgument) do
149
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
150
150
  @opt.parse!(%w"--octal-integer 09")
151
151
  end
152
152
 
153
- assert_raise(OptionParser::InvalidArgument) do
153
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
154
154
  @opt.parse!(%w"--octal-integer 0b1")
155
155
  end
156
156
 
157
- assert_raise(OptionParser::InvalidArgument) do
157
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
158
158
  @opt.parse!(%w"--octal-integer x")
159
159
  end
160
160
 
161
- assert_raise(OptionParser::InvalidArgument) do
161
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
162
162
  @opt.parse!(%w"--octal-integer 01234xyz")
163
163
  end
164
164
  end
@@ -176,21 +176,21 @@ class TestOptionParserAcceptable < TestOptionParser
176
176
  assert_equal(%w"", no_error {@opt.parse!(%w"--decimal-numeric 1E2")})
177
177
  assert_in_delta(100.0, @decimal_numeric)
178
178
 
179
- assert_raise(OptionParser::InvalidArgument) do
179
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
180
180
  @opt.parse!(%w"--decimal-numeric 0b1")
181
181
  end
182
182
 
183
- e = assert_raise(OptionParser::InvalidArgument) do
183
+ e = assert_raise(Cmd::OptionParser::InvalidArgument) do
184
184
  @opt.parse!(%w"--decimal-numeric 09")
185
185
  end
186
186
 
187
187
  assert_equal("invalid argument: --decimal-numeric 09", e.message)
188
188
 
189
- assert_raise(OptionParser::InvalidArgument) do
189
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
190
190
  @opt.parse!(%w"--decimal-integer 1234xyz")
191
191
  end
192
192
 
193
- assert_raise(OptionParser::InvalidArgument) do
193
+ assert_raise(Cmd::OptionParser::InvalidArgument) do
194
194
  @opt.parse!(%w"--decimal-integer 12.34xyz")
195
195
  end
196
196
  end
@@ -2,9 +2,9 @@
2
2
  require 'test/unit'
3
3
  require 'optparse/ac'
4
4
 
5
- class TestOptionParserAutoConf < Test::Unit::TestCase
5
+ class ::OptionParserAutoConf < Test::Unit::TestCase
6
6
  def setup
7
- @opt = OptionParser::AC.new
7
+ @opt = Cmd::OptionParser::AC.new
8
8
  @foo = @bar = self.class
9
9
  @opt.ac_arg_enable("foo", "foo option") {|x| @foo = x}
10
10
  @opt.ac_arg_disable("bar", "bar option") {|x| @bar = x}
@@ -54,7 +54,7 @@ class TestOptionParserAutoConf < Test::Unit::TestCase
54
54
  def test_without
55
55
  @opt.parse!(%w"--without-zot")
56
56
  assert_nil(@zot)
57
- assert_raise(OptionParser::NeedlessArgument) {@opt.parse!(%w"--without-zot=foobar")}
57
+ assert_raise(Cmd::OptionParser::NeedlessArgument) {@opt.parse!(%w"--without-zot=foobar")}
58
58
  end
59
59
 
60
60
  def test_help
@@ -2,9 +2,9 @@
2
2
  require 'test/unit'
3
3
  require 'optparse'
4
4
 
5
- class TestOptionParserBashCompletion < Test::Unit::TestCase
5
+ class ::OptionParserBashCompletion < Test::Unit::TestCase
6
6
  def setup
7
- @opt = OptionParser.new
7
+ @opt = Cmd::OptionParser.new
8
8
  @opt.define("-z", "zzz") {}
9
9
  @opt.define("--foo") {}
10
10
  @opt.define("--bar=BAR") {}
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  require_relative 'test_optparse'
3
3
 
4
- class TestOptionParserCClass < TestOptionParser
4
+ class ::OptionParserCClass < ::OptionParser
5
5
  def test_no_argument
6
6
  flags = []
7
7
  @opt.def_option("-[a-z]") {|x| flags << x}
@@ -6,7 +6,7 @@ rescue LoadError
6
6
  return
7
7
  end
8
8
 
9
- class TestOptionParserDidYouMean < TestOptionParser
9
+ class ::OptionParserDidYouMean < ::OptionParser
10
10
  def setup
11
11
  super
12
12
  @opt.def_option("--foo", Integer) { |v| @foo = v }
@@ -29,19 +29,19 @@ class TestOptionParserDidYouMean < TestOptionParser
29
29
  end
30
30
 
31
31
  def test_no_suggestion
32
- assert_raise_with_message(OptionParser::InvalidOption, "invalid option: --cuz") do
32
+ assert_raise_with_message(Cmd::OptionParser::InvalidOption, "invalid option: --cuz") do
33
33
  @opt.permute!(%w"--cuz")
34
34
  end
35
35
  end
36
36
 
37
37
  def test_plain
38
- assert_raise_with_message(OptionParser::InvalidOption, /invalid option: --baa\nDid you mean\?\s+bar\s+baz\Z/) do
38
+ assert_raise_with_message(Cmd::OptionParser::InvalidOption, /invalid option: --baa\nDid you mean\?\s+bar\s+baz\Z/) do
39
39
  @opt.permute!(%w"--baa")
40
40
  end
41
41
  end
42
42
 
43
43
  def test_ambiguous
44
- assert_raise_with_message(OptionParser::AmbiguousOption, /ambiguous option: --ba\nDid you mean\?\s+bar\s+baz\Z/) do
44
+ assert_raise_with_message(Cmd::OptionParser::AmbiguousOption, /ambiguous option: --ba\nDid you mean\?\s+bar\s+baz\Z/) do
45
45
  @opt.permute!(%w"--ba")
46
46
  end
47
47
  end
@@ -2,9 +2,9 @@
2
2
  require 'test/unit'
3
3
  require 'optparse'
4
4
 
5
- class TestOptionParserGetopts < Test::Unit::TestCase
5
+ class ::OptionParserGetopts < Test::Unit::TestCase
6
6
  def setup
7
- @opt = OptionParser.new
7
+ @opt = Cmd::OptionParser.new
8
8
  end
9
9
 
10
10
  def test_short_noarg
@@ -3,7 +3,7 @@ require 'test/unit'
3
3
  require 'optparse'
4
4
  require 'optparse/kwargs'
5
5
 
6
- class TestOptionParserKwArg < Test::Unit::TestCase
6
+ class ::OptionParserKwArg < Test::Unit::TestCase
7
7
  class K
8
8
  def initialize(host:, port: 8080)
9
9
  @host = host
@@ -25,10 +25,10 @@ class TestOptionParserKwArg < Test::Unit::TestCase
25
25
  alias no_error assert_no_error
26
26
 
27
27
  def test_kwarg
28
- opt = OptionParser.new
28
+ opt = Cmd::OptionParser.new
29
29
  options = opt.define_by_keywords({}, K.instance_method(:initialize),
30
30
  port: [Integer])
31
- assert_raise(OptionParser::MissingArgument) {opt.parse!(%w"--host")}
31
+ assert_raise(Cmd::OptionParser::MissingArgument) {opt.parse!(%w"--host")}
32
32
  assert_nothing_raised {opt.parse!(%w"--host=localhost")}
33
33
  assert_equal("localhost", options[:host])
34
34
  assert_nothing_raised {opt.parse!(%w"--port")}
@@ -3,7 +3,7 @@ require 'test/unit'
3
3
  require 'optparse'
4
4
  require 'tmpdir'
5
5
 
6
- class TestOptionParserLoad < Test::Unit::TestCase
6
+ class ::OptionParserLoad < Test::Unit::TestCase
7
7
  def setup
8
8
  @tmpdir = Dir.mktmpdir("optparse_test-")
9
9
  @basename = File.basename($0, '.*')
@@ -19,7 +19,7 @@ class TestOptionParserLoad < Test::Unit::TestCase
19
19
 
20
20
  def new_parser
21
21
  @result = nil
22
- OptionParser.new do |opt|
22
+ Cmd::OptionParser.new do |opt|
23
23
  opt.on("--test=arg") {|v| @result = v}
24
24
  end
25
25
  end
@@ -1,23 +1,23 @@
1
1
  # frozen_string_literal: false
2
2
  require_relative 'test_optparse'
3
3
 
4
- module TestOptionParserNoArg
4
+ module ::OptionParserNoArg
5
5
  def setup
6
6
  super
7
7
  @opt.def_option "--with_underscore" do |x| @flag = x end
8
8
  @opt.def_option "--with-hyphen" do |x| @flag = x end
9
9
  end
10
10
 
11
- class Def1 < TestOptionParser
12
- include TestOptionParserNoArg
11
+ class Def1 < ::OptionParser
12
+ include ::OptionParserNoArg
13
13
  def setup
14
14
  super
15
15
  @opt.def_option("-x") {|x| @flag = x}
16
16
  @opt.def_option("--option") {|x| @flag = x}
17
17
  end
18
18
  end
19
- class Def2 < TestOptionParser
20
- include TestOptionParserNoArg
19
+ class Def2 < ::OptionParser
20
+ include ::OptionParserNoArg
21
21
  def setup
22
22
  super
23
23
  @opt.def_option("-x", "--option") {|x| @flag = x}
@@ -25,7 +25,7 @@ module TestOptionParserNoArg
25
25
  end
26
26
 
27
27
  def test_short
28
- assert_raise(OptionParser::InvalidOption) {@opt.parse!(%w"-xq")}
28
+ assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse!(%w"-xq")}
29
29
  assert_equal(%w"", no_error {@opt.parse!(%w"-x")})
30
30
  assert_equal(true, @flag)
31
31
  @flag = nil
@@ -34,11 +34,11 @@ module TestOptionParserNoArg
34
34
  end
35
35
 
36
36
  def test_abbrev
37
- assert_raise(OptionParser::InvalidOption) {@opt.parse!(%w"-oq")}
37
+ assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse!(%w"-oq")}
38
38
  assert_equal(%w"", no_error {@opt.parse!(%w"-o")})
39
39
  assert_equal(true, @flag)
40
40
  @flag = nil
41
- assert_raise(OptionParser::InvalidOption) {@opt.parse!(%w"-O")}
41
+ assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse!(%w"-O")}
42
42
  assert_nil(@flag)
43
43
  @flag = nil
44
44
  assert_equal(%w"foo", no_error {@opt.parse!(%w"-o foo")})
@@ -46,7 +46,7 @@ module TestOptionParserNoArg
46
46
  end
47
47
 
48
48
  def test_long
49
- assert_raise(OptionParser::NeedlessArgument) {@opt.parse!(%w"--option=x")}
49
+ assert_raise(Cmd::OptionParser::NeedlessArgument) {@opt.parse!(%w"--option=x")}
50
50
  assert_equal(%w"", no_error {@opt.parse!(%w"--opt")})
51
51
  assert_equal(true, @flag)
52
52
  @flag = nil
@@ -56,8 +56,8 @@ module TestOptionParserNoArg
56
56
 
57
57
  def test_ambiguous
58
58
  @opt.def_option("--open") {|x|}
59
- assert_raise(OptionParser::AmbiguousOption) {@opt.parse!(%w"--op")}
60
- assert_raise(OptionParser::AmbiguousOption) {@opt.parse!(%w"-o")}
59
+ assert_raise(Cmd::OptionParser::AmbiguousOption) {@opt.parse!(%w"--op")}
60
+ assert_raise(Cmd::OptionParser::AmbiguousOption) {@opt.parse!(%w"-o")}
61
61
  assert_equal(%w"", no_error {@opt.parse!(%w"--opt")})
62
62
  assert_equal(true, @flag)
63
63
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  require_relative 'test_optparse'
3
3
 
4
- class TestOptionParserOptArg < TestOptionParser
4
+ class ::OptionParserOptArg < ::OptionParser
5
5
  def setup
6
6
  super
7
7
  @opt.def_option("-x[VAL]") {|x| @flag = x}
@@ -2,9 +2,9 @@
2
2
  require 'test/unit'
3
3
  require 'cmd-optparse'
4
4
 
5
- class TestOptionParser < Test::Unit::TestCase
5
+ class ::OptionParserTest < Test::Unit::TestCase
6
6
  def setup
7
- @opt = OptionParser.new
7
+ @opt = Cmd::OptionParser.new
8
8
  @flag = self.class # cannot set by option
9
9
  end
10
10
 
@@ -98,11 +98,11 @@ class TestOptionParser < Test::Unit::TestCase
98
98
  assert_equal({F: 'foo', zrs: 'foo'}, result)
99
99
  end
100
100
 
101
- assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(--zr foo))}
102
- assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(--z foo))}
103
- assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zrs foo))}
104
- assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-zr foo))}
105
- assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
101
+ assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse(%w(--zr foo))}
102
+ assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse(%w(--z foo))}
103
+ assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse(%w(-zrs foo))}
104
+ assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse(%w(-zr foo))}
105
+ assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse(%w(-z foo))}
106
106
  end
107
107
 
108
108
  def test_raise_unknown
@@ -121,7 +121,7 @@ class TestOptionParser < Test::Unit::TestCase
121
121
  @opt.def_option(/^[^-]/) do |arg|
122
122
  assert(false, "Never gets called")
123
123
  end
124
- e = assert_raise(OptionParser::InvalidOption) {@opt.parse(%w(-t))}
124
+ e = assert_raise(Cmd::OptionParser::InvalidOption) {@opt.parse(%w(-t))}
125
125
  assert_equal(["-t"], e.args)
126
126
  end
127
127
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: false
2
2
  require_relative 'test_optparse'
3
3
 
4
- class TestOptionParserPlaceArg < TestOptionParser
4
+ class ::OptionParserPlaceArg < ::OptionParser
5
5
  def setup
6
6
  super
7
7
  @opt.def_option("-x [VAL]") {|x| @flag = x}
@@ -1,15 +1,15 @@
1
1
  # frozen_string_literal: false
2
2
  require_relative 'test_optparse'
3
3
 
4
- module TestOptionParserReqArg
4
+ module ::OptionParserReqArg
5
5
  def setup
6
6
  super
7
7
  @opt.def_option "--with_underscore=VAL" do |x| @flag = x end
8
8
  @opt.def_option "--with-hyphen=VAL" do |x| @flag = x end
9
9
  end
10
10
 
11
- class Def1 < TestOptionParser
12
- include TestOptionParserReqArg
11
+ class Def1 < ::OptionParser
12
+ include ::OptionParserReqArg
13
13
  def setup
14
14
  super
15
15
  @opt.def_option("-xVAL") {|x| @flag = x}
@@ -18,22 +18,22 @@ module TestOptionParserReqArg
18
18
  @reopt = nil
19
19
  end
20
20
  end
21
- class Def2 < TestOptionParser
22
- include TestOptionParserReqArg
21
+ class Def2 < ::OptionParser
22
+ include ::OptionParserReqArg
23
23
  def setup
24
24
  super
25
25
  @opt.def_option("-x", "--option=VAL") {|x| @flag = x}
26
26
  end
27
27
  end
28
- class Def3 < TestOptionParser
29
- include TestOptionParserReqArg
28
+ class Def3 < ::OptionParser
29
+ include ::OptionParserReqArg
30
30
  def setup
31
31
  super
32
32
  @opt.def_option("--option=VAL", "-x") {|x| @flag = x}
33
33
  end
34
34
  end
35
- class Def4 < TestOptionParser
36
- include TestOptionParserReqArg
35
+ class Def4 < ::OptionParser
36
+ include ::OptionParserReqArg
37
37
  def setup
38
38
  super
39
39
  @opt.def_option("-xVAL", "--option=VAL") {|x| @flag = x}
@@ -41,7 +41,7 @@ module TestOptionParserReqArg
41
41
  end
42
42
 
43
43
  def test_short
44
- assert_raise(OptionParser::MissingArgument) {@opt.parse!(%w"-x")}
44
+ assert_raise(Cmd::OptionParser::MissingArgument) {@opt.parse!(%w"-x")}
45
45
  assert_equal(%w"", no_error {@opt.parse!(%w"-x foo")})
46
46
  assert_equal("foo", @flag)
47
47
  assert_equal(%w"", no_error {@opt.parse!(%w"-xbar")})
@@ -51,7 +51,7 @@ module TestOptionParserReqArg
51
51
  end
52
52
 
53
53
  def test_abbrev
54
- assert_raise(OptionParser::MissingArgument) {@opt.parse!(%w"-o")}
54
+ assert_raise(Cmd::OptionParser::MissingArgument) {@opt.parse!(%w"-o")}
55
55
  assert_equal(%w"", no_error {@opt.parse!(%w"-o foo")})
56
56
  assert_equal("foo", @flag)
57
57
  assert_equal(%w"", no_error {@opt.parse!(%w"-obar")})
@@ -61,7 +61,7 @@ module TestOptionParserReqArg
61
61
  end
62
62
 
63
63
  def test_long
64
- assert_raise(OptionParser::MissingArgument) {@opt.parse!(%w"--opt")}
64
+ assert_raise(Cmd::OptionParser::MissingArgument) {@opt.parse!(%w"--opt")}
65
65
  assert_equal(%w"", no_error {@opt.parse!(%w"--opt foo")})
66
66
  assert_equal("foo", @flag)
67
67
  assert_equal(%w"foo", no_error {@opt.parse!(%w"--opt= foo")})
@@ -81,7 +81,7 @@ module TestOptionParserReqArg
81
81
  assert_equal("foo4", @flag)
82
82
  end
83
83
 
84
- class TestOptionParser::WithPattern < TestOptionParser
84
+ class ::OptionParser::WithPattern < ::OptionParser
85
85
  def test_pattern
86
86
  pat = num = nil
87
87
  @opt.def_option("--pattern=VAL", /(\w+)(?:\s*:\s*(\w+))?/) {|x, y, z| pat = [x, y, z]}
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: false
2
2
  require_relative 'test_optparse'
3
3
 
4
- class TestOptionParserSummaryTest < TestOptionParser
4
+ class ::OptionParserSummaryTest < ::OptionParser
5
5
  def test_short_clash
6
6
  r = nil
7
- o = OptionParser.new do |opts|
7
+ o = Cmd::OptionParser.new do |opts|
8
8
  opts.on("-f", "--first-option", "description 1", "description 2"){r = "first-option"}
9
9
  opts.on("-t", "--test-option"){r = "test-option"}
10
10
  opts.on("-t", "--another-test-option"){r = "another-test-option"}
@@ -21,32 +21,32 @@ class TestOptionParserSummaryTest < TestOptionParser
21
21
  end
22
22
 
23
23
  def test_banner
24
- o = OptionParser.new("foo bar")
24
+ o = Cmd::OptionParser.new("foo bar")
25
25
  assert_equal("foo bar", o.banner)
26
26
  end
27
27
 
28
28
  def test_banner_from_progname
29
- o = OptionParser.new
29
+ o = Cmd::OptionParser.new
30
30
  o.program_name = "foobar"
31
31
  assert_equal("Usage: foobar [options]\n", o.help)
32
32
  end
33
33
 
34
34
  def test_summary
35
- o = OptionParser.new("foo\nbar")
35
+ o = Cmd::OptionParser.new("foo\nbar")
36
36
  assert_equal("foo\nbar\n", o.to_s)
37
37
  assert_equal(["foo\n", "bar"], o.to_a)
38
38
  end
39
39
 
40
40
  def test_summary_containing_space
41
- # test for r35467. OptionParser#to_a shouldn't split str by spaces.
41
+ # test for r35467. Cmd::OptionParser#to_a shouldn't split str by spaces.
42
42
  bug6348 = '[ruby-dev:45568]'
43
- o = OptionParser.new("foo bar")
43
+ o = Cmd::OptionParser.new("foo bar")
44
44
  assert_equal("foo bar\n", o.to_s, bug6348)
45
45
  assert_equal(["foo bar"], o.to_a, bug6348)
46
46
  end
47
47
 
48
48
  def test_ver
49
- o = OptionParser.new("foo bar")
49
+ o = Cmd::OptionParser.new("foo bar")
50
50
  o.program_name = "foo"
51
51
  assert_warning('') {assert_nil(o.version)}
52
52
  assert_warning('') {assert_nil(o.release)}
@@ -58,7 +58,7 @@ class TestOptionParserSummaryTest < TestOptionParser
58
58
 
59
59
  # https://github.com/ruby/optparse/issues/37
60
60
  def test_very_long_without_short
61
- o = OptionParser.new do |opts|
61
+ o = Cmd::OptionParser.new do |opts|
62
62
  # This causes TypeError
63
63
  opts.on('', '--long-long-option-param-without-short', "Error desc") { options[:long_long_option_param_without_short] = true }
64
64
  opts.on('', '--long-option-param', "Long desc") { options[:long_option_param_without_short] = true }
@@ -2,9 +2,9 @@
2
2
  require 'test/unit'
3
3
  require 'optparse'
4
4
 
5
- class TestOptionParserZshCompletion < Test::Unit::TestCase
5
+ class ::OptionParserZshCompletion < Test::Unit::TestCase
6
6
  def setup
7
- @opt = OptionParser.new
7
+ @opt = Cmd::OptionParser.new
8
8
  @opt.define("-z", "zzz") {}
9
9
  @opt.define("--foo") {}
10
10
  @opt.define("--bar=BAR") {}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cmd-optparse.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - '0x1eef'