Skip to content

Commit

Permalink
update to v0.1.3 with cli flags
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmittag committed May 24, 2023
1 parent 3d054b3 commit a9b95ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
35 changes: 29 additions & 6 deletions cmd/pwt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,46 @@ import (
const default_host = "localhost"
const default_port = 80

type Mode uint8

const (
Server Mode = 1 << iota
Version
Usage
)

func main() {
flag.Usage = pwtUsage
mode := Server

timeSeconds := flag.Int("w", 10, "time wait in seconds")
modeVersion := flag.Bool("v", false, "print pwt version")
v := flag.Bool("v", false, "print pwt version")
h := flag.Bool("h", false, "print usage instructions")
flag.Usage = printUsage
flag.Parse()

host, port := parseArgs(flag.Args())

if *modeVersion {
printVersion()
if *v {
mode = Version
} else if *h {
mode = Usage
} else {
mode = Server
}

switch mode {
case Server:
wait(host, port, *timeSeconds)
case Usage:
printUsage()
case Version:
printVersion()
}
}

func pwtUsage() {
fmt.Fprintf(os.Stdout, "Usage: pwt [-v]|[-w n] host[:port]\n")
func printUsage() {
printVersion()
fmt.Printf("Usage: pwt [-v]|[-w n] host[:port]\n")
flag.PrintDefaults()
}

Expand Down
2 changes: 1 addition & 1 deletion pwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"time"
)

const Version string = "v0.1.2"
const Version string = "v0.1.3"

var dialler = &net.Dialer{
Timeout: 1 * time.Second,
Expand Down

0 comments on commit a9b95ca

Please sign in to comment.