Class: Devproxy::CLI

Inherits:
Connection show all
Defined in:
lib/devproxy/cli.rb

Constant Summary

Constants inherited from Connection

Devproxy::Connection::MAX_DOTS

Instance Attribute Summary

Attributes inherited from Connection

#options, #ssh

Class Method Summary collapse

Methods inherited from Connection

#halt?, #initialize, #loop!, loop!, #on_close, #on_stderr, #on_stdout, open_ssh, #stop!

Constructor Details

This class inherits a constructor from Devproxy::Connection

Class Method Details

.create(argv) ⇒ Object



51
52
53
# File 'lib/devproxy/cli.rb', line 51

def self.create(argv)
  super(parse(argv))
end

.parse(argv) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
# File 'lib/devproxy/cli.rb', line 6

def self.parse(argv)
  options = Devproxy::Options::default
  opts    = OptionParser.new
  opts.banner = "Usage: devproxy user [proxy] [options...]"

  opts.separator ""
  opts.separator "    user: \tDevproxy username."
  opts.separator "    proxy:\tThe name of the proxy you want to connect to (without the domain)."
  opts.separator "          \tDefaults to `user`."
  opts.separator "          \texample: 'foo' for tunneling 'foo.devproxy.io'"

  opts.separator ""

  opts.on "-p PORT", "--port PORT", Integer,
          "Local port accepting connections (default: #{options.port})" do |x|
    options.port = x
  end

  if ENV['DEVPROXY_DEVELOPMENT']
    opts.on "--host HOST", "remote hostname." do |x|
      options.host = x
    end
    opts.on "--remote-port PORT",Integer,"remote SSH port" do |x|
      options.remote_port = x
    end
  end

  opts.on_tail "-h", "--help", "show this message" do
    puts opts
    exit
  end

  opts.on_tail "--version", "Show version" do
    puts Devproxy::VERSION.join('.')
    exit
  end
  opts.parse!(argv)
  options.user  = argv[0]
  options.proxy = argv[1] || argv[0]
  unless options.valid?
    puts opts
    exit
  end
  options
end