Sha256: 93a0e13b0ce6bf6887b4d562a26eb3e68fd5769af71c023b3e18d6819f3a4656

Contents?: true

Size: 1.36 KB

Versions: 11

Compression:

Stored size: 1.36 KB

Contents

# -*- coding: utf-8 -*-

##
## ReVIEW::PDFMaker から、CLIに関する機能を分離する
##

require 'optparse'


module ReVIEW


  class CLI

    def initialize(script_name)
      @script_name = script_name
    end

    def parse_opts(args)
      parser = OptionParser.new
      parser.banner = "Usage: #{@script_name} <config.yaml>"
      parser.version = ReVIEW::VERSION
      cmdopts = {}
      parser.on('-h', '--help', 'Prints this message and quit.') do
        cmdopts['help'] = true
      end
      parser.on('--[no-]debug', 'Keep temporary files.') do |debug|
        cmdopts['debug'] = debug
      end
      parser.on('--ignore-errors', 'Ignore review-compile errors.') do
        cmdopts['ignore-errors'] = true
      end
      yield parser, cmdopts if block_given?
      @_cmdopt_parser = parser
      parser.parse!(args)
      #
      return cmdopts, args if cmdopts['help']
      #
      if args.length < 1
        raise OptionParser::InvalidOption.new("Config filename required.")
      elsif args.length > 1
        raise OptionParser::InvalidOption.new("Too many arguments.")
      end
      config_filename = args[0]
      File.exist?(config_filename)  or
        raise OptionParser::InvalidOption.new("file '#{config_filename}' not found.")
      #
      return cmdopts, config_filename
    end

    def help_message
      return @_cmdopt_parser.help
    end

  end


end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
review-retrovert-0.9.11 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.10 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.9 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.8 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.7 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.6 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.5 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.4 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.3 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.2 testdata/mybook/lib/ruby/review-cli.rb
review-retrovert-0.9.1 testdata/mybook/lib/ruby/review-cli.rb