Class: Modown::Options
- Inherits:
-
Object
- Object
- Modown::Options
- Defined in:
- lib/modown/options.rb
Overview
This class handles command line options
Instance Method Summary collapse
-
#initialize ⇒ Options
constructor
A new instance of Options.
-
#parse(args) ⇒ Hash
Parse the command line arguments.
Constructor Details
#initialize ⇒ Options
Returns a new instance of Options.
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/modown/options.rb', line 7 def initialize @options = { input: nil, count: 1, format: '*' } # Dont know how to do case-insensitive glob matching @formats_glob = {} @formats_glob['3ds'] = '*.3[Dd][Ss]' @formats_glob['max'] = '*.[Mm][Aa][Xx]' @formats_glob['gsm'] = '*.[Gg][Ss][Mm]' @formats_glob['mtl'] = '*.[Mm][Tt][Ll]' @formats_glob['*'] = '*' end |
Instance Method Details
#parse(args) ⇒ Hash
Parse the command line arguments
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/modown/options.rb', line 22 def parse(args) parser = OptionParser.new do |opts| opts. = 'Usage: modown [options] Object' opts.on('-c', '--count COUNT', Integer, 'Number of different models you want') do |count| @options[:count] = count end opts.on('-f', '--format FORMAT', 'The file format you want.', "Supported formats are [#{@formats_glob.keys.join(',')}].", 'All files are stored if no FORMAT is provided') do |format| @options[:format] = @formats_glob[format] end opts.on('-h', '--help', 'Displays Help') do puts opts exit end end parser.parse!(args) raise '[ERROR] Please provide the object to search' if args.length == 0 raise "[ERROR] Please provide a valid format for the -f flag. Supported formats are [#{@formats_glob.keys.join(',')}]" if @options[:format].nil? @options[:search_term] = args[0] @options end |