Class: Subrip::Command
- Inherits:
-
Object
- Object
- Subrip::Command
- Defined in:
- lib/command.rb
Class Method Summary collapse
-
.parse(args) ⇒ Object
Return a structure describing the options.
-
.validate ⇒ Object
parse().
Class Method Details
.parse(args) ⇒ Object
Return a structure describing the options.
10 11 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 |
# File 'lib/command.rb', line 10 def self.parse(args) # The options specified on the command line will be collected in *options*. # We set default values here. @options = OpenStruct.new opts = OptionParser.new do |opts| opts. = "Usage: example.rb [options] input_file output_file" opts.separator "" opts.on("-o", "--operation OPERATION", [:add, :sub], "Operation can either be 'add' or 'sub'") do |oper| @options.operation = oper end opts.on("-t", "--time TIME_TO_SHIFT", "Time should be of format 11,222 where '11' is the amount of seconds and '222' the amount of milliseconds") do |time| @options.time_to_shift = time end opts.separator "" opts.separator "Common options:" # No argument, shows at tail. This will print an options summary. # Try it and see! opts.on_tail("-h", "--help", "Show this message") do puts opts exit end end # OptionParser.new do begin @options.ip_file = args.fetch(4) @options.op_file = args.fetch(5) rescue IndexError raise OptionParser::MissingArgument, "See --help." exit end opts.parse!(args) @options end |
.validate ⇒ Object
parse()
54 55 56 57 58 59 60 |
# File 'lib/command.rb', line 54 def self.validate if @options.ip_file.nil? or @options.op_file.nil? or @options.time_to_shift.nil? or @options.operation.nil? raise OptionParser::MissingArgument, "See --help." else true end end |