Sha256: 3961705150bbd67127e1c67ff44c314fdf4ee9e125ab56e6dd7150cf3dbd397e

Contents?: true

Size: 1.69 KB

Versions: 2

Compression:

Stored size: 1.69 KB

Contents

module Tane
  class Parser
    class << self

      def global_options
        @global_options ||= []
      end

      def global_option(name, *args)
        self.global_options << {:name => name, :args => args}
      end

      def parse(args)
        # The options specified on the command line will be collected in *options*.
        # We set default values here.
        options = OpenStruct.new
        options.scheme = "http"
        options.host = "localhost"
        options.port = 3000
        options.inplace = false
        options.encoding = "utf8"
        options.transfer_type = :auto
        options.verbose = false

        global_option :port,    '-p', '--port PORT',     Integer, "The port your local Cloudfuji app is running on"
        global_option :host,    '-n', '--host HOST',     String,  "The hostname where your local Cloudfuji app is running"
        global_option :scheme,  '-s', '--scheme SCHEME', String,  "Either http or https, whichever protocol your local Cloudfuji app is using"
        global_option :verbose, '-V', '--verbose',                "Output a lot of noise"

        opts = OptionParser.new do |opts|
          banner  = "Usage: tane command [options]\n"
          banner += Tane::Commands.command_list_and_help

          opts.banner = banner

          opts.separator ""
          opts.separator "Specific options:"

          # Mandatory argument.
          global_options.each do |option|
            opts.on(option[:name].to_s, *option[:args]) do |value|
              options.send("#{option[:name]}=", value)
            end
          end
          options.send("help_text=", opts.help())
          opts.parse!(args)
          return options
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tane-0.0.5 lib/tane/parser.rb
tane-0.0.4 lib/tane/parser.rb