Skip to content

Commit f63b504

Browse files
committed
fix: added proper help output to gouroboros command
1 parent 5c8e061 commit f63b504

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

cmd/gouroboros/main.go

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"net"
2222
"os"
2323

24-
"github.com/blinklabs-io/gouroboros"
24+
ouroboros "github.com/blinklabs-io/gouroboros"
2525
)
2626

2727
type globalFlags struct {
@@ -89,26 +89,38 @@ func main() {
8989
f.networkMagic = int(network.NetworkMagic)
9090
}
9191

92-
if len(f.flagset.Args()) > 0 {
93-
switch f.flagset.Arg(0) {
94-
case "chain-sync":
95-
testChainSync(f)
96-
case "local-tx-submission":
97-
testLocalTxSubmission(f)
98-
case "server":
99-
testServer(f)
100-
case "query":
101-
testQuery(f)
102-
case "mem-usage":
103-
testMemUsage(f)
104-
default:
105-
fmt.Printf("Unknown subcommand: %s\n", f.flagset.Arg(0))
106-
os.Exit(1)
92+
subcommands := map[string]func(*globalFlags){
93+
"chain-sync": testChainSync,
94+
"local-tx-submission": testLocalTxSubmission,
95+
"server": testServer,
96+
"query": testQuery,
97+
"mem-usage": testMemUsage,
98+
}
99+
100+
if len(f.flagset.Args()) == 0 {
101+
fmt.Printf("\n")
102+
fmt.Printf("Usage of gouroboros:\n")
103+
fmt.Printf("\n")
104+
fmt.Printf("Commands:\n")
105+
106+
for k := range subcommands {
107+
fmt.Printf(" %s\n", k)
107108
}
108-
} else {
109-
fmt.Printf("You must specify a subcommand (chain-sync or local-tx-submission)\n")
109+
110+
fmt.Printf("\n")
111+
fmt.Printf("Global flags:\n")
112+
f.flagset.PrintDefaults()
113+
110114
os.Exit(1)
111115
}
116+
117+
fn, ok := subcommands[f.flagset.Arg(0)]
118+
if !ok {
119+
fmt.Printf("Unknown subcommand: %s\n", f.flagset.Arg(0))
120+
os.Exit(1)
121+
}
122+
123+
fn(f)
112124
}
113125

114126
func createClientConnection(f *globalFlags) net.Conn {

0 commit comments

Comments
 (0)