kwalify 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +24 -19
- data/README.txt +51 -51
- data/bin/kwalify +2 -2
- data/contrib/inline-require +151 -0
- data/contrib/kwalify +2850 -0
- data/doc-api/classes/CommandOptionError.html +184 -0
- data/doc-api/classes/CommandOptionParser.html +325 -0
- data/doc-api/classes/Kwalify.html +270 -0
- data/doc-api/classes/Kwalify/AssertionError.html +148 -0
- data/doc-api/classes/Kwalify/BaseError.html +296 -0
- data/doc-api/classes/Kwalify/CommandOptionError.html +168 -0
- data/doc-api/classes/Kwalify/ErrorHelper.html +218 -0
- data/doc-api/classes/Kwalify/HashInterface.html +240 -0
- data/doc-api/classes/Kwalify/KwalifyError.html +111 -0
- data/doc-api/classes/Kwalify/Main.html +336 -0
- data/doc-api/classes/Kwalify/MetaValidator.html +432 -0
- data/doc-api/classes/Kwalify/Parser.html +155 -0
- data/doc-api/classes/Kwalify/PlainYamlParser.html +520 -0
- data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +165 -0
- data/doc-api/classes/Kwalify/Rule.html +411 -0
- data/doc-api/classes/Kwalify/SchemaError.html +148 -0
- data/doc-api/classes/Kwalify/Types.html +301 -0
- data/doc-api/classes/Kwalify/ValidationError.html +148 -0
- data/doc-api/classes/Kwalify/Validator.html +311 -0
- data/doc-api/classes/Kwalify/YamlParser.html +535 -0
- data/doc-api/classes/Kwalify/YamlSyntaxError.html +168 -0
- data/doc-api/classes/Test.html +107 -0
- data/doc-api/classes/Test/Unit.html +101 -0
- data/doc-api/classes/YamlHelper.html +259 -0
- data/doc-api/created.rid +1 -0
- data/doc-api/files/__/README_txt.html +179 -0
- data/doc-api/files/kwalify/errors_rb.html +114 -0
- data/doc-api/files/kwalify/main_rb.html +117 -0
- data/doc-api/files/kwalify/messages_rb.html +107 -0
- data/doc-api/files/kwalify/meta-validator_rb.html +117 -0
- data/doc-api/files/kwalify/rule_rb.html +116 -0
- data/doc-api/files/kwalify/types_rb.html +114 -0
- data/doc-api/files/kwalify/util/assert-text-equal_rb.html +115 -0
- data/doc-api/files/kwalify/util/hash-interface_rb.html +107 -0
- data/doc-api/files/kwalify/util/option-parser_rb.html +107 -0
- data/doc-api/files/kwalify/util/testcase-helper_rb.html +115 -0
- data/doc-api/files/kwalify/util/yaml-helper_rb.html +114 -0
- data/doc-api/files/kwalify/validator_rb.html +117 -0
- data/doc-api/files/kwalify/yaml-parser_rb.html +117 -0
- data/doc-api/files/kwalify_rb.html +120 -0
- data/doc-api/fr_class_index.html +50 -0
- data/doc-api/fr_file_index.html +41 -0
- data/doc-api/fr_method_index.html +109 -0
- data/doc-api/index.html +24 -0
- data/doc-api/rdoc-style.css +208 -0
- data/doc/users-guide.html +693 -193
- data/examples/address-book/Makefile +5 -0
- data/examples/address-book/address-book.schema.yaml +2 -1
- data/examples/invoice/Makefile +5 -0
- data/examples/invoice/invoice.schema.yaml +3 -2
- data/examples/tapkit/Makefile +5 -0
- data/examples/tapkit/main.rb +7 -0
- data/examples/tapkit/tapkit.schema.yaml +6 -1
- data/lib/kwalify.rb +3 -3
- data/lib/kwalify/errors.rb +2 -2
- data/lib/kwalify/main.rb +161 -84
- data/lib/kwalify/messages.rb +17 -11
- data/lib/kwalify/meta-validator.rb +11 -2
- data/lib/kwalify/rule.rb +13 -3
- data/lib/kwalify/templates/genclass-java.eruby +195 -0
- data/lib/kwalify/templates/genclass-ruby.eruby +84 -0
- data/lib/kwalify/types.rb +18 -18
- data/lib/kwalify/util/assert-text-equal.rb +44 -0
- data/lib/kwalify/util/hash-interface.rb +37 -0
- data/lib/kwalify/util/option-parser.rb +2 -2
- data/lib/kwalify/util/testcase-helper.rb +112 -0
- data/lib/kwalify/util/yaml-helper.rb +2 -2
- data/lib/kwalify/validator.rb +2 -2
- data/lib/kwalify/yaml-parser.rb +12 -9
- data/test/test-main.rb +77 -78
- data/test/test-main.yaml +543 -769
- data/test/test-metavalidator.rb +27 -47
- data/test/test-metavalidator.yaml +21 -2
- data/test/test-rule.rb +6 -39
- data/test/test-rule.yaml +2 -2
- data/test/test-validator.rb +36 -869
- data/test/test-validator.yaml +28 -20
- data/test/test-yamlparser.rb +30 -1248
- data/test/test-yamlparser.yaml +138 -110
- data/test/test.rb +33 -13
- data/test/tmp.dir/Context.java +40 -0
- data/test/tmp.dir/Group.java +33 -0
- data/test/tmp.dir/User.java +43 -0
- data/test/tmp.dir/action1.document +18 -0
- data/test/tmp.dir/action1.schema +32 -0
- data/test/tmp.dir/action2.document +18 -0
- data/test/tmp.dir/action2.schema +32 -0
- data/test/tmp.dir/emacs.document +6 -0
- data/test/tmp.dir/emacs.schema +6 -0
- data/test/tmp.dir/meta1.document +0 -0
- data/test/tmp.dir/meta1.schema +3 -0
- data/test/tmp.dir/meta2.document +0 -0
- data/test/tmp.dir/meta2.schema +3 -0
- data/test/tmp.dir/silent1.document +3 -0
- data/test/tmp.dir/silent1.schema +3 -0
- data/test/tmp.dir/silent2.document +7 -0
- data/test/tmp.dir/silent2.schema +3 -0
- data/test/tmp.dir/stream.invalid +8 -0
- data/test/tmp.dir/stream.schema +3 -0
- data/test/tmp.dir/stream.valid +8 -0
- data/test/tmp.dir/untabify.document +5 -0
- data/test/tmp.dir/untabify.schema +10 -0
- metadata +98 -12
- data/lib/kwalify/util/assert-diff.rb +0 -44
@@ -0,0 +1,184 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: CommandOptionError</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">CommandOptionError</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/kwalify/util/option-parser_rb.html">
|
59
|
+
kwalify/util/option-parser.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
StandardError
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
<div id="description">
|
82
|
+
<p>
|
83
|
+
$Rev: 51 $ $Release: 0.6.0 $ copyright(c) 2005 kuwata-lab all rights reserved.
|
84
|
+
</p>
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
<div id="method-list">
|
92
|
+
<h3 class="section-bar">Methods</h3>
|
93
|
+
|
94
|
+
<div class="name-list">
|
95
|
+
<a href="#M000001">new</a>
|
96
|
+
</div>
|
97
|
+
</div>
|
98
|
+
|
99
|
+
</div>
|
100
|
+
|
101
|
+
|
102
|
+
<!-- if includes -->
|
103
|
+
|
104
|
+
<div id="section">
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
<div id="attribute-list">
|
111
|
+
<h3 class="section-bar">Attributes</h3>
|
112
|
+
|
113
|
+
<div class="name-list">
|
114
|
+
<table>
|
115
|
+
<tr class="top-aligned-row context-row">
|
116
|
+
<td class="context-item-name">error_symbol</td>
|
117
|
+
<td class="context-item-value"> [R] </td>
|
118
|
+
<td class="context-item-desc"></td>
|
119
|
+
</tr>
|
120
|
+
<tr class="top-aligned-row context-row">
|
121
|
+
<td class="context-item-name">option</td>
|
122
|
+
<td class="context-item-value"> [R] </td>
|
123
|
+
<td class="context-item-desc"></td>
|
124
|
+
</tr>
|
125
|
+
</table>
|
126
|
+
</div>
|
127
|
+
</div>
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
<!-- if method_list -->
|
132
|
+
<div id="methods">
|
133
|
+
<h3 class="section-bar">Public Class methods</h3>
|
134
|
+
|
135
|
+
<div id="method-M000001" class="method-detail">
|
136
|
+
<a name="M000001"></a>
|
137
|
+
|
138
|
+
<div class="method-heading">
|
139
|
+
<a href="#M000001" class="method-signature">
|
140
|
+
<span class="method-name">new</span><span class="method-args">(option, error_symbol, message=nil)</span>
|
141
|
+
</a>
|
142
|
+
</div>
|
143
|
+
|
144
|
+
<div class="method-description">
|
145
|
+
<p><a class="source-toggle" href="#"
|
146
|
+
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
147
|
+
<div class="method-source-code" id="M000001-source">
|
148
|
+
<pre>
|
149
|
+
<span class="ruby-comment cmt"># File kwalify/util/option-parser.rb, line 8</span>
|
150
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">option</span>, <span class="ruby-identifier">error_symbol</span>, <span class="ruby-identifier">message</span>=<span class="ruby-keyword kw">nil</span>)
|
151
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">message</span>
|
152
|
+
<span class="ruby-keyword kw">case</span> <span class="ruby-identifier">error_symbol</span>
|
153
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:no_argument</span>
|
154
|
+
<span class="ruby-identifier">message</span> = <span class="ruby-value str">"-%s: argument required."</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">option</span>
|
155
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:unknown_option</span>
|
156
|
+
<span class="ruby-identifier">message</span> = <span class="ruby-value str">"-%s: unknown option."</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">option</span>
|
157
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:invalid_property</span>
|
158
|
+
<span class="ruby-identifier">message</span> = <span class="ruby-value str">"-%s: invalid property."</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">option</span>
|
159
|
+
<span class="ruby-keyword kw">else</span>
|
160
|
+
<span class="ruby-identifier">message</span> = <span class="ruby-node">"*** internal error(optchar=#{option}, error_symbol=#{error_symbol}) ***"</span>
|
161
|
+
<span class="ruby-keyword kw">end</span>
|
162
|
+
<span class="ruby-keyword kw">end</span>
|
163
|
+
<span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">message</span>)
|
164
|
+
<span class="ruby-ivar">@option</span> = <span class="ruby-identifier">option</span>
|
165
|
+
<span class="ruby-ivar">@error_symbol</span> = <span class="ruby-identifier">error_symbol</span>
|
166
|
+
<span class="ruby-keyword kw">end</span>
|
167
|
+
</pre>
|
168
|
+
</div>
|
169
|
+
</div>
|
170
|
+
</div>
|
171
|
+
|
172
|
+
|
173
|
+
</div>
|
174
|
+
|
175
|
+
|
176
|
+
</div>
|
177
|
+
|
178
|
+
|
179
|
+
<div id="validator-badges">
|
180
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
181
|
+
</div>
|
182
|
+
|
183
|
+
</body>
|
184
|
+
</html>
|
@@ -0,0 +1,325 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: CommandOptionParser</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">CommandOptionParser</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/kwalify/util/option-parser_rb.html">
|
59
|
+
kwalify/util/option-parser.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
Object
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
<div id="description">
|
82
|
+
<p>
|
83
|
+
ex.
|
84
|
+
</p>
|
85
|
+
<pre>
|
86
|
+
## create parser
|
87
|
+
arg_none = "hv" # ex. -h -v
|
88
|
+
arg_required = "xf" # ex. -x suffix -f filename
|
89
|
+
arg_optional = "i" # ex. -i (or -i10)
|
90
|
+
parser = CommandOptionParser.new(arg_none, arg_required, arg_optional)
|
91
|
+
|
92
|
+
## parse options
|
93
|
+
argv = %w[-h -v -f filename -i 10 aaa bbb]
|
94
|
+
options, properties = parser.parse(argv)
|
95
|
+
p options #=> { ?h=>true, ?v=>true, ?f=>"filename", ?i=>true }
|
96
|
+
p argv #=> ["10", "aaa", "bbb"]
|
97
|
+
|
98
|
+
## parse options #2
|
99
|
+
argv = %w[-hvx.txt -ffilename -i10 aaa bbb]
|
100
|
+
options, properties = parser.parse(argv)
|
101
|
+
p options #=> { ?h=>true, ?v=>true, ?x=>".txt", ?f=>"filename", ?i=>10 }
|
102
|
+
p argv #=> ["aaa", "bbb"]
|
103
|
+
|
104
|
+
## parse properties
|
105
|
+
argv = %w[-hi --index=10 --user-name=foo --help]
|
106
|
+
options, properties = parser.parse(argv)
|
107
|
+
p options #=> {?h=>true, ?i=>true}
|
108
|
+
p properties #=> {"index"=>"10", "user-name"=>"foo", "help"=>nil}
|
109
|
+
|
110
|
+
## parse properties with auto-convert
|
111
|
+
argv = %w[-hi --index=10 --user-name=foo --help]
|
112
|
+
options, properties = parser.parse(argv, true)
|
113
|
+
p options #=> {?h=>true, ?i=>true}
|
114
|
+
p properties #=> {:index=>10, :user_name=>foo, :help=>true}
|
115
|
+
|
116
|
+
## -a: unknown option.
|
117
|
+
argv = %w[-abc]
|
118
|
+
begin
|
119
|
+
options, properties = parser.parse(argv)
|
120
|
+
rescue CommandOptionError => ex
|
121
|
+
$stderr.puts ex.message # -a: unknown option.
|
122
|
+
end
|
123
|
+
|
124
|
+
## -f: argument required.
|
125
|
+
argv = %w[-f]
|
126
|
+
begin
|
127
|
+
options, properties = parser.parse(argv)
|
128
|
+
rescue CommandOptionError => ex
|
129
|
+
$stderr.puts ex.message # -f: argument required.
|
130
|
+
end
|
131
|
+
|
132
|
+
## --@prop=10: invalid property.
|
133
|
+
argv = %w[--@prop=10]
|
134
|
+
begin
|
135
|
+
options, properties = parser.parse(argv)
|
136
|
+
rescue CommandOptionError => ex
|
137
|
+
$stderr.puts ex.message # --@prop=10: invalid property.
|
138
|
+
end
|
139
|
+
</pre>
|
140
|
+
|
141
|
+
</div>
|
142
|
+
|
143
|
+
|
144
|
+
</div>
|
145
|
+
|
146
|
+
<div id="method-list">
|
147
|
+
<h3 class="section-bar">Methods</h3>
|
148
|
+
|
149
|
+
<div class="name-list">
|
150
|
+
<a href="#M000002">new</a>
|
151
|
+
<a href="#M000004">parse</a>
|
152
|
+
<a href="#M000003">to_value</a>
|
153
|
+
</div>
|
154
|
+
</div>
|
155
|
+
|
156
|
+
</div>
|
157
|
+
|
158
|
+
|
159
|
+
<!-- if includes -->
|
160
|
+
|
161
|
+
<div id="section">
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
<!-- if method_list -->
|
171
|
+
<div id="methods">
|
172
|
+
<h3 class="section-bar">Public Class methods</h3>
|
173
|
+
|
174
|
+
<div id="method-M000002" class="method-detail">
|
175
|
+
<a name="M000002"></a>
|
176
|
+
|
177
|
+
<div class="method-heading">
|
178
|
+
<a href="#M000002" class="method-signature">
|
179
|
+
<span class="method-name">new</span><span class="method-args">(arg_none=nil, arg_required=nil, arg_optional=nil)</span>
|
180
|
+
</a>
|
181
|
+
</div>
|
182
|
+
|
183
|
+
<div class="method-description">
|
184
|
+
<p>
|
185
|
+
arg_none: option string which takes no argument arg_required: option string
|
186
|
+
which takes argument arg_otpional: option string which may takes argument
|
187
|
+
optionally
|
188
|
+
</p>
|
189
|
+
<p><a class="source-toggle" href="#"
|
190
|
+
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
191
|
+
<div class="method-source-code" id="M000002-source">
|
192
|
+
<pre>
|
193
|
+
<span class="ruby-comment cmt"># File kwalify/util/option-parser.rb, line 92</span>
|
194
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">arg_none</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">arg_required</span>=<span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">arg_optional</span>=<span class="ruby-keyword kw">nil</span>)
|
195
|
+
<span class="ruby-ivar">@arg_none</span> = <span class="ruby-identifier">arg_none</span> <span class="ruby-operator">||</span> <span class="ruby-value str">""</span>
|
196
|
+
<span class="ruby-ivar">@arg_required</span> = <span class="ruby-identifier">arg_required</span> <span class="ruby-operator">||</span> <span class="ruby-value str">""</span>
|
197
|
+
<span class="ruby-ivar">@arg_optional</span> = <span class="ruby-identifier">arg_optional</span> <span class="ruby-operator">||</span> <span class="ruby-value str">""</span>
|
198
|
+
<span class="ruby-keyword kw">end</span>
|
199
|
+
</pre>
|
200
|
+
</div>
|
201
|
+
</div>
|
202
|
+
</div>
|
203
|
+
|
204
|
+
<div id="method-M000003" class="method-detail">
|
205
|
+
<a name="M000003"></a>
|
206
|
+
|
207
|
+
<div class="method-heading">
|
208
|
+
<a href="#M000003" class="method-signature">
|
209
|
+
<span class="method-name">to_value</span><span class="method-args">(str)</span>
|
210
|
+
</a>
|
211
|
+
</div>
|
212
|
+
|
213
|
+
<div class="method-description">
|
214
|
+
<p><a class="source-toggle" href="#"
|
215
|
+
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
216
|
+
<div class="method-source-code" id="M000003-source">
|
217
|
+
<pre>
|
218
|
+
<span class="ruby-comment cmt"># File kwalify/util/option-parser.rb, line 99</span>
|
219
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_value</span>(<span class="ruby-identifier">str</span>)
|
220
|
+
<span class="ruby-keyword kw">case</span> <span class="ruby-identifier">str</span>
|
221
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-keyword kw">nil</span>, <span class="ruby-value str">"null"</span>, <span class="ruby-value str">"nil"</span> ; <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
|
222
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"true"</span>, <span class="ruby-value str">"yes"</span> ; <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
|
223
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"false"</span>, <span class="ruby-value str">"no"</span> ; <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
|
224
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/\A\d+\z/</span> ; <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">str</span>.<span class="ruby-identifier">to_i</span>
|
225
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/\A\d+\.\d+\z/</span> ; <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">str</span>.<span class="ruby-identifier">to_f</span>
|
226
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/\/(.*)\//</span> ; <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">$1</span>)
|
227
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-regexp re">/\A'.*'\z/</span>, <span class="ruby-regexp re">/\A".*"\z/</span> ; <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">eval</span>(<span class="ruby-identifier">str</span>)
|
228
|
+
<span class="ruby-keyword kw">else</span> ; <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">str</span>
|
229
|
+
<span class="ruby-keyword kw">end</span>
|
230
|
+
<span class="ruby-keyword kw">end</span>
|
231
|
+
</pre>
|
232
|
+
</div>
|
233
|
+
</div>
|
234
|
+
</div>
|
235
|
+
|
236
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
237
|
+
|
238
|
+
<div id="method-M000004" class="method-detail">
|
239
|
+
<a name="M000004"></a>
|
240
|
+
|
241
|
+
<div class="method-heading">
|
242
|
+
<a href="#M000004" class="method-signature">
|
243
|
+
<span class="method-name">parse</span><span class="method-args">(argv, auto_convert=false)</span>
|
244
|
+
</a>
|
245
|
+
</div>
|
246
|
+
|
247
|
+
<div class="method-description">
|
248
|
+
<table>
|
249
|
+
<tr><td valign="top">argv:</td><td>array of string
|
250
|
+
|
251
|
+
</td></tr>
|
252
|
+
<tr><td valign="top">auto_convert:</td><td>if true, convert properties value to int, boolean, string, regexp, …
|
253
|
+
(default false)
|
254
|
+
|
255
|
+
</td></tr>
|
256
|
+
</table>
|
257
|
+
<p><a class="source-toggle" href="#"
|
258
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
259
|
+
<div class="method-source-code" id="M000004-source">
|
260
|
+
<pre>
|
261
|
+
<span class="ruby-comment cmt"># File kwalify/util/option-parser.rb, line 115</span>
|
262
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse</span>(<span class="ruby-identifier">argv</span>, <span class="ruby-identifier">auto_convert</span>=<span class="ruby-keyword kw">false</span>)
|
263
|
+
<span class="ruby-identifier">options</span> = {}
|
264
|
+
<span class="ruby-identifier">properties</span> = {}
|
265
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-identifier">argv</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">&&</span> <span class="ruby-identifier">argv</span>[<span class="ruby-value">0</span>][<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?-</span>
|
266
|
+
<span class="ruby-identifier">optstr</span> = <span class="ruby-identifier">argv</span>.<span class="ruby-identifier">shift</span>
|
267
|
+
<span class="ruby-identifier">optstr</span> = <span class="ruby-identifier">optstr</span>[<span class="ruby-value">1</span>, <span class="ruby-identifier">optstr</span>.<span class="ruby-identifier">length</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>]
|
268
|
+
<span class="ruby-comment cmt">#</span>
|
269
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">optstr</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">==</span> <span class="ruby-value">?-</span> <span class="ruby-comment cmt">## property</span>
|
270
|
+
<span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">optstr</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\A\-([-\w]+)(?:=(.*))?/</span>
|
271
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">CommandOptionError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">optstr</span>, <span class="ruby-identifier">:invalid_property</span>)
|
272
|
+
<span class="ruby-keyword kw">end</span>
|
273
|
+
<span class="ruby-identifier">prop_name</span> = <span class="ruby-identifier">$1</span>; <span class="ruby-identifier">prop_value</span> = <span class="ruby-identifier">$2</span>
|
274
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">auto_convert</span>
|
275
|
+
<span class="ruby-identifier">key</span> = <span class="ruby-identifier">prop_name</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp re">/-/</span>, <span class="ruby-value str">'_'</span>).<span class="ruby-identifier">intern</span>
|
276
|
+
<span class="ruby-identifier">value</span> = <span class="ruby-identifier">prop_value</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">nil</span> <span class="ruby-operator">?</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-constant">CommandOptionParser</span>.<span class="ruby-identifier">to_value</span>(<span class="ruby-identifier">prop_value</span>)
|
277
|
+
<span class="ruby-identifier">properties</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
|
278
|
+
<span class="ruby-keyword kw">else</span>
|
279
|
+
<span class="ruby-identifier">properties</span>[<span class="ruby-identifier">prop_name</span>] = <span class="ruby-identifier">prop_value</span>
|
280
|
+
<span class="ruby-keyword kw">end</span>
|
281
|
+
<span class="ruby-comment cmt">#</span>
|
282
|
+
<span class="ruby-keyword kw">else</span> <span class="ruby-comment cmt">## options</span>
|
283
|
+
<span class="ruby-keyword kw">while</span> <span class="ruby-identifier">optstr</span> <span class="ruby-operator">&&</span> <span class="ruby-operator">!</span><span class="ruby-identifier">optstr</span>.<span class="ruby-identifier">empty?</span>
|
284
|
+
<span class="ruby-identifier">optchar</span> = <span class="ruby-identifier">optstr</span>[<span class="ruby-value">0</span>]
|
285
|
+
<span class="ruby-identifier">optstr</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>] = <span class="ruby-value str">""</span>
|
286
|
+
<span class="ruby-comment cmt">#puts "*** debug: optchar=#{optchar.chr}, optstr=#{optstr.inspect}"</span>
|
287
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@arg_none</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">optchar</span>)
|
288
|
+
<span class="ruby-identifier">options</span>[<span class="ruby-identifier">optchar</span>] = <span class="ruby-keyword kw">true</span>
|
289
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@arg_required</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">optchar</span>)
|
290
|
+
<span class="ruby-identifier">arg</span> = <span class="ruby-identifier">optstr</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span><span class="ruby-identifier">argv</span>.<span class="ruby-identifier">shift</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">optstr</span>
|
291
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">CommandOptionError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">optchar</span>.<span class="ruby-identifier">chr</span>, <span class="ruby-identifier">:no_argument</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">arg</span>
|
292
|
+
<span class="ruby-identifier">options</span>[<span class="ruby-identifier">optchar</span>] = <span class="ruby-identifier">arg</span>
|
293
|
+
<span class="ruby-identifier">optstr</span> = <span class="ruby-keyword kw">nil</span>
|
294
|
+
<span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@arg_optional</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">optchar</span>)
|
295
|
+
<span class="ruby-identifier">arg</span> = <span class="ruby-identifier">optstr</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">true</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">optstr</span>
|
296
|
+
<span class="ruby-identifier">options</span>[<span class="ruby-identifier">optchar</span>] = <span class="ruby-identifier">arg</span>
|
297
|
+
<span class="ruby-identifier">optstr</span> = <span class="ruby-keyword kw">nil</span>
|
298
|
+
<span class="ruby-keyword kw">else</span>
|
299
|
+
<span class="ruby-identifier">raise</span> <span class="ruby-constant">CommandOptionError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">optchar</span>.<span class="ruby-identifier">chr</span>, <span class="ruby-identifier">:unknown_option</span>)
|
300
|
+
<span class="ruby-keyword kw">end</span>
|
301
|
+
<span class="ruby-keyword kw">end</span>
|
302
|
+
<span class="ruby-keyword kw">end</span>
|
303
|
+
<span class="ruby-comment cmt">#</span>
|
304
|
+
<span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># end of while</span>
|
305
|
+
|
306
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">options</span>, <span class="ruby-identifier">properties</span>
|
307
|
+
<span class="ruby-keyword kw">end</span>
|
308
|
+
</pre>
|
309
|
+
</div>
|
310
|
+
</div>
|
311
|
+
</div>
|
312
|
+
|
313
|
+
|
314
|
+
</div>
|
315
|
+
|
316
|
+
|
317
|
+
</div>
|
318
|
+
|
319
|
+
|
320
|
+
<div id="validator-badges">
|
321
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
322
|
+
</div>
|
323
|
+
|
324
|
+
</body>
|
325
|
+
</html>
|