Sha256: 90211c21e134b08d0d73ac58cdd87bf5cd6e76875868c4be3bb75916f7019ac8

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require "pair"
require "optparse"

module Pair
  class CommandLine
    attr_accessor :arguments,  :options
    private       :arguments=, :options=

    def self.run!(*arguments)
      new(*arguments).run!
    end

    def initialize(arguments)
      self.arguments = arguments
      self.options   = {}
    end

    def run!
      case command = arguments.shift
      when 'host'
        require "pair/command_line/host"
        Host.run!(arguments)
      else
        unknown_command(command)
      end
    rescue SystemExit
      raise
    rescue
      if $-d
        STDOUT.puts "\n"
        STDOUT.puts "  Please contact support@pairmill.com, there"
        STDOUT.puts "  was an issue creating your session."
        STDOUT.puts "\n"
      else
        raise
      end
    end

    private
    def unknown_command(command)
      puts "Unknown command: #{command}" if command

      #{$0} join [options]
      abort %Q[
        Usage: #{$0} host [options]

        You can pass -h to a subcommand to learn more about it.

          e.g. #{$0} join -h
      ].gsub(/^ {0,9}/,'')
    end

    def parse
      opts = OptionParser.new { |o| yield(o) }
      opts.parse!(arguments)
      opts
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pair-0.0.2 lib/pair/command_line.rb
pair-0.0.1 lib/pair/command_line.rb