From 036366a8751290316cb3fb50f3465aaa87a25d34 Mon Sep 17 00:00:00 2001 From: Rob Watson Date: Tue, 1 Apr 2025 15:59:30 +0200 Subject: [PATCH] chore: improve CLI help message --- main.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 0823112..a66bd53 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "cmp" "context" "flag" "fmt" @@ -54,8 +55,7 @@ func run(ctx context.Context) error { case "version": return printVersion() case "help", "-h", "--help": - // TODO: improve help message - flag.Usage() + printUsage() return nil } } @@ -133,10 +133,22 @@ func printConfigPath(configPath string) error { // printVersion prints the version of the application to stderr. func printVersion() error { - fmt.Fprintf(os.Stderr, "%s version %s\n", domain.AppName, "0.0.0") + fmt.Fprintf(os.Stderr, "%s version %s\n", domain.AppName, cmp.Or(version, "0.0.0-dev")) return nil } +func printUsage() { + os.Stderr.WriteString("Usage: octoplex [command]\n\n") + os.Stderr.WriteString("Commands:\n\n") + os.Stderr.WriteString(" edit-config Edit the config file\n") + os.Stderr.WriteString(" print-config Print the path to the config file\n") + os.Stderr.WriteString(" version Print the version of the application\n") + os.Stderr.WriteString(" help Print this help message\n") + os.Stderr.WriteString("\n") + os.Stderr.WriteString("Additionally, Octoplex can be configured with the following environment variables:\n\n") + os.Stderr.WriteString(" OCTO_DEBUG Enables debug logging if set\n") +} + // buildLogger builds the logger, which may be a no-op logger. func buildLogger(cfg config.LogFile) (*slog.Logger, error) { if !cfg.Enabled {