From a6aca4db9701e832bbbdce0c0dc361e001df0a0b Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Mon, 10 Nov 2025 13:45:28 -0800 Subject: [PATCH 1/2] Newest log (without redirect info message about cli tools) and linter updates --- ca_bundle.go | 1 - cli.go | 4 +++- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ca_bundle.go b/ca_bundle.go index e6942e4..d9b8cca 100644 --- a/ca_bundle.go +++ b/ca_bundle.go @@ -4,7 +4,6 @@ // See LICENSE //go:build !no_tls_fallback && !no_net -// +build !no_tls_fallback,!no_net package cli // import "fortio.org/cli" diff --git a/cli.go b/cli.go index fbd9377..65a637e 100644 --- a/cli.go +++ b/cli.go @@ -146,9 +146,11 @@ func Main() { //nolint: funlen // just over 70 lines MaxArgs = MinArgs } if ArgsHelp == "" { + var sb strings.Builder for i := 1; i <= MinArgs; i++ { - ArgsHelp += fmt.Sprintf(" arg%d", i) + sb.WriteString(fmt.Sprintf(" arg%d", i)) } + ArgsHelp += sb.String() if MaxArgs < 0 { ArgsHelp += " ..." } else if MaxArgs > MinArgs { diff --git a/go.mod b/go.mod index 1bac755..5ff84c9 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.20 require ( fortio.org/duration v1.0.4 - fortio.org/log v1.18.1 + fortio.org/log v1.18.3 fortio.org/version v1.0.4 golang.org/x/crypto/x509roots/fallback v0.0.0-20250203165127-fa5273e46196 ) diff --git a/go.sum b/go.sum index f1160fa..7dcdd79 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ fortio.org/duration v1.0.4 h1:TB07ng4UsMZPDRujJRkTJIcNqMTLM283zob10nb9K24= fortio.org/duration v1.0.4/go.mod h1:RuBVqdcCKRwMmI8WIdVq8kd7ngQPCIe6G7AU0NC0XDw= -fortio.org/log v1.18.1 h1:rqzz/57dGhDg3GAn5yQxVgh5JPQE1OAnNGS58S6dQOI= -fortio.org/log v1.18.1/go.mod h1:vqpyEZd/TP4xO5eAHQaa4buDZDCn1AxCAV+wl3eaTec= +fortio.org/log v1.18.3 h1:2kwEUise3faY4OouueQ/1tC+75Y2YGJjJaX2/ECmu4I= +fortio.org/log v1.18.3/go.mod h1:vqpyEZd/TP4xO5eAHQaa4buDZDCn1AxCAV+wl3eaTec= fortio.org/struct2env v0.4.2 h1:Xh7HlS9vf2ZdRvRfmoGIasNDO8t6z36M713utVODRCo= fortio.org/struct2env v0.4.2/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410= fortio.org/version v1.0.4 h1:FWUMpJ+hVTNc4RhvvOJzb0xesrlRmG/a+D6bjbQ4+5U= From 9ebf4ce953363f2fafce5d43fa08d2059cbdc3a3 Mon Sep 17 00:00:00 2001 From: Laurent Demailly Date: Mon, 10 Nov 2025 14:06:27 -0800 Subject: [PATCH 2/2] more linter fixes --- cli.go | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/cli.go b/cli.go index 65a637e..dbc884c 100644 --- a/cli.go +++ b/cli.go @@ -30,36 +30,44 @@ import ( // These variables is how to setup the arguments, flags and usage parsing for [Main] and [ServerMain]. // At minimum the MinArgs should be set. var ( - // Out parameters: + // Out parameters. + + // ShortVersion is x.y.z from tag/install. // *Version will be filled automatically by the cli package, using [fortio.org/version.FromBuildInfo()]. - ShortVersion string // x.y.z from tag/install - LongVersion string // version plus go version plus OS/arch - FullVersion string // LongVersion plus build date and git sha - Command string // first argument, if [CommandBeforeFlags] is true. + ShortVersion string + // LongVersion is ShortVersion plus go version plus OS/arch. + LongVersion string + // FullVersion is LongVersion plus build date and git sha and all the module versions. + FullVersion string + // Command is the first argument, if [CommandBeforeFlags] is true. + Command string + // Following can/should be specified. - ProgramName string // Used at the beginning of Usage() - // Optional for programs using subcommand, command will be set in [Command]. + + // ProgramName is used at the beginning of Usage() and can/should be specified. + ProgramName string + // CommandBeforeFlags is optional for programs using subcommand, command will be set in [Command]. // If you wish to replace the help default colorize `command` with something else set CommandHelp. CommandBeforeFlags bool - // Cli usage/arguments example, ie "url1..." program name and "[flags]" will be added" + // ArgsHelp is cli usage/arguments example, ie "url1..." program name and "[flags]" will be added" // can include \n for additional details in the Usage() before the flags are dumped. ArgsHelp string - // Command help will be used instead of purple "command " in help text for cli that have a + // CommandHelp will be used instead of purple "command " in help text for cli that have a // command before the flags (when [CommandBeforeFlags] is true). For instance you could use // cli.CommandHelp = "{" + cli.ColorJoin(log.Colors.Purple, "a", "b", "c") + "}" // for colorize {a|b|c} in the help before [flags]. CommandHelp string MinArgs int // Minimum number of arguments expected, not counting (optional) command. MaxArgs int // Maximum number of arguments expected. 0 means same as MinArgs. -1 means no limit. - // If not set to true, will setup static loglevel flag and logger output for client tools. + // ServerMode if not set to true, will setup static loglevel flag and logger output for client tools. ServerMode = false - // Override this to change the exit function (for testing), will be applied to log.Fatalf too. + // ExitFunction can be overridden to change the exit function (for testing), will be applied to log.Fatalf too. ExitFunction = os.Exit - // Hook to call before flag.Parse() - for instance to use ChangeFlagDefaults for logger flags etc. + // BeforeFlagParseHook is a hook to call before flag.Parse() - for instance to use ChangeFlagDefaults for logger flags etc. BeforeFlagParseHook = func() {} // Calculated base exe name from args (will be used if ProgramName if not set). baseExe string - // List of functions to call for env help. + // EnvHelpFuncs is a list of functions to call for env help. EnvHelpFuncs = []func(w io.Writer){log.EnvHelp} ) @@ -237,7 +245,7 @@ func errArgCount(prefix string, expected, actual int) { ErrUsage("%s %d %s expected, got %d", prefix, expected, Plural(expected, "argument"), actual) } -// Show usage and error message on stderr and calls [ExitFunction] with code 1. +// ErrUsage shows usage and error message on stderr and calls [ExitFunction] with code 1. func ErrUsage(msg string, args ...any) { usage(os.Stderr, log.Colors.BrightRed+msg+log.Colors.Reset, args...) ExitFunction(1)