class Object

Constants

APP_VERSION
ARGV_COUNT

Public Instance Methods

parse_options(args) click to toggle source
# File bin/bechad, line 33
def parse_options(args)
    options = OpenStruct.new

    opt_parser = OptionParser.new do |opts|
      opts.banner = "Usage: bechad [options] cmd [args]\n\n" +
      "Avalaible commands:\n" +
      "  power-on\t\t- Power ON the tape recorder\n" +
      "  power-off\t\t- Power OFF the tape recorder\n" +
      "  record track-path\t\t- Record track into the tape recorder"

      options.verbose = false
      options.playlist_path = Pathname.new('./becha.playlist.conf').expand_path
      options.log_path = Pathname.new('./becha.log').expand_path
      options.errlog_path = Pathname.new('./becha.error.log').expand_path
      options.port = 2014

      opts.separator ""
      opts.separator "Common options:"

      opts.on("-l", "--playlist path", String, "Define playlist information") do |path|
        options.playlist_path = Pathname.new path
      end

      opts.on("-p", "--port num", Integer, "Define UDP port number") do |port|
        options.port = port
      end

      opts.on("-e", "--log path", String, "Define log file") do |path|
        options.log_path = Pathname.new path
      end

      opts.on("-E", "--errlog path", String, "Define log file for errors") do |path|
        options.errlog_path = Pathname.new path
      end

      opts.on("--verbose", "Print extra information") do
        options.verbose = true
      end

      opts.on_tail("-h", "--help", "Show this message") do
        puts opts
        exit
      end

      opts.on_tail("--version", "Show version") do
        puts APP_VERSION
        exit
      end
    end

    opt_parser.parse!(args)
    [options, opt_parser]
  end