Module: Solo::CLI

Defined in:
lib/solo/cli.rb

Class Method Summary collapse

Class Method Details

.call(argv = ARGV) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/solo/cli.rb', line 5

def self.call(argv=ARGV)
  trap("INT") { puts "Shutting down..."; exit; }
  begin
    opts = parse_opts argv
    Solo.call(opts[:port]) do
      system(*argv)
    end
  rescue
    STDERR.puts "#{$!}"
    abort
  end
end

.parse_opts(argv) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/solo/cli.rb', line 17

def self.parse_opts argv
  opts = {}
  opts_parser = OptionParser.new do |parser|
    parser.banner = "Usage: solo --port PORT COMMAND"
    parser.on("-p", "--port [PORT]", Integer, "Set the PORT used to host the server")
  end
  opts_parser.parse!(argv, into: opts)
  unless opts[:port] && opts[:port] > 0 && opts[:port] < 65565
    raise ArgumentError.new("Invalid port: #{opts[:port]} \n#{opts_parser}")
  end
  opts
end