tune up the help a little bit
Ted Unangst tedu@tedunangst.com
Mon, 11 Mar 2024 02:31:23 -0400
M
cli.go
→
cli.go
@@ -149,10 +149,10 @@ unfollowyou(user, honkerid, true)
}, }, "sendmsg": { - help: "send a message", + help: "send a raw activity", callback: func(args []string) { if len(args) < 4 { - errx("usage: honk send username filename rcpt") + errx("usage: honk sendmsg username filename rcpt") } user, err := butwhatabout(args[1]) if err != nil {@@ -166,7 +166,7 @@ deliverate(user.ID, args[3], data)
}, }, "cleanup": { - help: "clean up? (enter usefull )", + help: "clean up stale data from database", callback: func(args []string) { arg := "30" if len(args) > 1 {@@ -176,7 +176,7 @@ cleanupdb(arg)
}, }, "unplug": { - help: "not sure", + help: "disconnect from a dead server", callback: func(args []string) { if len(args) < 2 { errx("usage: honk unplug servername")
M
main.go
→
main.go
@@ -24,6 +24,8 @@ "log/syslog"
notrand "math/rand" "os" "runtime/pprof" + "sort" + "strings" "time" "humungus.tedunangst.com/r/webs/log"@@ -82,18 +84,28 @@ var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var memprofile = flag.String("memprofile", "", "write memory profile to this file") var memprofilefd *os.File +func usage() { + flag.PrintDefaults() + out := flag.CommandLine.Output() + fmt.Fprintf(out, "\n available honk commands:\n") + var msgs []string + for n, c := range commands { + msgs = append(msgs, fmt.Sprintf(" %s: %s\n", n, c.help)) + } + sort.Strings(msgs) + fmt.Fprintf(out, "%s", strings.Join(msgs, "")) +} + func main() { + commands["help"] = cmd{ + help: "you're looking at it", + callback: func(args []string) { + usage() + }, + } flag.StringVar(&dataDir, "datadir", dataDir, "data directory") flag.StringVar(&viewDir, "viewdir", viewDir, "view directory") - flag.Usage = func() { - flag.PrintDefaults() - helpText := "\n available honk commands:\n" - for n, c := range commands { - helpText += fmt.Sprintf(" %s: %s\n", n, c.help) - } - - fmt.Fprint(flag.CommandLine.Output(), helpText) - } + flag.Usage = usage flag.Parse() if *cpuprofile != "" {