Skip to content

Commit

Permalink
fix: added proper help output to gouroboros command
Browse files Browse the repository at this point in the history
  • Loading branch information
rakshasa committed Feb 13, 2024
1 parent 5c8e061 commit f63b504
Showing 1 changed file with 30 additions and 18 deletions.
48 changes: 30 additions & 18 deletions cmd/gouroboros/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"net"
"os"

"github.com/blinklabs-io/gouroboros"
ouroboros "github.com/blinklabs-io/gouroboros"
)

type globalFlags struct {
Expand Down Expand Up @@ -89,26 +89,38 @@ func main() {
f.networkMagic = int(network.NetworkMagic)
}

if len(f.flagset.Args()) > 0 {
switch f.flagset.Arg(0) {
case "chain-sync":
testChainSync(f)
case "local-tx-submission":
testLocalTxSubmission(f)
case "server":
testServer(f)
case "query":
testQuery(f)
case "mem-usage":
testMemUsage(f)
default:
fmt.Printf("Unknown subcommand: %s\n", f.flagset.Arg(0))
os.Exit(1)
subcommands := map[string]func(*globalFlags){
"chain-sync": testChainSync,
"local-tx-submission": testLocalTxSubmission,
"server": testServer,
"query": testQuery,
"mem-usage": testMemUsage,
}

if len(f.flagset.Args()) == 0 {
fmt.Printf("\n")
fmt.Printf("Usage of gouroboros:\n")
fmt.Printf("\n")
fmt.Printf("Commands:\n")

for k := range subcommands {
fmt.Printf(" %s\n", k)
}
} else {
fmt.Printf("You must specify a subcommand (chain-sync or local-tx-submission)\n")

fmt.Printf("\n")
fmt.Printf("Global flags:\n")
f.flagset.PrintDefaults()

os.Exit(1)
}

fn, ok := subcommands[f.flagset.Arg(0)]
if !ok {
fmt.Printf("Unknown subcommand: %s\n", f.flagset.Arg(0))
os.Exit(1)
}

fn(f)
}

func createClientConnection(f *globalFlags) net.Conn {
Expand Down

0 comments on commit f63b504

Please sign in to comment.