Welcome to the "trac"-ing site of soap4r!
[soap4r] [httpclient] [openpgp4u] [pkcs1] [logger] [csv] [vtr]

root/tags/RELEASE_1_5_6/bin/xsd2ruby.rb

Revision 1437, 1.5 kB (checked in by nahi, 4 years ago)

let wsdl2ruby.rb and xsd2ruby.rb be a library. bin/wsdl2ruby.rb and bin/xsd2ruby.rb use these libraries. let tests use the libraries. fixes #69.

Line 
1 #!/usr/bin/env ruby
2
3 require 'getoptlong'
4 require 'logger'
5 require 'wsdl/xmlSchema/xsd2ruby'
6
7
8 class XSD2RubyApp < Logger::Application
9 private
10
11   OptSet = [
12     ['--xsd','-x', GetoptLong::REQUIRED_ARGUMENT],
13     ['--classname','-n', GetoptLong::NO_ARGUMENT],
14     ['--force','-f', GetoptLong::NO_ARGUMENT],
15     ['--quiet','-q', GetoptLong::NO_ARGUMENT],
16   ]
17
18   def initialize
19     super('app')
20     STDERR.sync = true
21     self.level = Logger::FATAL
22   end
23
24   def run
25     @worker = WSDL::XMLSchema::XSD2Ruby.new
26     @worker.logger = @log
27     location, opt = parse_opt(GetoptLong.new(*OptSet))
28     usage_exit unless location
29     @worker.location = location
30     if opt['quiet']
31       self.level = Logger::FATAL
32     else
33       self.level = Logger::INFO
34     end
35     @worker.opt.update(opt)
36     @worker.run
37     0
38   end
39
40   def usage_exit
41     puts <<__EOU__
42 Usage: #{ $0 } --xsd xsd_location [options]
43   xsd_location: filename or URL
44
45 Example:
46   #{ $0 } --xsd myapp.xsd --classname Foo
47
48 Options:
49   --xsd xsd_location
50   --classname classname
51   --force
52   --quiet
53 __EOU__
54     exit 1
55   end
56
57   def parse_opt(getoptlong)
58     opt = {}
59     xsd = nil
60     begin
61       getoptlong.each do |name, arg|
62         case name
63         when "--xsd"
64           xsd = arg
65         when "--classname"
66           opt[name.sub(/^--/, '')] = arg.empty? ? nil : arg
67         when "--force"
68           opt['force'] = true
69         when "--quiet"
70           opt['quiet'] = true
71         else
72           raise ArgumentError.new("Unknown type #{ arg }")
73         end
74       end
75     rescue
76       usage_exit
77     end
78     return xsd, opt
79   end
80 end
81
82 XSD2RubyApp.new.start
Note: See TracBrowser for help on using the browser.