fix cli style
This commit is contained in:
+17
-9
@@ -4,25 +4,33 @@ import "core:fmt"
|
||||
import "core:net"
|
||||
import "core:os"
|
||||
|
||||
USAGE :: `usage: hanabi (-c[onnect]:<server-ip:port> | -h[ost]:<p1> <p2> [p3] [p4] [p5])
|
||||
USAGE :: `usage: hanabi (-c[onnect] <p0> | -h[ost] <p1> <p2> [p3] [p4] [p5])
|
||||
where px is of the form ip:port
|
||||
|
||||
example host: \
|
||||
example host:
|
||||
$ hanabi -h 127.0.0.1:42069 127.0.0.1:42070
|
||||
|
||||
example player: \
|
||||
$ hanabi -c 127.0.0.1:42069`
|
||||
example player 1:
|
||||
$ hanabi -c 127.0.0.1:42069
|
||||
|
||||
example player 2:
|
||||
$ hanabi -c 127.0.0.1:42070`
|
||||
|
||||
|
||||
main :: proc() {
|
||||
n := len(os.args) - 2
|
||||
ok := false
|
||||
N := len(os.args) - 2
|
||||
defer if !ok do fmt.println(USAGE)
|
||||
if N <= 0 do return
|
||||
|
||||
switch os.args[1] {
|
||||
case "-c", "-connect", "--connect":
|
||||
assert(n == 1)
|
||||
if N != 1 do return
|
||||
addr, ok := net.parse_endpoint(os.args[2])
|
||||
if !ok do panic(fmt.tprintln("failed to parse host endpoint:", os.args[2]))
|
||||
run_client(addr)
|
||||
case "-H", "-host", "--host":
|
||||
assert(2 <= n && n <= 5)
|
||||
case "-h", "-host", "--host":
|
||||
if !(2 <= N && N <= 5) do return
|
||||
addrs: [dynamic]net.Endpoint
|
||||
defer delete(addrs)
|
||||
for addr_str in os.args[2:] {
|
||||
@@ -32,8 +40,8 @@ main :: proc() {
|
||||
}
|
||||
run_server(addrs[:])
|
||||
case:
|
||||
fmt.println(USAGE)
|
||||
return
|
||||
}
|
||||
ok = true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user