Class: Ditto::Options
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Ditto::Options
- Includes:
- Singleton
- Defined in:
- lib/ditto/options.rb
Constant Summary collapse
- DEFAULTS =
{ :connstring => ENV['DATABASE_URL'] || 'nodb://a/b', :modelpath => '.', :debug => false, :droptables => false, :verbose => 0, :loadpaths => nil }
Instance Method Summary collapse
-
#initialize ⇒ Options
constructor
A new instance of Options.
- #parse(argv) ⇒ Object
Constructor Details
Instance Method Details
#parse(argv) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ditto/options.rb', line 21 def parse argv Ditto::Options::DEFAULTS.each do |k,v| self.send "#{k}=".to_s, v end OptionParser.new do |opts| opts. = "Usage: ditto [ options ] paths..." opts.separator "Paths will be searched for .ditto files (definitions) and .yaml files (data)" opts.on("-c STRING", "--connection", String, "Database connection string", "Defaults to environment variable DATABASE_URL", "Current default is #{DEFAULTS[:connstring]}") do |s| self.connstring = s end opts.on("-m PATH", "--modelpath", String, "Path to load DataMapper models from (default #{DEFAULTS[:modelpath]})") do |m| raise "Modelpath #{m} does not exist!" unless Dir.exist?(m) self.modelpath = m end opts.on("-d", "--debug", "Debug") do |s| self.debug = true end opts.on("-v", "--verbose", "Verbose (repeat for more)") do self.verbose += 1 end opts.on("--droptables", "Delete existing database tables!") do self.droptables = true end opts.on("-?", "-h", "--help", "Show this message") do puts opts exit end begin opts.parse!(argv) rescue OptionParser::ParseError => e STDERR.puts e., "\n", opts exit(-1) end end self.loadpaths = argv return self end |