Sha256: 7d1581a2d8170ae13168e7aa207d525cac218106211c7a3d2d55cbd5326eabc7
Contents?: true
Size: 1 KB
Versions: 1
Compression:
Stored size: 1 KB
Contents
require 'optparse' module SnowmanIO # Parse command line. class Options AVAILABLE_COMMANDS = %w[server] def parse!(args) options = default_options opt_parser = OptionParser.new do |opts| opts.banner = "Usage: snowman COMMAND [options]" opts.separator "" opts.separator "Commands" opts.separator " server Run SnowManIO server" opts.separator "" opts.separator "Server options:" opts.on("-p", "--port PORT", "use PORT (default: 4567)") do |port| options[:port] = port.to_i end if args.empty? puts opts exit end options[:command] = args.shift unless AVAILABLE_COMMANDS.include?(options[:command]) puts "Error: Command '#{options[:command]}' not recognized" puts opts exit end end opt_parser.parse!(args) options end private def default_options { port: 4567 } end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
snowman-io-0.0.3 | lib/snowman-io/options.rb |