Sha256: f23a6d191b0271d46bba7846fa17e9c640adf7c5f1caf2ed3c1674f67f8ee777

Contents?: true

Size: 1.15 KB

Versions: 6

Compression:

Stored size: 1.15 KB

Contents

require 'optparse'

module Wparser
  class CLI
    def self.execute(stdout, arguments=[])

      # NOTE: the option -p/--path= is given as an example, and should be replaced in your application.

      options = {
        :path     => '~'
      }
      mandatory_options = %w(  )

      parser = OptionParser.new do |opts|
        opts.banner = <<-BANNER.gsub(/^          /,'')
          This application is wonderful because...

          Usage: #{File.basename($0)} [options]

          Options are:
        BANNER
        opts.separator ""
        opts.on("-p", "--path PATH", String,
                "This is a sample message.",
                "For multiple lines, add more strings.",
                "Default: ~") { |arg| options[:path] = arg }
        opts.on("-h", "--help",
                "Show this help message.") { stdout.puts opts; exit }
        opts.parse!(arguments)

        if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
          stdout.puts opts; exit
        end
      end

      path = options[:path]

      # do stuff
      stdout.puts "To update this executable, look in lib/wparser/cli.rb"
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wparser-0.1.3 lib/wparser/cli.rb
wparser-0.1.2 lib/wparser/cli.rb
wparser-0.1.1 lib/wparser/cli.rb
wparser-0.1.0 lib/wparser/cli.rb
wparser-0.0.2 lib/wparser/cli.rb
wparser-0.0.1 lib/wparser/cli.rb