Top Level Namespace

Defined Under Namespace

Modules: Envoy

Constant Summary collapse

TRACE =
5
DEBUG =
4
INFO =
3
WARN =
2
ERROR =
1
FATAL =
0

Instance Method Summary collapse

Instance Method Details

#default_optionsObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/envoy/client/option_parser.rb', line 3

def default_options
  {
    "server_host" => 'p45.eu',
    "server_port" => "8282",
    "local_host" => '127.0.0.1',
    "tls" => false,
    "verbosity" => 3,
    "version" => Envoy::VERSION,
    "delay" => 1,
    "dir" => ".",
    "timestamps" => false,
    "show_log_level" => true,
    "color_log_level" => true,
  }
end

#find_configObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/envoy/client/command.rb', line 6

def find_config
  dirs = Dir.pwd.split("/")
  r = dirs.reduce([]) do |m, x|
    [[*m[0], x], *m]
  end.map do |p|
    p.join("/") + "/.envoy"
  end.each do |p|
    return p if File.exist?(p)
  end
  false
end

#load_configObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/envoy/client/command.rb', line 18

def load_config
  if path = find_config
    conf = YAML.load(File.read(path))
    Array(conf).each do |conf|
      if conf["rails"]
        conf["dir"] = conf["rails"]
        conf["pidfile"] = "tmp/pids/server.pid"
        conf["command"] = "rails s -p %{local_port}"
        conf["delay"] = 10
      elsif conf["rackup"]
        conf["dir"] = conf["rackup"]
        conf["command"] = "rackup -p %{local_port}"
        conf["delay"] = 10
      end
      conf["host"] ||= conf["dir"].split("/")[-1] if conf["dir"]
      conf["dir"] = File.expand_path(conf["dir"], path + "/..") if conf["dir"]
    end
  else
    [{}]
  end
end

#parse_optionsObject



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
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
# File 'lib/envoy/client/option_parser.rb', line 19

def parse_options
  options = default_options
  OptionParser.new do |op|
    op.banner = "Usage: #{$0} [options] [[HOST:]PORT] [LABEL]"
    op.on "-l LABEL", "--label", "--host", "Allocate this domain label on the proxy" do |v|
      options["hosts"] ||= []
      options["hosts"] << v
    end
    op.on "-k KEY", "--key", "Secure access to the label with this key" do |v|
      options["key"] = v
    end
    op.on "-s SERVER", "--server", "Specify envoy server" do |v|
      host, port = v.split(":")
      options["server_host"] = host
      options["server_port"] ||= port
    end
    op.on "-c COMMAND", "Run this command" do |v|
      options["command"] = v
    end
    op.on "-v", "--verbose", "Show messages. Repeat to show more." do
      options["verbosity"] += 1
    end
    op.on "-q", "--quiet", "Hide messages. Repeat to hide more." do
      options["verbosity"] -= 1
    end
    op.on "-h", "--help", "Show this message" do
      puts op
      exit
    end
    op.on "-V", "--version", "Show version number" do
      puts Envoy::VERSION
      exit
    end
    op.parse!
    case ARGV[0]
    when "rails"
      options["pidfile"] = "tmp/pids/server.pid"
      options["command"] = "rails s -p %{local_port}"
      options["delay"] = 10
    when "rackup"
      options["command"] = "rackup -p %{local_port}"
      options["delay"] = 10
    when /^(\d+)$/
      options["local_port"] = $1
    when /^(\[[^\]+]\]|[^:]+):(\d+)$/x
      options["local_host"] = $1
      options["local_port"] = $2
    when /^(.*)$/
      options["local_host"] = $1
    end
    if ARGV[1]
      options["hosts"] ||= []
      options["hosts"] << ARGV[1]
    end
  end
  options
end