Class: Devproxy::CLI

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

Defined Under Namespace

Classes: Options, Server

Constant Summary

Constants inherited from Connection

Devproxy::Connection::HEARTBEAT, Devproxy::Connection::MAX_DOTS

Instance Attribute Summary

Attributes inherited from Connection

#options, #ssh

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Connection

#halt?, loop!, #on_close, #on_connected, #on_heartbeat, #on_stderr, #on_stdout, open_ssh

Constructor Details

#initialize(*args) ⇒ CLI

Returns a new instance of CLI.



13
14
15
16
# File 'lib/devproxy/cli.rb', line 13

def initialize *args
  super(*args)
  initialize_test_server
end

Class Method Details

.create(argv) ⇒ Object



108
109
110
# File 'lib/devproxy/cli.rb', line 108

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

.parse(argv) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/devproxy/cli.rb', line 50

def self.parse(argv)
  options = 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

  opts.on "--test-server", "Launch local server for testing" do |x|
    options.test = true
  end

  opts.on "-v", "--verbose",
          "Verbose output (default: #{options.verbose})" do |x|
    options.verbose = true
  end

  if ENV['DEVPROXY_DEVELOPMENT']
    opts.on "-l ADDRESS", "--listen ADDRESS",
            "Local address to listen on (default: #{options.listen})" do |x|
      options.listen = x
    end
    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

Instance Method Details

#loop!Object



18
19
20
21
# File 'lib/devproxy/cli.rb', line 18

def loop!
  start_test_server
  super
end

#stop!Object



23
24
25
26
# File 'lib/devproxy/cli.rb', line 23

def stop!
  stop_test_server
  super
end