get-port has a proper CLI.
parent
e4741daeb3
commit
bf2075be9e
|
@ -1,11 +1,33 @@
|
||||||
require "file_utils"
|
require "file_utils"
|
||||||
|
require "option_parser"
|
||||||
|
|
||||||
require "./config.cr"
|
require "./config.cr"
|
||||||
|
|
||||||
START_PORT = 49152
|
START_PORT = 49152
|
||||||
PORTS_CACHE_DIRECTORY = "#{CACHE_DIRECTORY}/ports/"
|
PORTS_CACHE_DIRECTORY = "#{CACHE_DIRECTORY}/ports/"
|
||||||
|
|
||||||
service = ARGV[0]
|
service = ""
|
||||||
wanted_default_port = ARGV[1]?.try &.to_i
|
wanted_default_port : String? = nil
|
||||||
|
|
||||||
|
parser = OptionParser.parse do |parser|
|
||||||
|
parser.banner = "usage: get-post <id> [default-port] [options]\n" +
|
||||||
|
"options:\n"
|
||||||
|
|
||||||
|
parser.on "-h", "--help", "Prints this help message." do
|
||||||
|
puts parser
|
||||||
|
exit 0
|
||||||
|
end
|
||||||
|
|
||||||
|
parser.unknown_args do |arg|
|
||||||
|
if arg.size < 1 || arg.size > 2
|
||||||
|
puts parser
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
|
service = arg[0]
|
||||||
|
wanted_default_port = arg[1]?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
service_port_file = "#{PORTS_CACHE_DIRECTORY}/#{service.gsub /\//, ":"}"
|
service_port_file = "#{PORTS_CACHE_DIRECTORY}/#{service.gsub /\//, ":"}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue