Class: Pair::Cli::Host

Inherits:
Pair::Cli show all
Defined in:
lib/pair/cli/host.rb

Instance Attribute Summary

Attributes inherited from Pair::Cli

#arguments, #options

Instance Method Summary collapse

Methods inherited from Pair::Cli

#initialize, run!

Constructor Details

This class inherits a constructor from Pair::Cli

Instance Method Details

#parse!Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/pair/cli/host.rb', line 26

def parse!
  opts = parse do |opts|
    opts.banner = "Usage: #{$0.split("/").last} host [-s SESSION_NAME] [-v PAIR[,PAIR[,...]] [-p PAIR[,PAIR[,...]]" +
                  "\n\n" +
                  "At least one PAIR (of any type must be defined). A PAIR takes the form of a Github username." +
                  "\n\n"+
                  "Options:"

    opts.on("-s", "--session-name=SESSION_NAME", "Automatically generated by server if not provided.") do |session_name|
      options[:name] = session_name
    end

    opts.on("-v", "--viewers=PAIRS", Array) do |pairs|
      options[:viewers] = pairs
    end

    opts.on("-p", "--participants=PAIRS", Array) do |pairs|
      options[:participants] = pairs
    end

    opts.on_tail("-h", "--help", "Display this text") do
      puts opts
      exit
    end
  end

  if options[:viewers].to_a.empty? && options[:participants].to_a.empty?
    $stderr.puts "ERROR: At least one PAIR is required...\n\n"
    abort(opts.inspect)
  end
end

#run!Object



4
5
6
7
8
9
10
# File 'lib/pair/cli/host.rb', line 4

def run!
  parse!

  with_valid_config do
    Pair::Session.host(options)
  end
end

#with_valid_configObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pair/cli/host.rb', line 12

def with_valid_config
  config = Pair.config

  unless config.api_token
    raise ApiTokenMissingError.new("api-token is required. try --help to understand how")
  end

  unless config.ssh_on?
    raise EnableSSHError.new("ssh is not enabled, turn on ssh daemon to continue")
  end

  yield
end