Class: RubyIt::RubyItOptions
- Inherits:
-
Object
- Object
- RubyIt::RubyItOptions
- Defined in:
- lib/ruby_it/ruby_it_options.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
Return a structure describing the options.
Class Method Details
.parse(args) ⇒ Object
Return a structure describing the options.
12 13 14 15 16 17 18 19 20 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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby_it/ruby_it_options.rb', line 12 def self.parse(args) # The options specified on the command line will be collected in *options*. # We set default values here. = OpenStruct.new $verbose = false .version = RubyIt::VERSION .output_path = '' ## Order of Precedence #Commandline overrides Data file .data = Array.new .parameters = Array.new .output_filename = '' .filelist = Array.new opts = OptionParser.new do |opts| opts. = "Usage: #{__FILE__} [options] -p ../generated/ -f ../templates/input.rhtml Multiple -c, -p, -o and -f may be used but -f will use preceding -p and -o options" opts.separator "" opts.separator "Common options:" # No argument, shows at tail. This will print an options summary. opts.on("-h", "--help", "Show this message") do puts opts exit end # Another typical switch to print the version. opts.on("--version", "Show version") do #puts OptionParser::Version.join('.') puts "Version " + .version exit end # Specify Input Templates opts.on("-f", "--file input_filename", String, "Input source file to evaluate") do |input_filename| # TODO How to insert command line parameters (options.parameters) .input_filename = input_filename temp = RubyIt::Document.new(input_filename, .output_filename, .output_path) temp.add_parameter( .parameters ) .filelist << temp # Setting the output_filename is only valid for one input file .output_filename = "" end opts.separator "" opts.separator "Specific options:" # Control Verbosity opts.on("-v", "--[no-]verbose", "Run Verbosely") do |v| $verbose = v end opts.on("-q", "--quiet", "Run Quiet, not Verbose") do |v| $verbose = 0 end # Specify command line arguments ie --parameter @hellos=3 opts.on("--parameter param", String, "Command line parameters (Override data file settings)") do |param| pp param .parameters << param end # Specify Config Files opts.on("-c", "--config config_data", String, "Load Config File") do |data| .data << data end # Specify Output path if not the same as input opts.on("-p", "--outpath output_path", String, "Redirect generated file output") do |path| .output_path = path end # Rename output if different from input opts.on("-o", "--out output_filename", String, "Define different generated filename from source file") do |new_name| .output_filename = new_name end end .leftovers = opts.parse!(args) end |