clasp-ruby 0.10.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +30 -0
- data/README.md +186 -0
- data/examples/cr-example.rb +63 -0
- data/lib/clasp-ruby.rb +51 -0
- data/lib/clasp.rb +51 -0
- data/lib/clasp/aliases.rb +256 -0
- data/lib/clasp/arguments.rb +467 -0
- data/lib/clasp/clasp.rb +54 -0
- data/lib/clasp/cli.rb +264 -0
- data/lib/clasp/doc_.rb +151 -0
- data/lib/clasp/old_module.rb +54 -0
- data/lib/clasp/version.rb +69 -0
- data/test/scratch/test_aliases.rb +38 -0
- data/test/scratch/test_list_command_line.rb +37 -0
- data/test/scratch/test_usage.rb +32 -0
- data/test/scratch/test_usage_with_duplicate_aliases.rb +30 -0
- data/test/unit/tc_ARGV_rewrite.rb +61 -0
- data/test/unit/tc_aliases.rb +75 -0
- data/test/unit/tc_arguments_1.rb +684 -0
- data/test/unit/tc_arguments_2.rb +65 -0
- data/test/unit/tc_arguments_3.rb +89 -0
- data/test/unit/tc_defaults_1.rb +73 -0
- data/test/unit/tc_examples_Arguments.rb +149 -0
- data/test/unit/tc_usage.rb +110 -0
- data/test/unit/ts_all.rb +13 -0
- metadata +70 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: clasp/old_module.rb
|
4
|
+
#
|
5
|
+
# Purpose: Introduces old module Clasp (which clashes with an existing
|
6
|
+
# gem)
|
7
|
+
#
|
8
|
+
# Created: 10th June 2016
|
9
|
+
# Updated: 10th June 2016
|
10
|
+
#
|
11
|
+
# Home: http://github.com/synesissoftware/CLASP.Ruby
|
12
|
+
#
|
13
|
+
# Author: Matthew Wilson
|
14
|
+
#
|
15
|
+
# Copyright (c) 2016, Matthew Wilson and Synesis Software
|
16
|
+
# All rights reserved.
|
17
|
+
#
|
18
|
+
# Redistribution and use in source and binary forms, with or without
|
19
|
+
# modification, are permitted provided that the following conditions are
|
20
|
+
# met:
|
21
|
+
#
|
22
|
+
# * Redistributions of source code must retain the above copyright
|
23
|
+
# notice, this list of conditions and the following disclaimer.
|
24
|
+
#
|
25
|
+
# * Redistributions in binary form must reproduce the above copyright
|
26
|
+
# notice, this list of conditions and the following disclaimer in the
|
27
|
+
# documentation and/or other materials provided with the distribution.
|
28
|
+
#
|
29
|
+
# * Neither the names of the copyright holder nor the names of its
|
30
|
+
# contributors may be used to endorse or promote products derived from
|
31
|
+
# this software without specific prior written permission.
|
32
|
+
#
|
33
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
34
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
35
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
36
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
37
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
38
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
39
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
40
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
41
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
42
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
43
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
44
|
+
#
|
45
|
+
# ######################################################################## #
|
46
|
+
|
47
|
+
|
48
|
+
require 'clasp'
|
49
|
+
|
50
|
+
# Backwards-compatible alias for the CLASP library's CLASP module
|
51
|
+
Clasp = CLASP
|
52
|
+
|
53
|
+
# ############################## end of file ############################# #
|
54
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: clasp/version.rb
|
4
|
+
#
|
5
|
+
# Purpose: Version for CLASP.Ruby library
|
6
|
+
#
|
7
|
+
# Created: 16th November 2014
|
8
|
+
# Updated: 11th June 2016
|
9
|
+
#
|
10
|
+
# Home: http://github.com/synesissoftware/CLASP.Ruby
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
# Copyright (c) 2014-2016, Matthew Wilson and Synesis Software
|
15
|
+
# All rights reserved.
|
16
|
+
#
|
17
|
+
# Redistribution and use in source and binary forms, with or without
|
18
|
+
# modification, are permitted provided that the following conditions are
|
19
|
+
# met:
|
20
|
+
#
|
21
|
+
# * Redistributions of source code must retain the above copyright
|
22
|
+
# notice, this list of conditions and the following disclaimer.
|
23
|
+
#
|
24
|
+
# * Redistributions in binary form must reproduce the above copyright
|
25
|
+
# notice, this list of conditions and the following disclaimer in the
|
26
|
+
# documentation and/or other materials provided with the distribution.
|
27
|
+
#
|
28
|
+
# * Neither the names of the copyright holder nor the names of its
|
29
|
+
# contributors may be used to endorse or promote products derived from
|
30
|
+
# this software without specific prior written permission.
|
31
|
+
#
|
32
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
33
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
34
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
35
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
36
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
37
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
38
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
39
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
40
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
41
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
42
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
43
|
+
#
|
44
|
+
# ######################################################################## #
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
=begin
|
49
|
+
=end
|
50
|
+
|
51
|
+
module CLASP
|
52
|
+
|
53
|
+
# Current version of the CLASP.Ruby library
|
54
|
+
VERSION = '0.10.2'
|
55
|
+
|
56
|
+
private
|
57
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
58
|
+
public
|
59
|
+
# Major version of the CLASP.Ruby library
|
60
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
61
|
+
# Minor version of the CLASP.Ruby library
|
62
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
63
|
+
# Revision version of the CLASP.Ruby library
|
64
|
+
VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
|
65
|
+
|
66
|
+
end # module CLASP
|
67
|
+
|
68
|
+
# ############################## end of file ############################# #
|
69
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
require 'recls'
|
7
|
+
|
8
|
+
Aliases = [
|
9
|
+
|
10
|
+
CLASP.Flag('--help', help: 'shows this help and quits'),
|
11
|
+
CLASP.Flag('--version', alias: '-v', help: 'shows this version and quits'),
|
12
|
+
|
13
|
+
CLASP.Option('--directory', alias: '-d', help: 'a directory within which to process'),
|
14
|
+
CLASP.Option('--patterns', alias: '-p', help: "one or more patterns, separated by '|' or '#{Recls::PATH_SEPARATOR}', against which the entries will be matched"),
|
15
|
+
|
16
|
+
CLASP.Option('--case-sensitive', alias: '-c', help: 'determines whether case sensitive', values_range: %W{ yes no true false }, default_value: false),
|
17
|
+
]
|
18
|
+
|
19
|
+
Arguments = CLASP::Arguments.new(ARGV, Aliases)
|
20
|
+
Flags = Arguments.flags
|
21
|
+
Options = Arguments.options
|
22
|
+
Values = Arguments.values
|
23
|
+
|
24
|
+
#Arguments.aliases.each do |a|
|
25
|
+
#
|
26
|
+
# puts a.inspect
|
27
|
+
#end
|
28
|
+
|
29
|
+
Flags.each do |f|
|
30
|
+
|
31
|
+
puts f.inspect
|
32
|
+
end
|
33
|
+
|
34
|
+
Options.each do |o|
|
35
|
+
|
36
|
+
puts o.inspect
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
|
7
|
+
Aliases = [
|
8
|
+
|
9
|
+
CLASP.Flag('--help', help: 'shows this help and quits'),
|
10
|
+
CLASP.Flag('--version', alias: '-v', help: 'shows this version and quits'),
|
11
|
+
|
12
|
+
CLASP.Option('--verbosity', aliases: %w{ -V --verbose }),
|
13
|
+
]
|
14
|
+
|
15
|
+
Args = CLASP::Arguments.new(ARGV, Aliases)
|
16
|
+
|
17
|
+
puts
|
18
|
+
puts "flags #{Args.flags.size}:"
|
19
|
+
Args.flags.each do |flag|
|
20
|
+
|
21
|
+
puts "\t#{flag}\t[#{flag.given_index}, #{flag.given_name}, #{flag.argument_alias}, #{flag.given_hyphens}, #{flag.given_label}, #{flag.name}]"
|
22
|
+
end
|
23
|
+
|
24
|
+
puts
|
25
|
+
puts "options #{Args.options.size}:"
|
26
|
+
Args.options.each do |option|
|
27
|
+
|
28
|
+
puts "\t#{option}\t[#{option.given_index}, #{option.given_name}, #{option.argument_alias}, #{option.given_hyphens}, #{option.given_label}, #{option.name}, #{option.value}]"
|
29
|
+
end
|
30
|
+
|
31
|
+
puts
|
32
|
+
puts "values #{Args.values.size}:"
|
33
|
+
Args.values.each do |value|
|
34
|
+
|
35
|
+
puts "\t#{value}"
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
|
7
|
+
Aliases = [
|
8
|
+
|
9
|
+
CLASP.Flag('--version', alias: '-v', help: 'shows the program version and quits'),
|
10
|
+
|
11
|
+
CLASP.Option('--verbosity', help: 'the verbosity', values: [ 'silent', 'quiet', 'succinct', 'chatty', 'verbose' ]),
|
12
|
+
CLASP.Option('--length', alias: '-l', help: 'specifies the length'),
|
13
|
+
CLASP.Flag('--verbosity=succinct', aliases: [ '--succinct', '-s' ]),
|
14
|
+
CLASP.Flag('--verbosity=verbose', alias: '--verbose'),
|
15
|
+
]
|
16
|
+
|
17
|
+
Arguments = CLASP::Arguments.new(ARGV, Aliases)
|
18
|
+
|
19
|
+
puts
|
20
|
+
puts '*' * 40
|
21
|
+
puts 'usage:'
|
22
|
+
puts
|
23
|
+
CLASP.show_usage(Aliases)
|
24
|
+
puts '*' * 40
|
25
|
+
|
26
|
+
puts 'version:'
|
27
|
+
puts
|
28
|
+
#CLASP.show_version Aliases, version: '1.2.3.4'
|
29
|
+
#CLASP.show_version Aliases, version_major: 1, version_minor: 2
|
30
|
+
CLASP.show_version Aliases, version: [ 1, 2, 3 ]
|
31
|
+
puts '*' * 40
|
32
|
+
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '..', '..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
|
7
|
+
Aliases = [
|
8
|
+
|
9
|
+
CLASP.Flag('--version', alias: '-v', help: 'shows the program version and quits'),
|
10
|
+
|
11
|
+
CLASP.Option('--verbosity', help: 'the verbosity', values: [ 'silent', 'quiet', 'succinct', 'chatty', 'verbose' ]),
|
12
|
+
CLASP.Option('--length', alias: '-l', help: 'specifies the length'),
|
13
|
+
CLASP.Flag('--verbosity=succinct', aliases: [ '--succinct', '-s' ]),
|
14
|
+
CLASP.Flag('--verbosity=verbose', aliases: [ '--verbose', '-v' ]),
|
15
|
+
]
|
16
|
+
|
17
|
+
Arguments = CLASP::Arguments.new(ARGV, Aliases)
|
18
|
+
|
19
|
+
puts
|
20
|
+
puts '*' * 40
|
21
|
+
puts 'usage:'
|
22
|
+
puts
|
23
|
+
CLASP.show_usage(Aliases)
|
24
|
+
puts '*' * 40
|
25
|
+
|
26
|
+
puts 'version:'
|
27
|
+
puts
|
28
|
+
CLASP.show_version Aliases, version: [ 1, 2, 3 ]
|
29
|
+
puts '*' * 40
|
30
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class Test_Arguments_4 < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_ARGV_rewrite_1
|
12
|
+
|
13
|
+
aliases = nil
|
14
|
+
argv = [ 'val1', '-f1', 'val2', '--' ]
|
15
|
+
argv_c = argv.dup
|
16
|
+
args = CLASP::Arguments.new argv, aliases
|
17
|
+
|
18
|
+
assert_equal 1, args.flags.size
|
19
|
+
assert_equal Hash.new, args.flags[0].extras
|
20
|
+
|
21
|
+
assert_equal 0, args.options.size
|
22
|
+
|
23
|
+
assert_equal 2, args.values.size
|
24
|
+
|
25
|
+
assert_same argv, args.argv
|
26
|
+
assert_equal 2, argv.size
|
27
|
+
assert_equal 'val1', argv[0]
|
28
|
+
assert_equal 'val2', argv[1]
|
29
|
+
|
30
|
+
assert_equal args.argv_original_copy, argv_c
|
31
|
+
assert_equal argv_c, args.argv_original_copy
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_ARGV_rewrite_2
|
35
|
+
|
36
|
+
aliases = nil
|
37
|
+
argv = [ 'val1', '-f1', 'val2', '--' ]
|
38
|
+
argv_c = argv.dup
|
39
|
+
args = CLASP::Arguments.new argv, aliases, mutate_argv: false
|
40
|
+
|
41
|
+
assert_equal 1, args.flags.size
|
42
|
+
assert_equal Hash.new, args.flags[0].extras
|
43
|
+
|
44
|
+
assert_equal 0, args.options.size
|
45
|
+
|
46
|
+
assert_equal 2, args.values.size
|
47
|
+
|
48
|
+
assert_same argv, args.argv
|
49
|
+
assert_equal 4, argv.size
|
50
|
+
assert_equal 'val1', argv[0]
|
51
|
+
assert_equal '-f1', argv[1]
|
52
|
+
assert_equal 'val2', argv[2]
|
53
|
+
assert_equal '--', argv[3]
|
54
|
+
|
55
|
+
assert_equal args.argv_original_copy, argv_c
|
56
|
+
assert_equal argv_c, args.argv_original_copy
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class Test_Aliases_1 < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_option_with_two_flag_aliases
|
12
|
+
|
13
|
+
aliases = [
|
14
|
+
|
15
|
+
CLASP.Flag('--action=list', alias: '-l'),
|
16
|
+
CLASP.Flag('--action=change', alias: '-c'),
|
17
|
+
CLASP.Option('--action', alias: '-a'),
|
18
|
+
]
|
19
|
+
|
20
|
+
# With no arguments
|
21
|
+
begin
|
22
|
+
|
23
|
+
argv = []
|
24
|
+
args = CLASP::Arguments.new argv, aliases
|
25
|
+
|
26
|
+
assert_equal 0, args.flags.size
|
27
|
+
assert_equal 0, args.options.size
|
28
|
+
assert_equal 0, args.values.size
|
29
|
+
end
|
30
|
+
|
31
|
+
# With option
|
32
|
+
begin
|
33
|
+
|
34
|
+
argv = %w{ --action=action1 }
|
35
|
+
args = CLASP::Arguments.new argv, aliases
|
36
|
+
|
37
|
+
assert_equal 0, args.flags.size
|
38
|
+
assert_equal 1, args.options.size
|
39
|
+
assert_equal 0, args.values.size
|
40
|
+
|
41
|
+
assert_equal '--action', args.options[0].name
|
42
|
+
assert_equal 'action1', args.options[0].value
|
43
|
+
end
|
44
|
+
|
45
|
+
# With option alias
|
46
|
+
begin
|
47
|
+
|
48
|
+
argv = %w{ -a action2 }
|
49
|
+
args = CLASP::Arguments.new argv, aliases
|
50
|
+
|
51
|
+
assert_equal 0, args.flags.size
|
52
|
+
assert_equal 1, args.options.size
|
53
|
+
assert_equal 0, args.values.size
|
54
|
+
|
55
|
+
assert_equal '--action', args.options[0].name
|
56
|
+
assert_equal 'action2', args.options[0].value
|
57
|
+
end
|
58
|
+
|
59
|
+
# With flag alias
|
60
|
+
begin
|
61
|
+
|
62
|
+
argv = %w{ -c }
|
63
|
+
args = CLASP::Arguments.new argv, aliases
|
64
|
+
|
65
|
+
assert_equal 0, args.flags.size
|
66
|
+
assert_equal 1, args.options.size
|
67
|
+
assert_equal 0, args.values.size
|
68
|
+
|
69
|
+
assert_equal '--action', args.options[0].name
|
70
|
+
assert_equal 'change', args.options[0].value
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,684 @@
|
|
1
|
+
#! /usr/bin/ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
4
|
+
|
5
|
+
require 'clasp'
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
|
9
|
+
class Test_Arguments < Test::Unit::TestCase
|
10
|
+
|
11
|
+
def test_empty_args
|
12
|
+
|
13
|
+
args = CLASP::Arguments.new([])
|
14
|
+
|
15
|
+
assert_equal 0, args.flags.size
|
16
|
+
|
17
|
+
assert_equal 0, args.options.size
|
18
|
+
|
19
|
+
assert_equal 0, args.values.size
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_one_value
|
23
|
+
|
24
|
+
args = CLASP::Arguments.new([ 'value1' ])
|
25
|
+
|
26
|
+
assert_equal 0, args.flags.size
|
27
|
+
|
28
|
+
assert_equal 0, args.options.size
|
29
|
+
|
30
|
+
assert_equal 1, args.values.size
|
31
|
+
assert_equal 'value1', args.values[0]
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_two_values
|
35
|
+
|
36
|
+
args = CLASP::Arguments.new([ 'value1', 'val2' ])
|
37
|
+
|
38
|
+
assert_equal 0, args.flags.size
|
39
|
+
|
40
|
+
assert_equal 0, args.options.size
|
41
|
+
|
42
|
+
assert_equal 2, args.values.size
|
43
|
+
assert_equal 'value1', args.values[0]
|
44
|
+
assert_equal 'val2', args.values[1]
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_ten_values
|
48
|
+
|
49
|
+
argv = (0 .. 10).map { |n| "value#{n}" }
|
50
|
+
|
51
|
+
args = CLASP::Arguments.new(argv)
|
52
|
+
|
53
|
+
assert_equal 0, args.flags.size
|
54
|
+
|
55
|
+
assert_equal 0, args.options.size
|
56
|
+
|
57
|
+
assert_equal argv.size, args.values.size
|
58
|
+
(0 ... argv.size).each do |n|
|
59
|
+
assert_equal argv[n], args.values[n]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_one_flag
|
64
|
+
|
65
|
+
args = CLASP::Arguments.new([ '-f1' ])
|
66
|
+
|
67
|
+
assert_equal 1, args.flags.size
|
68
|
+
assert_equal 0, args.flags[0].given_index
|
69
|
+
assert_equal '-f1', args.flags[0].to_s
|
70
|
+
assert_equal '-f1', args.flags[0].name
|
71
|
+
assert_equal 'f1', args.flags[0].given_label
|
72
|
+
assert_equal '-f1', args.flags[0].given_name
|
73
|
+
assert_equal 1, args.flags[0].given_hyphens
|
74
|
+
assert_nil args.flags[0].argument_alias
|
75
|
+
assert_equal Hash.new, args.flags[0].extras
|
76
|
+
|
77
|
+
assert_equal 0, args.options.size
|
78
|
+
|
79
|
+
assert_equal 0, args.values.size
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_two_flags
|
83
|
+
|
84
|
+
args = CLASP::Arguments.new([ '-f1', '--flag2' ])
|
85
|
+
|
86
|
+
assert_equal 2, args.flags.size
|
87
|
+
assert_equal 0, args.flags[0].given_index
|
88
|
+
assert_equal '-f1', args.flags[0].to_s
|
89
|
+
assert_equal '-f1', args.flags[0].name
|
90
|
+
assert_equal 'f1', args.flags[0].given_label
|
91
|
+
assert_equal '-f1', args.flags[0].given_name
|
92
|
+
assert_equal 1, args.flags[0].given_hyphens
|
93
|
+
assert_nil args.flags[0].argument_alias
|
94
|
+
assert_equal Hash.new, args.flags[0].extras
|
95
|
+
assert_equal 1, args.flags[1].given_index
|
96
|
+
assert_equal '--flag2', args.flags[1].to_s
|
97
|
+
assert_equal '--flag2', args.flags[1].name
|
98
|
+
assert_equal 'flag2', args.flags[1].given_label
|
99
|
+
assert_equal '--flag2', args.flags[1].given_name
|
100
|
+
assert_equal 2, args.flags[1].given_hyphens
|
101
|
+
assert_nil args.flags[1].argument_alias
|
102
|
+
assert_equal Hash.new, args.flags[1].extras
|
103
|
+
|
104
|
+
assert_equal 0, args.options.size
|
105
|
+
|
106
|
+
assert_equal 0, args.values.size
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_three_flags
|
110
|
+
|
111
|
+
args = CLASP::Arguments.new([ '-f1', '--flag2', '---x' ])
|
112
|
+
|
113
|
+
assert_equal 3, args.flags.size
|
114
|
+
assert_equal 0, args.flags[0].given_index
|
115
|
+
assert_equal '-f1', args.flags[0].to_s
|
116
|
+
assert_equal '-f1', args.flags[0].name
|
117
|
+
assert_equal 'f1', args.flags[0].given_label
|
118
|
+
assert_equal '-f1', args.flags[0].given_name
|
119
|
+
assert_equal 1, args.flags[0].given_hyphens
|
120
|
+
assert_nil args.flags[0].argument_alias
|
121
|
+
assert_equal Hash.new, args.flags[0].extras
|
122
|
+
assert_equal 1, args.flags[1].given_index
|
123
|
+
assert_equal '--flag2', args.flags[1].to_s
|
124
|
+
assert_equal '--flag2', args.flags[1].name
|
125
|
+
assert_equal 'flag2', args.flags[1].given_label
|
126
|
+
assert_equal '--flag2', args.flags[1].given_name
|
127
|
+
assert_equal 2, args.flags[1].given_hyphens
|
128
|
+
assert_nil args.flags[1].argument_alias
|
129
|
+
assert_equal Hash.new, args.flags[1].extras
|
130
|
+
assert_equal 2, args.flags[2].given_index
|
131
|
+
assert_equal '---x', args.flags[2].to_s
|
132
|
+
assert_equal '---x', args.flags[2].name
|
133
|
+
assert_equal 'x', args.flags[2].given_label
|
134
|
+
assert_equal '---x', args.flags[2].given_name
|
135
|
+
assert_equal 3, args.flags[2].given_hyphens
|
136
|
+
assert_nil args.flags[2].argument_alias
|
137
|
+
assert_equal Hash.new, args.flags[2].extras
|
138
|
+
|
139
|
+
assert_equal 0, args.options.size
|
140
|
+
|
141
|
+
assert_equal 0, args.values.size
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_one_option
|
145
|
+
|
146
|
+
args = CLASP::Arguments.new([ '-o1=v1' ])
|
147
|
+
|
148
|
+
assert_equal 0, args.flags.size
|
149
|
+
|
150
|
+
assert_equal 1, args.options.size
|
151
|
+
assert_equal 0, args.options[0].given_index
|
152
|
+
assert_equal '-o1=v1', args.options[0].to_s
|
153
|
+
assert_equal '-o1', args.options[0].name
|
154
|
+
assert_equal 'o1', args.options[0].given_label
|
155
|
+
assert_equal 'v1', args.options[0].value
|
156
|
+
assert_equal '-o1', args.options[0].given_name
|
157
|
+
assert_equal 1, args.options[0].given_hyphens
|
158
|
+
assert_nil args.options[0].argument_alias
|
159
|
+
assert_equal Hash.new, args.options[0].extras
|
160
|
+
|
161
|
+
assert_equal 0, args.values.size
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_two_options
|
165
|
+
|
166
|
+
args = CLASP::Arguments.new([ '-o1=v1', '--option2=value2' ])
|
167
|
+
|
168
|
+
assert_equal 0, args.flags.size
|
169
|
+
|
170
|
+
assert_equal 2, args.options.size
|
171
|
+
assert_equal '-o1=v1', args.options[0].to_s
|
172
|
+
assert_equal '-o1', args.options[0].name
|
173
|
+
assert_equal 'o1', args.options[0].given_label
|
174
|
+
assert_equal 'v1', args.options[0].value
|
175
|
+
assert_equal '-o1', args.options[0].given_name
|
176
|
+
assert_equal 1, args.options[0].given_hyphens
|
177
|
+
assert_nil args.options[0].argument_alias
|
178
|
+
assert_equal Hash.new, args.options[0].extras
|
179
|
+
assert_equal '--option2=value2', args.options[1].to_s
|
180
|
+
assert_equal '--option2', args.options[1].name
|
181
|
+
assert_equal 'option2', args.options[1].given_label
|
182
|
+
assert_equal 'value2', args.options[1].value
|
183
|
+
assert_equal '--option2', args.options[1].given_name
|
184
|
+
assert_equal 2, args.options[1].given_hyphens
|
185
|
+
assert_nil args.options[1].argument_alias
|
186
|
+
assert_equal Hash.new, args.options[1].extras
|
187
|
+
|
188
|
+
assert_equal 0, args.values.size
|
189
|
+
end
|
190
|
+
|
191
|
+
def test_three_options
|
192
|
+
|
193
|
+
args = CLASP::Arguments.new([ '-o1=v1', '--option2=value2', '---the-third-option=the third value' ])
|
194
|
+
|
195
|
+
assert_equal 0, args.flags.size
|
196
|
+
|
197
|
+
assert_equal 3, args.options.size
|
198
|
+
assert_equal '-o1=v1', args.options[0].to_s
|
199
|
+
assert_equal '-o1', args.options[0].name
|
200
|
+
assert_equal 'o1', args.options[0].given_label
|
201
|
+
assert_equal 'v1', args.options[0].value
|
202
|
+
assert_equal '-o1', args.options[0].given_name
|
203
|
+
assert_equal 1, args.options[0].given_hyphens
|
204
|
+
assert_nil args.options[0].argument_alias
|
205
|
+
assert_equal Hash.new, args.options[0].extras
|
206
|
+
assert_equal '--option2=value2', args.options[1].to_s
|
207
|
+
assert_equal '--option2', args.options[1].name
|
208
|
+
assert_equal 'option2', args.options[1].given_label
|
209
|
+
assert_equal 'value2', args.options[1].value
|
210
|
+
assert_equal '--option2', args.options[1].given_name
|
211
|
+
assert_equal 2, args.options[1].given_hyphens
|
212
|
+
assert_nil args.options[1].argument_alias
|
213
|
+
assert_equal Hash.new, args.options[1].extras
|
214
|
+
assert_equal '---the-third-option=the third value', args.options[2].to_s
|
215
|
+
assert_equal '---the-third-option', args.options[2].name
|
216
|
+
assert_equal 'the-third-option', args.options[2].given_label
|
217
|
+
assert_equal 'the third value', args.options[2].value
|
218
|
+
assert_equal '---the-third-option', args.options[2].given_name
|
219
|
+
assert_equal 3, args.options[2].given_hyphens
|
220
|
+
assert_nil args.options[2].argument_alias
|
221
|
+
assert_equal Hash.new, args.options[2].extras
|
222
|
+
|
223
|
+
assert_equal 0, args.values.size
|
224
|
+
end
|
225
|
+
|
226
|
+
def test_one_flag_and_one_option_and_one_value
|
227
|
+
|
228
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '--first-option=val1' ]
|
229
|
+
|
230
|
+
assert_equal 1, args.flags.size
|
231
|
+
assert_equal '-f1', args.flags[0].to_s
|
232
|
+
assert_equal '-f1', args.flags[0].name
|
233
|
+
assert_equal 'f1', args.flags[0].given_label
|
234
|
+
assert_equal '-f1', args.flags[0].given_name
|
235
|
+
assert_equal 1, args.flags[0].given_hyphens
|
236
|
+
assert_nil args.flags[0].argument_alias
|
237
|
+
assert_equal Hash.new, args.flags[0].extras
|
238
|
+
|
239
|
+
assert_equal 1, args.options.size
|
240
|
+
assert_equal '--first-option=val1', args.options[0].to_s
|
241
|
+
assert_equal '--first-option', args.options[0].name
|
242
|
+
assert_equal 'first-option', args.options[0].given_label
|
243
|
+
assert_equal 'val1', args.options[0].value
|
244
|
+
assert_equal '--first-option', args.options[0].given_name
|
245
|
+
assert_equal 2, args.options[0].given_hyphens
|
246
|
+
assert_equal Hash.new, args.options[0].extras
|
247
|
+
|
248
|
+
assert_equal 1, args.values.size
|
249
|
+
assert_equal 'value1', args.values[0]
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_double_hyphen_1
|
253
|
+
|
254
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '--', '-f2' ]
|
255
|
+
|
256
|
+
assert_equal 1, args.flags.size
|
257
|
+
assert_equal '-f1', args.flags[0].to_s
|
258
|
+
assert_equal '-f1', args.flags[0].name
|
259
|
+
assert_equal 'f1', args.flags[0].given_label
|
260
|
+
assert_equal '-f1', args.flags[0].given_name
|
261
|
+
assert_equal 1, args.flags[0].given_hyphens
|
262
|
+
assert_nil args.flags[0].argument_alias
|
263
|
+
assert_equal Hash.new, args.flags[0].extras
|
264
|
+
|
265
|
+
assert_equal 0, args.options.size
|
266
|
+
|
267
|
+
assert_equal 2, args.values.size
|
268
|
+
assert_equal 'value1', args.values[0]
|
269
|
+
assert_equal '-f2', args.values[1]
|
270
|
+
end
|
271
|
+
|
272
|
+
def test_double_hyphen_2
|
273
|
+
|
274
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '--', '-f2', '--', '--option1=v1' ]
|
275
|
+
|
276
|
+
assert_equal 1, args.flags.size
|
277
|
+
assert_equal '-f1', args.flags[0].to_s
|
278
|
+
assert_equal '-f1', args.flags[0].name
|
279
|
+
assert_equal 'f1', args.flags[0].given_label
|
280
|
+
assert_equal '-f1', args.flags[0].given_name
|
281
|
+
assert_equal 1, args.flags[0].given_hyphens
|
282
|
+
assert_nil args.flags[0].argument_alias
|
283
|
+
assert_equal Hash.new, args.flags[0].extras
|
284
|
+
|
285
|
+
assert_equal 0, args.options.size
|
286
|
+
|
287
|
+
assert_equal 4, args.values.size
|
288
|
+
assert_equal 'value1', args.values[0]
|
289
|
+
assert_equal '-f2', args.values[1]
|
290
|
+
assert_equal '--', args.values[2]
|
291
|
+
assert_equal '--option1=v1', args.values[3]
|
292
|
+
end
|
293
|
+
|
294
|
+
def test_double_hyphen_3
|
295
|
+
|
296
|
+
aliases = [
|
297
|
+
CLASP.Option('--password', alias: '-p', extras: 'extra'),
|
298
|
+
]
|
299
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-p', '--', 'value2' ], aliases
|
300
|
+
|
301
|
+
assert_equal 1, args.flags.size
|
302
|
+
assert_equal '-f1', args.flags[0].to_s
|
303
|
+
assert_equal '-f1', args.flags[0].name
|
304
|
+
assert_equal 'f1', args.flags[0].given_label
|
305
|
+
assert_equal '-f1', args.flags[0].given_name
|
306
|
+
assert_equal 1, args.flags[0].given_hyphens
|
307
|
+
assert_nil args.flags[0].argument_alias
|
308
|
+
assert_equal Hash.new, args.flags[0].extras
|
309
|
+
|
310
|
+
assert_equal 1, args.options.size
|
311
|
+
assert_equal '--password=', args.options[0].to_s
|
312
|
+
assert_equal '--password', args.options[0].name
|
313
|
+
assert_equal 'p', args.options[0].given_label
|
314
|
+
assert_nil args.options[0].value
|
315
|
+
assert_equal '-p', args.options[0].given_name
|
316
|
+
assert_equal 1, args.options[0].given_hyphens
|
317
|
+
assert_equal 'extra', args.options[0].extras
|
318
|
+
|
319
|
+
assert_equal 2, args.values.size
|
320
|
+
assert_equal 'value1', args.values[0]
|
321
|
+
assert_equal 'value2', args.values[1]
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_flag_aliases_1
|
325
|
+
|
326
|
+
aliases = [
|
327
|
+
]
|
328
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-x', '--delete' ], aliases
|
329
|
+
|
330
|
+
assert_equal 3, args.flags.size
|
331
|
+
assert_equal '-f1', args.flags[0].to_s
|
332
|
+
assert_equal '-f1', args.flags[0].name
|
333
|
+
assert_equal 'f1', args.flags[0].given_label
|
334
|
+
assert_equal '-f1', args.flags[0].given_name
|
335
|
+
assert_equal 1, args.flags[0].given_hyphens
|
336
|
+
assert_nil args.flags[0].argument_alias
|
337
|
+
assert_equal Hash.new, args.flags[0].extras
|
338
|
+
assert_equal '-x', args.flags[1].to_s
|
339
|
+
assert_equal '-x', args.flags[1].name
|
340
|
+
assert_equal 'x', args.flags[1].given_label
|
341
|
+
assert_equal '-x', args.flags[1].given_name
|
342
|
+
assert_equal 1, args.flags[1].given_hyphens
|
343
|
+
assert_nil args.flags[1].argument_alias
|
344
|
+
assert_equal Hash.new, args.flags[1].extras
|
345
|
+
assert_equal '--delete', args.flags[2].to_s
|
346
|
+
assert_equal '--delete', args.flags[2].name
|
347
|
+
assert_equal 'delete', args.flags[2].given_label
|
348
|
+
assert_equal '--delete', args.flags[2].given_name
|
349
|
+
assert_equal 2, args.flags[2].given_hyphens
|
350
|
+
assert_nil args.flags[2].argument_alias
|
351
|
+
assert_equal Hash.new, args.flags[2].extras
|
352
|
+
|
353
|
+
assert_equal 0, args.options.size
|
354
|
+
|
355
|
+
assert_equal 1, args.values.size
|
356
|
+
assert_equal 'value1', args.values[0]
|
357
|
+
end
|
358
|
+
|
359
|
+
def test_flag_aliases_2
|
360
|
+
|
361
|
+
aliases = [
|
362
|
+
CLASP.Flag('--expand', alias: '-x')
|
363
|
+
]
|
364
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-x', '--delete' ], aliases
|
365
|
+
|
366
|
+
assert_equal 3, args.flags.size
|
367
|
+
assert_equal '-f1', args.flags[0].to_s
|
368
|
+
assert_equal '-f1', args.flags[0].name
|
369
|
+
assert_equal 'f1', args.flags[0].given_label
|
370
|
+
assert_equal '-f1', args.flags[0].given_name
|
371
|
+
assert_equal 1, args.flags[0].given_hyphens
|
372
|
+
assert_nil args.flags[0].argument_alias
|
373
|
+
assert_equal Hash.new, args.flags[0].extras
|
374
|
+
assert_equal '--expand', args.flags[1].to_s
|
375
|
+
assert_equal '--expand', args.flags[1].name
|
376
|
+
assert_equal 'x', args.flags[1].given_label
|
377
|
+
assert_equal '-x', args.flags[1].given_name
|
378
|
+
assert_equal 1, args.flags[1].given_hyphens
|
379
|
+
assert_equal aliases[0], args.flags[1].argument_alias
|
380
|
+
assert_equal Hash.new, args.flags[1].extras
|
381
|
+
assert_equal '--delete', args.flags[2].to_s
|
382
|
+
assert_equal '--delete', args.flags[2].name
|
383
|
+
assert_equal 'delete', args.flags[2].given_label
|
384
|
+
assert_equal '--delete', args.flags[2].given_name
|
385
|
+
assert_equal 2, args.flags[2].given_hyphens
|
386
|
+
assert_nil args.flags[2].argument_alias
|
387
|
+
assert_equal Hash.new, args.flags[2].extras
|
388
|
+
|
389
|
+
assert_equal 0, args.options.size
|
390
|
+
|
391
|
+
assert_equal 1, args.values.size
|
392
|
+
assert_equal 'value1', args.values[0]
|
393
|
+
end
|
394
|
+
|
395
|
+
def test_flag_aliases_3
|
396
|
+
|
397
|
+
aliases = [
|
398
|
+
CLASP.Flag('--expand', aliases: [ '-x', '--x' ], extras: %w{ e x t r a })
|
399
|
+
]
|
400
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-x', '--delete', '--x' ], aliases
|
401
|
+
|
402
|
+
assert_equal 4, args.flags.size
|
403
|
+
assert_equal '-f1', args.flags[0].to_s
|
404
|
+
assert_equal '-f1', args.flags[0].name
|
405
|
+
assert_equal 'f1', args.flags[0].given_label
|
406
|
+
assert_equal '-f1', args.flags[0].given_name
|
407
|
+
assert_equal 1, args.flags[0].given_hyphens
|
408
|
+
assert_nil args.flags[0].argument_alias
|
409
|
+
assert_equal Hash.new, args.flags[0].extras
|
410
|
+
assert_equal '--expand', args.flags[1].to_s
|
411
|
+
assert_equal '--expand', args.flags[1].name
|
412
|
+
assert_equal 'x', args.flags[1].given_label
|
413
|
+
assert_equal '-x', args.flags[1].given_name
|
414
|
+
assert_equal 1, args.flags[1].given_hyphens
|
415
|
+
assert_equal aliases[0], args.flags[1].argument_alias
|
416
|
+
assert_equal [ 'e', 'x', 't', 'r', 'a' ], args.flags[1].extras
|
417
|
+
assert_equal '--delete', args.flags[2].to_s
|
418
|
+
assert_equal '--delete', args.flags[2].name
|
419
|
+
assert_equal 'delete', args.flags[2].given_label
|
420
|
+
assert_equal '--delete', args.flags[2].given_name
|
421
|
+
assert_equal 2, args.flags[2].given_hyphens
|
422
|
+
assert_nil args.flags[2].argument_alias
|
423
|
+
assert_equal Hash.new, args.flags[2].extras
|
424
|
+
assert_equal '--expand', args.flags[3].to_s
|
425
|
+
assert_equal '--expand', args.flags[3].name
|
426
|
+
assert_equal 'x', args.flags[3].given_label
|
427
|
+
assert_equal '--x', args.flags[3].given_name
|
428
|
+
assert_equal 2, args.flags[3].given_hyphens
|
429
|
+
assert_equal aliases[0], args.flags[3].argument_alias
|
430
|
+
assert_equal [ 'e', 'x', 't', 'r', 'a' ], args.flags[3].extras
|
431
|
+
|
432
|
+
assert_equal 0, args.options.size
|
433
|
+
|
434
|
+
assert_equal 1, args.values.size
|
435
|
+
assert_equal 'value1', args.values[0]
|
436
|
+
end
|
437
|
+
|
438
|
+
def test_option_aliases_1
|
439
|
+
|
440
|
+
aliases = [
|
441
|
+
]
|
442
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-o=value' ], aliases
|
443
|
+
|
444
|
+
assert_equal 1, args.flags.size
|
445
|
+
assert_equal '-f1', args.flags[0].to_s
|
446
|
+
assert_equal '-f1', args.flags[0].name
|
447
|
+
assert_equal 'f1', args.flags[0].given_label
|
448
|
+
assert_equal '-f1', args.flags[0].given_name
|
449
|
+
assert_equal 1, args.flags[0].given_hyphens
|
450
|
+
assert_equal Hash.new, args.flags[0].extras
|
451
|
+
|
452
|
+
assert_equal 1, args.options.size
|
453
|
+
assert_equal '-o=value', args.options[0].to_s
|
454
|
+
assert_equal '-o', args.options[0].name
|
455
|
+
assert_equal 'o', args.options[0].given_label
|
456
|
+
assert_equal 'value', args.options[0].value
|
457
|
+
assert_equal '-o', args.options[0].given_name
|
458
|
+
assert_equal 1, args.options[0].given_hyphens
|
459
|
+
assert_equal Hash.new, args.options[0].extras
|
460
|
+
|
461
|
+
assert_equal 1, args.values.size
|
462
|
+
assert_equal 'value1', args.values[0]
|
463
|
+
end
|
464
|
+
|
465
|
+
def test_option_aliases_2
|
466
|
+
|
467
|
+
aliases = [
|
468
|
+
CLASP.Option('--option', aliases: [ '-o' ])
|
469
|
+
]
|
470
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-o=value' ], aliases
|
471
|
+
|
472
|
+
assert_equal 1, args.flags.size
|
473
|
+
assert_equal '-f1', args.flags[0].to_s
|
474
|
+
assert_equal '-f1', args.flags[0].name
|
475
|
+
assert_equal 'f1', args.flags[0].given_label
|
476
|
+
assert_equal '-f1', args.flags[0].given_name
|
477
|
+
assert_equal 1, args.flags[0].given_hyphens
|
478
|
+
assert_equal Hash.new, args.flags[0].extras
|
479
|
+
|
480
|
+
assert_equal 1, args.options.size
|
481
|
+
assert_equal '--option=value', args.options[0].to_s
|
482
|
+
assert_equal '--option', args.options[0].name
|
483
|
+
assert_equal 'o', args.options[0].given_label
|
484
|
+
assert_equal 'value', args.options[0].value
|
485
|
+
assert_equal '-o', args.options[0].given_name
|
486
|
+
assert_equal 1, args.options[0].given_hyphens
|
487
|
+
assert_equal Hash.new, args.options[0].extras
|
488
|
+
|
489
|
+
assert_equal 1, args.values.size
|
490
|
+
assert_equal 'value1', args.values[0]
|
491
|
+
end
|
492
|
+
|
493
|
+
def test_option_aliases_3
|
494
|
+
|
495
|
+
aliases = [
|
496
|
+
CLASP.Option('--option', aliases: [ '-o' ])
|
497
|
+
]
|
498
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-o', 'value' ], aliases
|
499
|
+
|
500
|
+
assert_equal 1, args.flags.size
|
501
|
+
assert_equal '-f1', args.flags[0].to_s
|
502
|
+
assert_equal '-f1', args.flags[0].name
|
503
|
+
assert_equal 'f1', args.flags[0].given_label
|
504
|
+
assert_equal '-f1', args.flags[0].given_name
|
505
|
+
assert_equal 1, args.flags[0].given_hyphens
|
506
|
+
assert_equal Hash.new, args.flags[0].extras
|
507
|
+
|
508
|
+
assert_equal 1, args.options.size
|
509
|
+
assert_equal '--option=value', args.options[0].to_s
|
510
|
+
assert_equal '--option', args.options[0].name
|
511
|
+
assert_equal 'o', args.options[0].given_label
|
512
|
+
assert_equal 'value', args.options[0].value
|
513
|
+
assert_equal '-o', args.options[0].given_name
|
514
|
+
assert_equal 1, args.options[0].given_hyphens
|
515
|
+
assert_equal Hash.new, args.options[0].extras
|
516
|
+
|
517
|
+
assert_equal 1, args.values.size
|
518
|
+
assert_equal 'value1', args.values[0]
|
519
|
+
end
|
520
|
+
|
521
|
+
def test_option_default_aliases_1
|
522
|
+
|
523
|
+
aliases = [
|
524
|
+
CLASP.Option('--option', aliases: [ '-o' ]),
|
525
|
+
CLASP.Option('--option=special-value', alias: '-s')
|
526
|
+
]
|
527
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-o', 'value', '-s', '-s=explicit-value' ], aliases
|
528
|
+
|
529
|
+
assert_equal 1, args.flags.size
|
530
|
+
assert_equal '-f1', args.flags[0].to_s
|
531
|
+
assert_equal '-f1', args.flags[0].name
|
532
|
+
assert_equal 'f1', args.flags[0].given_label
|
533
|
+
assert_equal '-f1', args.flags[0].given_name
|
534
|
+
assert_equal 1, args.flags[0].given_hyphens
|
535
|
+
assert_equal Hash.new, args.flags[0].extras
|
536
|
+
|
537
|
+
assert_equal 3, args.options.size
|
538
|
+
assert_equal '--option=value', args.options[0].to_s
|
539
|
+
assert_equal '--option', args.options[0].name
|
540
|
+
assert_equal 'o', args.options[0].given_label
|
541
|
+
assert_equal 'value', args.options[0].value
|
542
|
+
assert_equal '-o', args.options[0].given_name
|
543
|
+
assert_equal 1, args.options[0].given_hyphens
|
544
|
+
assert_equal Hash.new, args.options[0].extras
|
545
|
+
assert_equal '--option=special-value', args.options[1].to_s
|
546
|
+
assert_equal '--option', args.options[1].name
|
547
|
+
assert_equal 's', args.options[1].given_label
|
548
|
+
assert_equal 'special-value', args.options[1].value
|
549
|
+
assert_equal '-s', args.options[1].given_name
|
550
|
+
assert_equal 1, args.options[1].given_hyphens
|
551
|
+
assert_equal Hash.new, args.options[1].extras
|
552
|
+
assert_equal '--option=explicit-value', args.options[2].to_s
|
553
|
+
assert_equal '--option', args.options[2].name
|
554
|
+
assert_equal 's', args.options[2].given_label
|
555
|
+
assert_equal 'explicit-value', args.options[2].value
|
556
|
+
assert_equal '-s', args.options[2].given_name
|
557
|
+
assert_equal 1, args.options[2].given_hyphens
|
558
|
+
assert_equal Hash.new, args.options[2].extras
|
559
|
+
|
560
|
+
assert_equal 1, args.values.size
|
561
|
+
assert_equal 'value1', args.values[0]
|
562
|
+
end
|
563
|
+
|
564
|
+
def test_option_default_aliases_2
|
565
|
+
|
566
|
+
aliases = [
|
567
|
+
CLASP.Option('--option', aliases: [ '-o' ]),
|
568
|
+
CLASP.Flag('--option=special-value', alias: '-s'),
|
569
|
+
CLASP.Flag('--verbose', alias: '-v'),
|
570
|
+
]
|
571
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-o', 'value', '-sv', '-s=explicit-value' ], aliases
|
572
|
+
|
573
|
+
assert_equal 2, args.flags.size
|
574
|
+
flag = args.flags[0]
|
575
|
+
assert_equal '-f1', flag.to_s
|
576
|
+
assert_equal '-f1', flag.name
|
577
|
+
assert_equal 'f1', flag.given_label
|
578
|
+
assert_equal '-f1', flag.given_name
|
579
|
+
assert_equal 1, flag.given_hyphens
|
580
|
+
assert_equal Hash.new, flag.extras
|
581
|
+
assert_equal 0, flag.given_index
|
582
|
+
flag = args.flags[1]
|
583
|
+
assert_equal '--verbose', flag.to_s
|
584
|
+
assert_equal '--verbose', flag.name
|
585
|
+
assert_equal 'sv', flag.given_label
|
586
|
+
assert_equal '-sv', flag.given_name
|
587
|
+
assert_equal 1, flag.given_hyphens
|
588
|
+
assert_equal Hash.new, flag.extras
|
589
|
+
assert_equal 4, flag.given_index
|
590
|
+
|
591
|
+
assert_equal 3, args.options.size
|
592
|
+
option = args.options[0]
|
593
|
+
assert_equal '--option=value', option.to_s
|
594
|
+
assert_equal '--option', option.name
|
595
|
+
assert_equal 'o', option.given_label
|
596
|
+
assert_equal 'value', option.value
|
597
|
+
assert_equal '-o', option.given_name
|
598
|
+
assert_equal 1, option.given_hyphens
|
599
|
+
assert_equal Hash.new, option.extras
|
600
|
+
assert_equal 2, option.given_index
|
601
|
+
option = args.options[1]
|
602
|
+
assert_equal '--option=special-value', option.to_s
|
603
|
+
assert_equal '--option', option.name
|
604
|
+
assert_equal 'sv', option.given_label
|
605
|
+
assert_equal 'special-value', option.value
|
606
|
+
assert_equal '-sv', option.given_name
|
607
|
+
assert_equal 1, option.given_hyphens
|
608
|
+
assert_equal Hash.new, option.extras
|
609
|
+
assert_equal 4, option.given_index
|
610
|
+
option = args.options[2]
|
611
|
+
assert_equal '--option=explicit-value', option.to_s
|
612
|
+
assert_equal '--option', option.name
|
613
|
+
assert_equal 's', option.given_label
|
614
|
+
assert_equal 'explicit-value', option.value
|
615
|
+
assert_equal '-s', option.given_name
|
616
|
+
assert_equal 1, option.given_hyphens
|
617
|
+
assert_equal Hash.new, option.extras
|
618
|
+
assert_equal 5, option.given_index
|
619
|
+
|
620
|
+
assert_equal 1, args.values.size
|
621
|
+
assert_equal 'value1', args.values[0]
|
622
|
+
end
|
623
|
+
|
624
|
+
def test_option_default_aliases_3
|
625
|
+
|
626
|
+
aliases = [
|
627
|
+
CLASP.Option('--option', aliases: [ '-o' ]),
|
628
|
+
CLASP.Flag('--option=special-value', alias: '-s'),
|
629
|
+
CLASP.Flag('-v'),
|
630
|
+
]
|
631
|
+
args = CLASP::Arguments.new [ '-f1', 'value1', '-o', 'value', '-sv', '-s=explicit-value' ], aliases
|
632
|
+
|
633
|
+
assert_equal 2, args.flags.size
|
634
|
+
flag = args.flags[0]
|
635
|
+
assert_equal '-f1', flag.to_s
|
636
|
+
assert_equal '-f1', flag.name
|
637
|
+
assert_equal 'f1', flag.given_label
|
638
|
+
assert_equal '-f1', flag.given_name
|
639
|
+
assert_equal 1, flag.given_hyphens
|
640
|
+
assert_equal Hash.new, flag.extras
|
641
|
+
assert_equal 0, flag.given_index
|
642
|
+
flag = args.flags[1]
|
643
|
+
assert_equal '-v', flag.to_s
|
644
|
+
assert_equal '-v', flag.name
|
645
|
+
assert_equal 'sv', flag.given_label
|
646
|
+
assert_equal '-sv', flag.given_name
|
647
|
+
assert_equal 1, flag.given_hyphens
|
648
|
+
assert_equal Hash.new, flag.extras
|
649
|
+
assert_equal 4, flag.given_index
|
650
|
+
|
651
|
+
assert_equal 3, args.options.size
|
652
|
+
option = args.options[0]
|
653
|
+
assert_equal '--option=value', option.to_s
|
654
|
+
assert_equal '--option', option.name
|
655
|
+
assert_equal 'o', option.given_label
|
656
|
+
assert_equal 'value', option.value
|
657
|
+
assert_equal '-o', option.given_name
|
658
|
+
assert_equal 1, option.given_hyphens
|
659
|
+
assert_equal Hash.new, option.extras
|
660
|
+
assert_equal 2, option.given_index
|
661
|
+
option = args.options[1]
|
662
|
+
assert_equal '--option=special-value', option.to_s
|
663
|
+
assert_equal '--option', option.name
|
664
|
+
assert_equal 'sv', option.given_label
|
665
|
+
assert_equal 'special-value', option.value
|
666
|
+
assert_equal '-sv', option.given_name
|
667
|
+
assert_equal 1, option.given_hyphens
|
668
|
+
assert_equal Hash.new, option.extras
|
669
|
+
assert_equal 4, option.given_index
|
670
|
+
option = args.options[2]
|
671
|
+
assert_equal '--option=explicit-value', option.to_s
|
672
|
+
assert_equal '--option', option.name
|
673
|
+
assert_equal 's', option.given_label
|
674
|
+
assert_equal 'explicit-value', option.value
|
675
|
+
assert_equal '-s', option.given_name
|
676
|
+
assert_equal 1, option.given_hyphens
|
677
|
+
assert_equal Hash.new, option.extras
|
678
|
+
assert_equal 5, option.given_index
|
679
|
+
|
680
|
+
assert_equal 1, args.values.size
|
681
|
+
assert_equal 'value1', args.values[0]
|
682
|
+
end
|
683
|
+
end
|
684
|
+
|