clasp-ruby 0.23.0.2 → 0.23.1
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 +4 -4
- data/examples/cr-example.rb +16 -16
- data/examples/flag_and_option_specifications.rb +15 -15
- data/examples/show_usage_and_version.rb +10 -11
- data/lib/clasp/arguments.rb +86 -87
- data/lib/clasp/clasp.rb +15 -11
- data/lib/clasp/cli.rb +135 -134
- data/lib/clasp/old_module.rb +8 -8
- data/lib/clasp/specifications.rb +325 -322
- data/lib/clasp/util/exceptions.rb +21 -22
- data/lib/clasp/util/value_parser.rb +99 -101
- data/lib/clasp/version.rb +12 -12
- data/lib/clasp-ruby.rb +8 -7
- data/lib/clasp.rb +8 -7
- data/test/scratch/test_list_command_line.rb +6 -6
- data/test/scratch/test_specifications.rb +14 -14
- data/test/scratch/test_usage.rb +5 -5
- data/test/scratch/test_usage_with_duplicate_specifications.rb +5 -5
- data/test/unit/tc_ARGV_rewrite.rb +36 -36
- data/test/unit/tc_arguments_1.rb +708 -708
- data/test/unit/tc_arguments_2.rb +43 -43
- data/test/unit/tc_arguments_3.rb +77 -77
- data/test/unit/tc_arguments_inspect.rb +55 -55
- data/test/unit/tc_cli.rb +4 -4
- data/test/unit/tc_default_value.rb +91 -91
- data/test/unit/tc_defaults_1.rb +38 -38
- data/test/unit/tc_examples_Arguments.rb +130 -130
- data/test/unit/tc_extras.rb +24 -24
- data/test/unit/tc_option_required.rb +38 -38
- data/test/unit/tc_option_value_aliases.rb +44 -44
- data/test/unit/tc_specifications.rb +7 -7
- data/test/unit/tc_typed_options.rb +200 -200
- data/test/unit/tc_usage.rb +69 -69
- data/test/unit/tc_with_action.rb +23 -23
- metadata +9 -8
data/test/unit/tc_extras.rb
CHANGED
@@ -8,37 +8,37 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_extras_1 < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
11
|
+
def test_Option_with_no_extras
|
12
12
|
|
13
|
-
|
13
|
+
o = CLASP.Option('--verbose')
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
assert_equal '--verbose', o.name
|
16
|
+
assert_equal [], o.aliases
|
17
|
+
assert_equal [], o.values_range
|
18
|
+
assert_equal nil, o.default_value
|
19
|
+
assert_equal ({}), o.extras
|
20
|
+
end
|
21
21
|
|
22
|
-
|
22
|
+
def test_Option_with_extras_as_symbol
|
23
23
|
|
24
|
-
|
24
|
+
o = CLASP.Option('--verbose', extras: :extras)
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
assert_equal '--verbose', o.name
|
27
|
+
assert_equal [], o.aliases
|
28
|
+
assert_equal [], o.values_range
|
29
|
+
assert_equal nil, o.default_value
|
30
|
+
assert_equal :extras, o.extras
|
31
|
+
end
|
32
32
|
|
33
|
-
|
33
|
+
def test_Option_with_extras_as_hash
|
34
34
|
|
35
|
-
|
35
|
+
o = CLASP.Option('--verbose', extras: { :abc => 'abc', :def => 'def' })
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
assert_equal '--verbose', o.name
|
38
|
+
assert_equal [], o.aliases
|
39
|
+
assert_equal [], o.values_range
|
40
|
+
assert_equal nil, o.default_value
|
41
|
+
assert_equal ({ :abc => 'abc', :def => 'def' }), o.extras
|
42
|
+
end
|
43
43
|
end
|
44
44
|
|
@@ -8,43 +8,43 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_Option_required < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
11
|
+
def test_Option_required_false_implicit
|
12
|
+
|
13
|
+
o = CLASP.Option('--verbose')
|
14
|
+
|
15
|
+
assert_equal '--verbose', o.name
|
16
|
+
assert_equal [], o.aliases
|
17
|
+
assert_equal [], o.values_range
|
18
|
+
assert_equal nil, o.default_value
|
19
|
+
assert_equal ({}), o.extras
|
20
|
+
assert !o.required?
|
21
|
+
assert_equal "'--verbose' not specified; use --help for usage", o.required_message
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_Option_required_false_explicit
|
25
|
+
|
26
|
+
o = CLASP.Option('--verbose', required: false, required_message: "\0Verbosity")
|
27
|
+
|
28
|
+
assert_equal '--verbose', o.name
|
29
|
+
assert_equal [], o.aliases
|
30
|
+
assert_equal [], o.values_range
|
31
|
+
assert_equal nil, o.default_value
|
32
|
+
assert_equal ({}), o.extras
|
33
|
+
assert !o.required?
|
34
|
+
assert_equal "Verbosity not specified; use --help for usage", o.required_message
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_Option_required_true
|
38
|
+
|
39
|
+
o = CLASP.Option('--verbose', required: true, required_message: 'Verbosity not given')
|
40
|
+
|
41
|
+
assert_equal '--verbose', o.name
|
42
|
+
assert_equal [], o.aliases
|
43
|
+
assert_equal [], o.values_range
|
44
|
+
assert_equal nil, o.default_value
|
45
|
+
assert_equal ({}), o.extras
|
46
|
+
assert o.required?
|
47
|
+
assert_equal "Verbosity not given", o.required_message
|
48
|
+
end
|
49
49
|
end
|
50
50
|
|
@@ -8,67 +8,67 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_OptionValueAliases_1 < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
11
|
+
def test_option_with_two_flag_specifications
|
12
12
|
|
13
|
-
|
13
|
+
specifications = [
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
CLASP.Flag('--action=list', alias: '-l'),
|
16
|
+
CLASP.Flag('--action=change', alias: '-c'),
|
17
|
+
CLASP.Option('--action', alias: '-a'),
|
18
|
+
]
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
# With no arguments
|
21
|
+
begin
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
argv = []
|
24
|
+
args = CLASP::Arguments.new argv, specifications
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
26
|
+
assert_equal 0, args.flags.size
|
27
|
+
assert_equal 0, args.options.size
|
28
|
+
assert_equal 0, args.values.size
|
29
|
+
end
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
# With option
|
32
|
+
begin
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
argv = %w{ --action=action1 }
|
35
|
+
args = CLASP::Arguments.new argv, specifications
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
37
|
+
assert_equal 0, args.flags.size
|
38
|
+
assert_equal 1, args.options.size
|
39
|
+
assert_equal 0, args.values.size
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
assert_equal '--action', args.options[0].name
|
42
|
+
assert_equal 'action1', args.options[0].value
|
43
|
+
end
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
# With option alias
|
46
|
+
begin
|
47
47
|
|
48
|
-
|
49
|
-
|
48
|
+
argv = %w{ -a action2 }
|
49
|
+
args = CLASP::Arguments.new argv, specifications
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
assert_equal 0, args.flags.size
|
52
|
+
assert_equal 1, args.options.size
|
53
|
+
assert_equal 0, args.values.size
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
55
|
+
assert_equal '--action', args.options[0].name
|
56
|
+
assert_equal 'action2', args.options[0].value
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
# With flag alias
|
60
|
+
begin
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
argv = %w{ -c }
|
63
|
+
args = CLASP::Arguments.new argv, specifications
|
64
64
|
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
assert_equal 0, args.flags.size
|
66
|
+
assert_equal 1, args.options.size
|
67
|
+
assert_equal 0, args.values.size
|
68
68
|
|
69
|
-
|
70
|
-
|
71
|
-
end
|
69
|
+
assert_equal '--action', args.options[0].name
|
70
|
+
assert_equal 'change', args.options[0].value
|
72
71
|
end
|
72
|
+
end
|
73
73
|
end
|
74
74
|
|
@@ -8,14 +8,14 @@ require 'test/unit'
|
|
8
8
|
|
9
9
|
class Test_Specifications_1 < Test::Unit::TestCase
|
10
10
|
|
11
|
-
|
11
|
+
def test_simple_Flag
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
flag_debug = CLASP.Flag('--name')
|
14
|
+
flag_logged = CLASP.Flag('--logged')
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
16
|
+
assert_equal flag_debug, flag_debug
|
17
|
+
assert_equal flag_debug, '--name'
|
18
|
+
assert_not_equal flag_logged, flag_debug
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|