optiflag 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/ReleaseNotes.txt +110 -0
- data/doc/example/example_1.rb +30 -0
- data/doc/example/example_1_1.rb +27 -0
- data/doc/example/example_1_2.rb +28 -0
- data/doc/example/example_2.rb +28 -0
- data/doc/example/example_2_1.rb +23 -0
- data/doc/example/example_2_2.rb +31 -0
- data/doc/example/example_2_3.rb +37 -0
- data/doc/example/example_2_4.rb +37 -0
- data/doc/example/example_2_5.rb +28 -0
- data/doc/example/example_2_6.rb +22 -0
- data/doc/example/example_3.rb +33 -0
- data/doc/example/example_4.rb +12 -0
- data/doc/example/example_5.rb +26 -0
- data/doc/example/example_6.rb +17 -0
- data/doc/example/example_7.rb +39 -0
- data/lib/optiflag.rb +860 -0
- data/optiflag.gemspec +13 -0
- data/test/tc_advanced_usage_helping.rb +42 -0
- data/test/tc_basic_alternate_forms.rb +30 -0
- data/test/tc_basic_char_flags.rb +103 -0
- data/test/tc_basic_optional_flag.rb +74 -0
- data/test/tc_basic_parsing.rb +51 -0
- data/test/tc_basic_usage_helping.rb +40 -0
- data/test/tc_basic_value_validation.rb +40 -0
- data/test/tc_bug_one.rb +25 -0
- data/test/tc_bug_two.rb +33 -0
- data/test/tc_change_symbols.rb +61 -0
- data/test/tc_enumerated_value_validation.rb +35 -0
- data/test/tc_flagall.rb +17 -0
- data/test/tc_flagless_arg.rb +37 -0
- data/test/tc_keyword.rb +37 -0
- data/test/tc_values_as_hash.rb +46 -0
- metadata +95 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'optiflag.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
module SymbolArgs extend OptiFlag::Flagset(:flag_symbol => "/")
|
5
|
+
flag "directory"
|
6
|
+
flag "script", :description => "The Script directory"
|
7
|
+
flag "mode" do
|
8
|
+
value_matches /[0-9]/
|
9
|
+
end
|
10
|
+
flag ["date"] do
|
11
|
+
value_matches ["Must be of form mm\/dd\/yy",
|
12
|
+
/^[0-9]{2}\/[0-9]{2}\/[0-9]{2,4}$/]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
module AnotherSymbolArgs extend OptiFlag::Flagset
|
16
|
+
flag "directory"
|
17
|
+
flag "script", :description => "The Script directory"
|
18
|
+
flag "mode" do
|
19
|
+
value_matches /[0-9]/
|
20
|
+
end
|
21
|
+
flag ["date"] do
|
22
|
+
value_matches ["Must be of form mm\/dd\/yy",
|
23
|
+
/^[0-9]{2}\/[0-9]{2}\/[0-9]{2,4}$/]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class TC_SymbolArgs < Test::Unit::TestCase
|
28
|
+
|
29
|
+
|
30
|
+
def test_validation
|
31
|
+
command_line = %w{/directory c:/eu /script RunMe /mode 3 /date 12/23/2006}
|
32
|
+
args = SymbolArgs::parse(command_line)
|
33
|
+
assert(! args.errors?,
|
34
|
+
"No errors should have occurred")
|
35
|
+
assert_equal("c:/eu",args.flag_value.directory,
|
36
|
+
"Directory not properly set")
|
37
|
+
|
38
|
+
args2 = AnotherSymbolArgs::parse(command_line)
|
39
|
+
assert(args2.errors?,
|
40
|
+
"An error should have occurred")
|
41
|
+
assert_equal(4,args2.errors.missing_flags.length,
|
42
|
+
"There should be 4 problems")
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_validation_with_errors
|
46
|
+
command_line = %w{-directory c:/eu -script RunMe -mode 3 -date 12/23/2006}
|
47
|
+
args = SymbolArgs::parse(command_line)
|
48
|
+
assert(args.errors?,
|
49
|
+
"An error should have occurred")
|
50
|
+
assert_equal(4,args.errors.missing_flags.length,
|
51
|
+
"There should be 4 problems")
|
52
|
+
args2 = AnotherSymbolArgs::parse(command_line)
|
53
|
+
assert_equal("c:/eu",args2.flag_value.directory,
|
54
|
+
"Directory not properly set")
|
55
|
+
assert(! args2.errors?,
|
56
|
+
"No errors should have occurred")
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'optiflag.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
module EnumeratedValidArgs extend OptiFlag::Flagset
|
5
|
+
flag "directory"
|
6
|
+
flag "script", :description => "The Script directory"
|
7
|
+
flag "mode" do
|
8
|
+
value_in_set [1,2,"three"]
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_EnumeratedValidArgs < Test::Unit::TestCase
|
14
|
+
|
15
|
+
|
16
|
+
def test_validation
|
17
|
+
command_line = %w{-directory c:/eu -script RunMe -mode 1 }
|
18
|
+
args = EnumeratedValidArgs::parse(command_line)
|
19
|
+
assert_equal("c:/eu",args.flag_value.directory,
|
20
|
+
"Directory not properly set")
|
21
|
+
assert(! args.errors?,
|
22
|
+
"No errors should have occurred")
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_validation_with_errors
|
26
|
+
command_line = %w{-directory c:/eu -script RunMe -mode wrx }
|
27
|
+
args = EnumeratedValidArgs::parse(command_line)
|
28
|
+
assert(args.errors?,
|
29
|
+
"An error should have occurred")
|
30
|
+
assert_equal(1,args.errors.validation_errors.length,
|
31
|
+
"There should be 1 problem")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
data/test/tc_flagall.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
|
3
|
+
require 'tc_basic_parsing.rb'
|
4
|
+
require 'tc_basic_value_validation.rb'
|
5
|
+
require 'tc_enumerated_value_validation.rb'
|
6
|
+
require 'tc_basic_alternate_forms.rb'
|
7
|
+
require 'tc_basic_usage_helping.rb'
|
8
|
+
require 'tc_advanced_usage_helping.rb'
|
9
|
+
require 'tc_change_symbols.rb'
|
10
|
+
require 'tc_basic_optional_flag.rb'
|
11
|
+
|
12
|
+
require 'tc_bug_one.rb'
|
13
|
+
require 'tc_bug_two.rb'
|
14
|
+
require 'tc_basic_char_flags.rb'
|
15
|
+
require 'tc_keyword.rb'
|
16
|
+
require 'tc_values_as_hash.rb'
|
17
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'optiflag.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
module KeywordArg extend OptiFlag::Flagset
|
5
|
+
flag "dir"
|
6
|
+
keyword "checkin" do
|
7
|
+
alternate_forms "ci"
|
8
|
+
end
|
9
|
+
|
10
|
+
keyword "co"
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_KeywordArg < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def test_a
|
16
|
+
cl = %w{ -dir c:/my_stuff }
|
17
|
+
result = KeywordArg::parse(cl)
|
18
|
+
assert(result.flag_value.dir?)
|
19
|
+
assert(!result.flag_value.checkin?)
|
20
|
+
assert(!result.flag_value.ci?)
|
21
|
+
end
|
22
|
+
def test_b
|
23
|
+
cl = %w{ checkin -dir c:/my_stuff co }
|
24
|
+
result = KeywordArg::parse(cl)
|
25
|
+
assert(result.flag_value.dir?)
|
26
|
+
assert(result.flag_value.checkin?)
|
27
|
+
assert(result.flag_value.co?)
|
28
|
+
end
|
29
|
+
def test_b
|
30
|
+
cl = %w{ checkin -dir c:/my_stuff co }
|
31
|
+
result = KeywordArg::parse(cl)
|
32
|
+
assert(result.flag_value.dir?)
|
33
|
+
assert(result.flag_value.ci?)
|
34
|
+
assert(result.flag_value.co?)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
data/test/tc_keyword.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'optiflag.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
module KeywordArg extend OptiFlag::Flagset
|
5
|
+
flag "dir"
|
6
|
+
keyword "checkin" do
|
7
|
+
alternate_forms "ci"
|
8
|
+
end
|
9
|
+
|
10
|
+
keyword "co"
|
11
|
+
end
|
12
|
+
|
13
|
+
class TC_KeywordArg < Test::Unit::TestCase
|
14
|
+
|
15
|
+
def test_a
|
16
|
+
cl = %w{ -dir c:/my_stuff }
|
17
|
+
result = KeywordArg::parse(cl)
|
18
|
+
assert(result.flag_value.dir?)
|
19
|
+
assert(!result.flag_value.checkin?)
|
20
|
+
assert(!result.flag_value.ci?)
|
21
|
+
end
|
22
|
+
def test_b
|
23
|
+
cl = %w{ checkin -dir c:/my_stuff co }
|
24
|
+
result = KeywordArg::parse(cl)
|
25
|
+
assert(result.flag_value.dir?)
|
26
|
+
assert(result.flag_value.checkin?)
|
27
|
+
assert(result.flag_value.co?)
|
28
|
+
end
|
29
|
+
def test_b
|
30
|
+
cl = %w{ checkin -dir c:/my_stuff co }
|
31
|
+
result = KeywordArg::parse(cl)
|
32
|
+
assert(result.flag_value.dir?)
|
33
|
+
assert(result.flag_value.ci?)
|
34
|
+
assert(result.flag_value.co?)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'optiflag.rb'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
module ValuesAsHashArg extend OptiFlag::Flagset
|
5
|
+
flag "&"
|
6
|
+
flag "dir"
|
7
|
+
flag "star" do
|
8
|
+
alternate_forms "*","aster"
|
9
|
+
end
|
10
|
+
keyword "co"
|
11
|
+
usage_flag "h","help","?"
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
class TC_ValuesAsHashArg < Test::Unit::TestCase
|
16
|
+
|
17
|
+
def test_a
|
18
|
+
cl = %w{ -dir sdsd co }
|
19
|
+
result = ValuesAsHashArg::parse(cl)
|
20
|
+
assert(result.flag_value.dir?)
|
21
|
+
assert(result.flag_value.dir)
|
22
|
+
assert(result.flag_value[:dir])
|
23
|
+
assert(result.flag_value[:star] == nil)
|
24
|
+
end
|
25
|
+
def test_b
|
26
|
+
cl = %w{-star STAR -dir sdsd co }
|
27
|
+
result = ValuesAsHashArg::parse(cl)
|
28
|
+
assert(result.flag_value.dir?)
|
29
|
+
assert(result.flag_value.dir == "sdsd")
|
30
|
+
assert(result.flag_value[:dir] == "sdsd")
|
31
|
+
assert(result.flag_value[:star] == "STAR")
|
32
|
+
assert(result.flag_value[:aster] == "STAR")
|
33
|
+
assert(result.flag_value[:*] == "STAR")
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_c
|
37
|
+
cl = %w{ -dir sdsd co -& amper }
|
38
|
+
result = ValuesAsHashArg::parse(cl)
|
39
|
+
assert(result.flag_value.dir?)
|
40
|
+
assert(! result.flag_value.star?)
|
41
|
+
assert(result.flag_value.dir)
|
42
|
+
assert(result.flag_value[:dir])
|
43
|
+
assert(result.flag_value[:&] == "amper")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.0
|
3
|
+
specification_version: 1
|
4
|
+
name: optiflag
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.6"
|
7
|
+
date: 2006-08-27 00:00:00 -04:00
|
8
|
+
summary: Optiflag is yet-another library for handling command-line options in an arbitrary Ruby program.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: doeklund@gmail.com
|
12
|
+
homepage: http://rubyforge.org/projects/optiflag/
|
13
|
+
rubyforge_project: optiflag
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Daniel Eklund
|
31
|
+
files:
|
32
|
+
- doc
|
33
|
+
- lib
|
34
|
+
- optiflag.gemspec
|
35
|
+
- ReleaseNotes.txt
|
36
|
+
- test
|
37
|
+
- doc/example
|
38
|
+
- doc/example/example_1.rb
|
39
|
+
- doc/example/example_1_1.rb
|
40
|
+
- doc/example/example_1_2.rb
|
41
|
+
- doc/example/example_2.rb
|
42
|
+
- doc/example/example_2_1.rb
|
43
|
+
- doc/example/example_2_2.rb
|
44
|
+
- doc/example/example_2_3.rb
|
45
|
+
- doc/example/example_2_4.rb
|
46
|
+
- doc/example/example_2_5.rb
|
47
|
+
- doc/example/example_2_6.rb
|
48
|
+
- doc/example/example_3.rb
|
49
|
+
- doc/example/example_4.rb
|
50
|
+
- doc/example/example_5.rb
|
51
|
+
- doc/example/example_6.rb
|
52
|
+
- doc/example/example_7.rb
|
53
|
+
- lib/optiflag.rb
|
54
|
+
- test/tc_advanced_usage_helping.rb
|
55
|
+
- test/tc_basic_alternate_forms.rb
|
56
|
+
- test/tc_basic_char_flags.rb
|
57
|
+
- test/tc_basic_optional_flag.rb
|
58
|
+
- test/tc_basic_parsing.rb
|
59
|
+
- test/tc_basic_usage_helping.rb
|
60
|
+
- test/tc_basic_value_validation.rb
|
61
|
+
- test/tc_bug_one.rb
|
62
|
+
- test/tc_bug_two.rb
|
63
|
+
- test/tc_change_symbols.rb
|
64
|
+
- test/tc_enumerated_value_validation.rb
|
65
|
+
- test/tc_flagall.rb
|
66
|
+
- test/tc_flagless_arg.rb
|
67
|
+
- test/tc_keyword.rb
|
68
|
+
- test/tc_values_as_hash.rb
|
69
|
+
test_files:
|
70
|
+
- test/tc_advanced_usage_helping.rb
|
71
|
+
- test/tc_basic_alternate_forms.rb
|
72
|
+
- test/tc_basic_char_flags.rb
|
73
|
+
- test/tc_basic_optional_flag.rb
|
74
|
+
- test/tc_basic_parsing.rb
|
75
|
+
- test/tc_basic_usage_helping.rb
|
76
|
+
- test/tc_basic_value_validation.rb
|
77
|
+
- test/tc_bug_one.rb
|
78
|
+
- test/tc_bug_two.rb
|
79
|
+
- test/tc_change_symbols.rb
|
80
|
+
- test/tc_enumerated_value_validation.rb
|
81
|
+
- test/tc_flagless_arg.rb
|
82
|
+
- test/tc_keyword.rb
|
83
|
+
- test/tc_values_as_hash.rb
|
84
|
+
rdoc_options: []
|
85
|
+
|
86
|
+
extra_rdoc_files: []
|
87
|
+
|
88
|
+
executables: []
|
89
|
+
|
90
|
+
extensions: []
|
91
|
+
|
92
|
+
requirements: []
|
93
|
+
|
94
|
+
dependencies: []
|
95
|
+
|