clasp-ruby 0.23.0.1 → 0.23.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +63 -52
- data/examples/cr-example.rb +16 -16
- data/examples/flag_and_option_specifications.md +25 -25
- data/examples/flag_and_option_specifications.rb +6 -6
- data/examples/show_usage_and_version.md +5 -5
- data/examples/show_usage_and_version.rb +1 -1
- data/examples/simple_command_line_no_specifications.rb +1 -1
- data/lib/clasp/arguments.rb +538 -537
- data/lib/clasp/clasp.rb +7 -7
- data/lib/clasp/cli.rb +140 -135
- data/lib/clasp/doc_.rb +3 -3
- data/lib/clasp/old_module.rb +3 -3
- data/lib/clasp/specifications.rb +337 -333
- data/lib/clasp/util/exceptions.rb +17 -17
- data/lib/clasp/util/value_parser.rb +97 -97
- data/lib/clasp/version.rb +15 -15
- data/lib/clasp-ruby.rb +3 -2
- data/lib/clasp.rb +3 -2
- data/test/scratch/test_list_command_line.rb +6 -6
- data/test/scratch/test_specifications.rb +14 -14
- data/test/scratch/test_usage.rb +6 -6
- data/test/scratch/test_usage_from_DATA.rb +1 -1
- data/test/scratch/test_usage_with_duplicate_specifications.rb +6 -6
- data/test/unit/tc_ARGV_rewrite.rb +36 -38
- data/test/unit/tc_arguments_1.rb +694 -694
- data/test/unit/tc_arguments_2.rb +52 -53
- data/test/unit/tc_arguments_3.rb +77 -77
- data/test/unit/tc_arguments_inspect.rb +55 -56
- 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 -132
- data/test/unit/tc_extras.rb +24 -26
- data/test/unit/tc_option_required.rb +38 -39
- data/test/unit/tc_option_value_aliases.rb +44 -44
- data/test/unit/tc_specifications.rb +7 -8
- data/test/unit/tc_typed_options.rb +204 -204
- data/test/unit/tc_usage.rb +112 -55
- data/test/unit/tc_with_action.rb +23 -24
- data/test/unit/ts_all.rb +1 -1
- metadata +5 -4
data/test/unit/tc_extras.rb
CHANGED
@@ -8,39 +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
|
|
45
|
-
|
46
|
-
|
@@ -8,44 +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
|
|
51
|
-
|
@@ -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
|
-
|
15
|
+
CLASP.Flag('--action=list', alias: '-l'),
|
16
16
|
CLASP.Flag('--action=change', alias: '-c'),
|
17
|
-
|
18
|
-
|
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
|
-
|
72
|
-
|
69
|
+
assert_equal '--action', args.options[0].name
|
70
|
+
assert_equal 'change', args.options[0].value
|
71
|
+
end
|
72
|
+
end
|
73
73
|
end
|
74
74
|
|
@@ -8,15 +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
|
|
22
|
-
|