kwalify 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (109) hide show
  1. data/ChangeLog +24 -19
  2. data/README.txt +51 -51
  3. data/bin/kwalify +2 -2
  4. data/contrib/inline-require +151 -0
  5. data/contrib/kwalify +2850 -0
  6. data/doc-api/classes/CommandOptionError.html +184 -0
  7. data/doc-api/classes/CommandOptionParser.html +325 -0
  8. data/doc-api/classes/Kwalify.html +270 -0
  9. data/doc-api/classes/Kwalify/AssertionError.html +148 -0
  10. data/doc-api/classes/Kwalify/BaseError.html +296 -0
  11. data/doc-api/classes/Kwalify/CommandOptionError.html +168 -0
  12. data/doc-api/classes/Kwalify/ErrorHelper.html +218 -0
  13. data/doc-api/classes/Kwalify/HashInterface.html +240 -0
  14. data/doc-api/classes/Kwalify/KwalifyError.html +111 -0
  15. data/doc-api/classes/Kwalify/Main.html +336 -0
  16. data/doc-api/classes/Kwalify/MetaValidator.html +432 -0
  17. data/doc-api/classes/Kwalify/Parser.html +155 -0
  18. data/doc-api/classes/Kwalify/PlainYamlParser.html +520 -0
  19. data/doc-api/classes/Kwalify/PlainYamlParser/Alias.html +165 -0
  20. data/doc-api/classes/Kwalify/Rule.html +411 -0
  21. data/doc-api/classes/Kwalify/SchemaError.html +148 -0
  22. data/doc-api/classes/Kwalify/Types.html +301 -0
  23. data/doc-api/classes/Kwalify/ValidationError.html +148 -0
  24. data/doc-api/classes/Kwalify/Validator.html +311 -0
  25. data/doc-api/classes/Kwalify/YamlParser.html +535 -0
  26. data/doc-api/classes/Kwalify/YamlSyntaxError.html +168 -0
  27. data/doc-api/classes/Test.html +107 -0
  28. data/doc-api/classes/Test/Unit.html +101 -0
  29. data/doc-api/classes/YamlHelper.html +259 -0
  30. data/doc-api/created.rid +1 -0
  31. data/doc-api/files/__/README_txt.html +179 -0
  32. data/doc-api/files/kwalify/errors_rb.html +114 -0
  33. data/doc-api/files/kwalify/main_rb.html +117 -0
  34. data/doc-api/files/kwalify/messages_rb.html +107 -0
  35. data/doc-api/files/kwalify/meta-validator_rb.html +117 -0
  36. data/doc-api/files/kwalify/rule_rb.html +116 -0
  37. data/doc-api/files/kwalify/types_rb.html +114 -0
  38. data/doc-api/files/kwalify/util/assert-text-equal_rb.html +115 -0
  39. data/doc-api/files/kwalify/util/hash-interface_rb.html +107 -0
  40. data/doc-api/files/kwalify/util/option-parser_rb.html +107 -0
  41. data/doc-api/files/kwalify/util/testcase-helper_rb.html +115 -0
  42. data/doc-api/files/kwalify/util/yaml-helper_rb.html +114 -0
  43. data/doc-api/files/kwalify/validator_rb.html +117 -0
  44. data/doc-api/files/kwalify/yaml-parser_rb.html +117 -0
  45. data/doc-api/files/kwalify_rb.html +120 -0
  46. data/doc-api/fr_class_index.html +50 -0
  47. data/doc-api/fr_file_index.html +41 -0
  48. data/doc-api/fr_method_index.html +109 -0
  49. data/doc-api/index.html +24 -0
  50. data/doc-api/rdoc-style.css +208 -0
  51. data/doc/users-guide.html +693 -193
  52. data/examples/address-book/Makefile +5 -0
  53. data/examples/address-book/address-book.schema.yaml +2 -1
  54. data/examples/invoice/Makefile +5 -0
  55. data/examples/invoice/invoice.schema.yaml +3 -2
  56. data/examples/tapkit/Makefile +5 -0
  57. data/examples/tapkit/main.rb +7 -0
  58. data/examples/tapkit/tapkit.schema.yaml +6 -1
  59. data/lib/kwalify.rb +3 -3
  60. data/lib/kwalify/errors.rb +2 -2
  61. data/lib/kwalify/main.rb +161 -84
  62. data/lib/kwalify/messages.rb +17 -11
  63. data/lib/kwalify/meta-validator.rb +11 -2
  64. data/lib/kwalify/rule.rb +13 -3
  65. data/lib/kwalify/templates/genclass-java.eruby +195 -0
  66. data/lib/kwalify/templates/genclass-ruby.eruby +84 -0
  67. data/lib/kwalify/types.rb +18 -18
  68. data/lib/kwalify/util/assert-text-equal.rb +44 -0
  69. data/lib/kwalify/util/hash-interface.rb +37 -0
  70. data/lib/kwalify/util/option-parser.rb +2 -2
  71. data/lib/kwalify/util/testcase-helper.rb +112 -0
  72. data/lib/kwalify/util/yaml-helper.rb +2 -2
  73. data/lib/kwalify/validator.rb +2 -2
  74. data/lib/kwalify/yaml-parser.rb +12 -9
  75. data/test/test-main.rb +77 -78
  76. data/test/test-main.yaml +543 -769
  77. data/test/test-metavalidator.rb +27 -47
  78. data/test/test-metavalidator.yaml +21 -2
  79. data/test/test-rule.rb +6 -39
  80. data/test/test-rule.yaml +2 -2
  81. data/test/test-validator.rb +36 -869
  82. data/test/test-validator.yaml +28 -20
  83. data/test/test-yamlparser.rb +30 -1248
  84. data/test/test-yamlparser.yaml +138 -110
  85. data/test/test.rb +33 -13
  86. data/test/tmp.dir/Context.java +40 -0
  87. data/test/tmp.dir/Group.java +33 -0
  88. data/test/tmp.dir/User.java +43 -0
  89. data/test/tmp.dir/action1.document +18 -0
  90. data/test/tmp.dir/action1.schema +32 -0
  91. data/test/tmp.dir/action2.document +18 -0
  92. data/test/tmp.dir/action2.schema +32 -0
  93. data/test/tmp.dir/emacs.document +6 -0
  94. data/test/tmp.dir/emacs.schema +6 -0
  95. data/test/tmp.dir/meta1.document +0 -0
  96. data/test/tmp.dir/meta1.schema +3 -0
  97. data/test/tmp.dir/meta2.document +0 -0
  98. data/test/tmp.dir/meta2.schema +3 -0
  99. data/test/tmp.dir/silent1.document +3 -0
  100. data/test/tmp.dir/silent1.schema +3 -0
  101. data/test/tmp.dir/silent2.document +7 -0
  102. data/test/tmp.dir/silent2.schema +3 -0
  103. data/test/tmp.dir/stream.invalid +8 -0
  104. data/test/tmp.dir/stream.schema +3 -0
  105. data/test/tmp.dir/stream.valid +8 -0
  106. data/test/tmp.dir/untabify.document +5 -0
  107. data/test/tmp.dir/untabify.schema +10 -0
  108. metadata +98 -12
  109. data/lib/kwalify/util/assert-diff.rb +0 -44
@@ -2,4 +2,9 @@
2
2
  all:
3
3
  kwalify -lm address-book.schema.yaml
4
4
  kwalify -lf address-book.schema.yaml address-book.yaml
5
+ kwalify -a genclass-ruby -lf address-book.schema.yaml > address-book.rb
6
+ # kwalify -a genclass-java -lf address-book.schema.yaml
5
7
 
8
+
9
+ clean:
10
+ rm -f address-book.rb
@@ -1,7 +1,7 @@
1
1
  ##
2
2
  ## Kwalify schema example for address book
3
3
  ##
4
- ## $Release: 0.5.1 $
4
+ ## $Release: 0.6.0 $
5
5
  ## copyright(c) 2005 kuwata-lab all rights reserved.
6
6
  ##
7
7
  ##
@@ -12,6 +12,7 @@ type: seq
12
12
  required: yes
13
13
  sequence:
14
14
  - type: map
15
+ classname: Person
15
16
  required: yes
16
17
  mapping:
17
18
  "name":
@@ -1,4 +1,9 @@
1
1
  all:
2
2
  kwalify -lm invoice.schema.yaml
3
3
  kwalify -lf invoice.schema.yaml invoice.yaml
4
+ kwalify -a genclass-ruby -lf invoice.schema.yaml > invoice.rb
5
+ # kwalify -a genclass-java -lf invoice.schema.yaml
4
6
 
7
+
8
+ clean:
9
+ rm -f invoice.rb
@@ -1,12 +1,13 @@
1
1
  ###
2
2
  ### Kwalify schema example for invoice
3
3
  ###
4
- ### $Rev: 41 $
5
- ### $Release: 0.5.1 $
4
+ ### $Rev: 51 $
5
+ ### $Release: 0.6.0 $
6
6
  ### copyright(c) 2005 kuwata-lab all rights reserved.
7
7
  ###
8
8
 
9
9
  type: map
10
+ classname: Invoice
10
11
  required: yes
11
12
  mapping:
12
13
  "invoice": { type: int, required: yes, unique: yes }
@@ -2,4 +2,9 @@
2
2
  all:
3
3
  kwalify -lm tapkit.schema.yaml
4
4
  kwalify -lf tapkit.schema.yaml tapkit.yaml
5
+ kwalify -a genclass-ruby -lf tapkit.schema.yaml --module=Tapkit > tapkit.rb
6
+ # kwalify -a genclass-java -lf tapkit.schema.yaml --package=tapkit
5
7
 
8
+
9
+ clean:
10
+ rm -f tapkit.rb
@@ -0,0 +1,7 @@
1
+ require 'yaml'
2
+ ydoc = YAML.load_file('tapkit.yaml')
3
+
4
+ require 'tapkit'
5
+ schema = Tapkit::Schema.new(ydoc)
6
+ require 'pp'
7
+ pp schema
@@ -1,11 +1,12 @@
1
1
  ##
2
2
  ## Kwalify schema example for TapKit
3
3
  ##
4
- ## $Release: 0.5.1 $
4
+ ## $Release: 0.6.0 $
5
5
  ## copyright(c) 2005 kuwata-lab all rights reserved.
6
6
  ##
7
7
 
8
8
  type: map
9
+ classname: Schema
9
10
  mapping:
10
11
  "adapter_name":
11
12
  type: str
@@ -17,6 +18,7 @@ mapping:
17
18
  #- OpenBase
18
19
  "connection":
19
20
  type: map
21
+ classname: Connection
20
22
  mapping:
21
23
  "url":
22
24
  type: str
@@ -37,6 +39,7 @@ mapping:
37
39
  type: seq
38
40
  sequence:
39
41
  - type: map
42
+ classname: Entity
40
43
  mapping:
41
44
  "name":
42
45
  type: str
@@ -61,6 +64,7 @@ mapping:
61
64
  required: yes
62
65
  sequence:
63
66
  - type: map
67
+ classname: Attribute
64
68
  mapping:
65
69
  "name":
66
70
  type: str
@@ -104,6 +108,7 @@ mapping:
104
108
  type: seq
105
109
  sequence:
106
110
  - type: map
111
+ classname: Relationship
107
112
  mapping:
108
113
  "name":
109
114
  type: str
@@ -1,13 +1,13 @@
1
1
  ###
2
- ### $Rev: 42 $
3
- ### $Release: 0.5.1 $
2
+ ### $Rev: 48 $
3
+ ### $Release: 0.6.0 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
7
7
 
8
8
  module Kwalify
9
9
 
10
- RELEASE = ("$Release: 0.5.1 $" =~ /[.\d]+/) && $&
10
+ RELEASE = ("$Release: 0.6.0 $" =~ /[.\d]+/) && $&
11
11
 
12
12
  end
13
13
 
@@ -1,6 +1,6 @@
1
1
  ###
2
- ### $Rev: 42 $
3
- ### $Release: 0.5.1 $
2
+ ### $Rev: 48 $
3
+ ### $Release: 0.6.0 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
@@ -1,10 +1,11 @@
1
1
  ###
2
- ### $Rev: 44 $
3
- ### $Release: 0.5.1 $
2
+ ### $Rev: 51 $
3
+ ### $Release: 0.6.0 $
4
4
  ### copyright(c) 2005 kuwata-lab all rights reserved.
5
5
  ###
6
6
 
7
7
  require 'yaml'
8
+ require 'erb'
8
9
  require 'kwalify'
9
10
  require 'kwalify/util/yaml-helper'
10
11
  #require 'kwalify/util/option-parser'
@@ -12,6 +13,7 @@ require 'kwalify/util/yaml-helper'
12
13
 
13
14
  module Kwalify
14
15
 
16
+
15
17
  class CommandOptionError < KwalifyError
16
18
  def initialize(message, option, error_symbol)
17
19
  super(message)
@@ -39,43 +41,40 @@ module Kwalify
39
41
  ##
40
42
  class Main
41
43
 
44
+
42
45
  def initialize(command=nil)
43
46
  @command = command || File.basename($0)
44
- @flag_help = false
45
- @flag_version = false
46
- @flag_silent = false
47
- @flag_meta = false
48
- @flag_untabify = false
49
- @flag_emacs = false
50
- @flag_linenum = false
51
- @flag_debug = false
52
- @schema_filename = nil
47
+ @options = {}
53
48
  @properties = {}
49
+ @template_path = []
50
+ $:.each do |path|
51
+ tpath = "#{path}/kwalify/templates"
52
+ @template_path << tpath if test(?d, tpath)
53
+ end
54
54
  end
55
55
 
56
56
 
57
57
  def debug?
58
- @flag_debug
58
+ @options[:debug]
59
59
  end
60
60
 
61
61
 
62
62
  def _inspect()
63
- s = ""
64
- s << "command : #{@command}\n"
65
- s << "flag_help : #{@flag_help}\n"
66
- s << "flag_version : #{@flag_version}\n"
67
- s << "flag_silent : #{@flag_silent}\n"
68
- s << "flag_meta : #{@flag_meta}\n"
69
- s << "flag_untabify : #{@flag_untabify}\n"
70
- s << "flag_emacs : #{@flag_emacs}\n"
71
- s << "flag_linenum : #{@flag_linenum}\n"
72
- s << "flag_debug : #{@flag_debug}\n"
73
- s << "schema_filename : #{@schema_filename != nil ? @schema_filename : 'null'}\n"
74
- s << "properties:\n"
75
- @properties.each do |key, val|
76
- s << " #{key}: #{val}\n"
63
+ sb = []
64
+ sb << "command: #{@command}\n"
65
+ sb << "options:\n"
66
+ @options.keys.sort {|k1,k2| k1.to_s<=>k2.to_s }.each do |key|
67
+ sb << " - #{key}: #{@options[key]}\n"
77
68
  end
78
- return s
69
+ sb << "properties:\n"
70
+ @properties.keys.sort_by {|k| k.to_s}.each do |key|
71
+ sb << " - #{key}: #{@properties[key]}\n"
72
+ end
73
+ #sb << "template_path:\n"
74
+ #@template_path.each do |path|
75
+ # sb << " - #{path}\n"
76
+ #end
77
+ return sb.join
79
78
  end
80
79
 
81
80
 
@@ -84,21 +83,31 @@ module Kwalify
84
83
  filenames = _parse_argv(argv)
85
84
 
86
85
  # help or version
87
- s = ''
88
- s << _version() << "\n" if @flag_version
89
- s << _usage() if @flag_help
90
- return s unless s.empty?
86
+ if @options[:help] || @options[:version]
87
+ action = @options[:action]
88
+ s = ''
89
+ s << _version() << "\n" if @options[:version]
90
+ s << _usage() if @options[:help] && !action
91
+ s << _describe_properties(action) if @options[:help] && action
92
+ return s
93
+ end
91
94
 
92
95
  # validation
93
- if @flag_meta2
96
+ if @options[:meta2]
94
97
  s = _quick_meta_validate(filenames)
95
- elsif @flag_meta
98
+ elsif @options[:meta]
96
99
  s = _meta_validate(filenames)
97
- elsif @schema_filename
98
- if @flag_debug
99
- s = _inspect_schema(@schema_filename)
100
+ elsif @options[:action]
101
+ if !@options[:schema]
102
+ #* key=:command_option_actionnoschema msg="schema filename is not specified."
103
+ raise option_error(:command_option_actionnoschema, @options[:action])
104
+ end
105
+ s = _perform_action(@options[:action], @options[:schema])
106
+ elsif @options[:schema]
107
+ if @options[:debug]
108
+ s = _inspect_schema(@options[:schema])
100
109
  else
101
- s = _validate(filenames, @schema_filename)
110
+ s = _validate(filenames, @options[:schema])
102
111
  end
103
112
  else
104
113
  #* key=:command_option_noaction msg="command-line option '-f' or '-m' required."
@@ -111,21 +120,21 @@ module Kwalify
111
120
  def self.main(command, argv=ARGV)
112
121
  begin
113
122
  main = Kwalify::Main.new(command)
114
- s = main.execute(ARGV)
123
+ s = main.execute(argv)
115
124
  print s if s
116
- #rescue Kwalify::CommandOptionError => ex
117
- # $stderr.puts ex.message
118
- # exit 1
119
- #rescue Kwalify::KwalifyError => ex
120
- # $stderr.puts "ERROR: #{ex.message}"
121
- # exit 1
122
- rescue => ex
123
- if main.debug?
124
- raise ex
125
- else
126
- $stderr.puts ex.message
127
- exit 1
128
- end
125
+ rescue Kwalify::CommandOptionError => ex
126
+ $stderr.puts ex.message
127
+ exit 1
128
+ rescue Kwalify::KwalifyError => ex
129
+ $stderr.puts "ERROR: #{ex.message}"
130
+ exit 1
131
+ #rescue => ex
132
+ # if main.debug?
133
+ # raise ex
134
+ # else
135
+ # $stderr.puts ex.message
136
+ # exit 1
137
+ # end
129
138
  end
130
139
  end
131
140
 
@@ -139,10 +148,51 @@ module Kwalify
139
148
  end
140
149
 
141
150
 
151
+ def _find_template(action)
152
+ template_filename = action + '.eruby'
153
+ unless test(?f, template_filename)
154
+ tpath = @template_path.find { |path| test(?f, "#{path}/#{template_filename}") }
155
+ #* key=:command_option_notemplate msg="%s: invalid action (template not found).\n"
156
+ raise option_error(:command_option_notemplate, action) unless tpath
157
+ template_filename = "#{tpath}/#{action}.eruby"
158
+ end
159
+ return template_filename
160
+ end
161
+
162
+
163
+ def _apply_template(template_filename, hash)
164
+ template = File.read(template_filename)
165
+ trim_mode = 1
166
+ erb = ERB.new(template, $SAFE, trim_mode)
167
+ context = Object.new
168
+ hash.each do |key, val|
169
+ context.instance_variable_set("@#{key}", val)
170
+ end
171
+ return context.instance_eval(erb.src, template_filename)
172
+ end
173
+
174
+
175
+ def _describe_properties(action)
176
+ template_filename = _find_template(action)
177
+ s = _apply_template(template_filename, :describe=>true)
178
+ return s
179
+ end
180
+
181
+
182
+ def _perform_action(action, schema_filename, describe=false)
183
+ template_filename = _find_template(action)
184
+ schema = _load_schema_file(schema_filename)
185
+ rule = Rule.new(schema)
186
+ @properties[:schema_filename] = schema_filename
187
+ s = _apply_template(template_filename, :rule=>rule, :properties=>@properties)
188
+ return s
189
+ end
190
+
191
+
142
192
  def _inspect_schema(schema_filename)
143
193
  filename = schema_filename
144
194
  str = File.open(schema_filename) { |f| f.read() }
145
- str = YamlUtil.untabify(str) if @flag_untabify
195
+ str = YamlUtil.untabify(str) if @options[:untabify]
146
196
  schema = YAML.load(str)
147
197
  return nil if schema == nil
148
198
  validator = Kwalify::Validator.new(schema) # error raised when schema is wrong
@@ -152,6 +202,7 @@ module Kwalify
152
202
  end
153
203
 
154
204
 
205
+ #--
155
206
  #class QuickMetaValidator
156
207
  # def validate(schema)
157
208
  # errors = []
@@ -163,6 +214,7 @@ module Kwalify
163
214
  # return errors
164
215
  # end
165
216
  #end
217
+ #++
166
218
 
167
219
 
168
220
  def _quick_meta_validate(filenames)
@@ -181,6 +233,15 @@ module Kwalify
181
233
  end
182
234
 
183
235
 
236
+ def _load_schema_file(schema_filename)
237
+ filename = schema_filename
238
+ str = File.read(filename)
239
+ str = YamlHelper.untabify(str) if @options[:untabify]
240
+ schema = YAML.load(str)
241
+ return schema
242
+ end
243
+
244
+
184
245
  def _meta_validate(filenames)
185
246
  meta_validator = Kwalify::MetaValidator.instance()
186
247
  s = _validate_files(meta_validator, filenames)
@@ -189,10 +250,7 @@ module Kwalify
189
250
 
190
251
 
191
252
  def _validate(filenames, schema_filename)
192
- filename = schema_filename
193
- str = File.open(filename) { |f| f.read() } # or File.read(filename) in ruby1.8
194
- str = YamlHelper.untabify(str) if @flag_untabify
195
- schema = YAML.load(str)
253
+ schema = _load_schema_file(schema_filename)
196
254
  if schema
197
255
  validator = Kwalify::Validator.new(schema)
198
256
  s = _validate_files(validator, filenames)
@@ -214,8 +272,8 @@ module Kwalify
214
272
  str = $stdin.read()
215
273
  filename = '(stdin)'
216
274
  end
217
- str = YamlHelper.untabify(str) if @flag_untabify
218
- if @flag_linenum
275
+ str = YamlHelper.untabify(str) if @options[:untabify]
276
+ if @options[:linenum]
219
277
  parser = Kwalify::YamlParser.new(str)
220
278
  i = 0
221
279
  while parser.has_next?
@@ -246,22 +304,22 @@ module Kwalify
246
304
  errors = validator.validate(doc)
247
305
  if errors == nil || errors.empty?
248
306
  #* key=:validation_valid msg="%s#%d: valid.\n"
249
- s << Kwalify.msg(:validation_valid) % [filename, i] unless @flag_silent
307
+ s << Kwalify.msg(:validation_valid) % [filename, i] unless @options[:silent]
250
308
  else
251
309
  #* key=:validation_invalid msg="%s#%d: INVALID\n"
252
310
  s << Kwalify.msg(:validation_invalid) % [filename, i]
253
- if @flag_linenum
311
+ if @options[:linenum]
254
312
  #assert parser != nil
255
313
  raise unless parser != nil
256
314
  parser.set_errors_linenum(errors)
257
315
  errors.sort!
258
316
  end
259
317
  errors.each do |error|
260
- if @flag_emacs
261
- #assert @flag_linenum
262
- raise unless @flag_linenum
318
+ if @options[:emacs]
319
+ #assert @options[:linenum]
320
+ raise unless @options[:linenum]
263
321
  s << "#{filename}:#{error.linenum}: [#{error.path}] #{error.message}\n"
264
- elsif @flag_linenum
322
+ elsif @options[:linenum]
265
323
  s << " - (line #{error.linenum}) [#{error.path}] #{error.message}\n"
266
324
  else
267
325
  s << " - [#{error.path}] #{error.message}\n"
@@ -273,7 +331,8 @@ module Kwalify
273
331
 
274
332
 
275
333
  def _usage()
276
- msg = Kwalify.msg(:command_help) % [@command, @command]
334
+ #msg = Kwalify.msg(:command_help) % [@command, @command, @command]
335
+ msg = Kwalify.msg(:command_help)
277
336
  return msg
278
337
  end
279
338
 
@@ -298,6 +357,30 @@ module Kwalify
298
357
 
299
358
 
300
359
  def _parse_argv(argv)
360
+ option_table = {
361
+ ?h => :help,
362
+ ?v => :version,
363
+ ?s => :silent,
364
+ ?t => :untabify,
365
+ ?m => :meta,
366
+ ?M => :meta2,
367
+ ?E => :emacs,
368
+ ?l => :linenum,
369
+ ?f => :schema,
370
+ ?D => :debug,
371
+ ?a => :action,
372
+ ?I => :tpath,
373
+ }
374
+
375
+ errcode_table = {
376
+ #* key=:command_option_noschema msg="-%s: schema filename required."
377
+ ?f => :command_option_noschema,
378
+ #* key=:command_option_noaction msg="-%s: action required."
379
+ ?a => :command_option_noaction,
380
+ #* key=:command_option_notpath msg="-%s: template path required."
381
+ ?I => :command_option_notpath,
382
+ }
383
+
301
384
  while argv[0] && argv[0][0] == ?-
302
385
  optstr = argv.shift
303
386
  optstr = optstr[1, optstr.length-1]
@@ -316,33 +399,27 @@ module Kwalify
316
399
  while optstr && !optstr.empty?
317
400
  optchar = optstr[0]
318
401
  optstr[0,1] = ""
402
+ unless option_table.key?(optchar)
403
+ #* key=:command_option_invalid msg="-%s: invalid command option."
404
+ raise option_error(:command_option_invalid, optchar.chr)
405
+ end
406
+ optkey = option_table[optchar]
319
407
  case optchar
320
- when ?h ; @flag_help = true
321
- when ?v ; @flag_version = true
322
- when ?s ; @flag_silent = true
323
- when ?t ; @flag_untabify = true
324
- when ?m ; @flag_meta = true
325
- when ?M ; @flag_meta2 = true
326
- when ?E ; @flag_emacs = true ; @flag_linenum = true
327
- when ?l ; @flag_linenum = true
328
- when ?D ; @flag_debug = true
329
- when ?f ;
408
+ when ?f, ?a, ?I
330
409
  arg = optstr.empty? ? argv.shift : optstr
331
- #* key=:command_option_noarg msg="-%s: argument required."
332
- #* key=:command_option_noschema msg="-%s: schema filename required."
333
- raise option_error(:command_option_noschema, "f") unless arg
334
- @schema_filename = arg
335
- optstr = nil
410
+ raise option_error(errcode_table[optchar], optchar.chr) unless arg
411
+ @options[optkey] = arg
412
+ optstr = ''
336
413
  else
337
- #* key=:command_option_invalid msg="-%s: invalid command option."
338
- raise option_error(:command_option_invalid, optchar.chr)
414
+ @options[optkey] = true
339
415
  end
340
416
  end
341
417
  end
342
418
  end # end of while
343
419
  #
344
- @flag_help = true if @properties[:help]
345
- @flag_version = true if @properties[:version]
420
+ @options[:linenum] = true if @options[:emacs]
421
+ @options[:help] = true if @properties[:help]
422
+ @options[:version] = true if @properties[:version]
346
423
  filenames = argv
347
424
  return filenames
348
425
  end