Skip to content

Commit d5f9824

Browse files
authored
Newest log (without redirect info message about cli tools) and linter induced updates (#50)
* Newest log (without redirect info message about cli tools) and linter updates * more linter fixes
1 parent dc07dfa commit d5f9824

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

ca_bundle.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// See LICENSE
55

66
//go:build !no_tls_fallback && !no_net
7-
// +build !no_tls_fallback,!no_net
87

98
package cli // import "fortio.org/cli"
109

cli.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,44 @@ import (
3030
// These variables is how to setup the arguments, flags and usage parsing for [Main] and [ServerMain].
3131
// At minimum the MinArgs should be set.
3232
var (
33-
// Out parameters:
33+
// Out parameters.
34+
35+
// ShortVersion is x.y.z from tag/install.
3436
// *Version will be filled automatically by the cli package, using [fortio.org/version.FromBuildInfo()].
35-
ShortVersion string // x.y.z from tag/install
36-
LongVersion string // version plus go version plus OS/arch
37-
FullVersion string // LongVersion plus build date and git sha
38-
Command string // first argument, if [CommandBeforeFlags] is true.
37+
ShortVersion string
38+
// LongVersion is ShortVersion plus go version plus OS/arch.
39+
LongVersion string
40+
// FullVersion is LongVersion plus build date and git sha and all the module versions.
41+
FullVersion string
42+
// Command is the first argument, if [CommandBeforeFlags] is true.
43+
Command string
44+
3945
// Following can/should be specified.
40-
ProgramName string // Used at the beginning of Usage()
41-
// Optional for programs using subcommand, command will be set in [Command].
46+
47+
// ProgramName is used at the beginning of Usage() and can/should be specified.
48+
ProgramName string
49+
// CommandBeforeFlags is optional for programs using subcommand, command will be set in [Command].
4250
// If you wish to replace the help default colorize `command` with something else set CommandHelp.
4351
CommandBeforeFlags bool
44-
// Cli usage/arguments example, ie "url1..." program name and "[flags]" will be added"
52+
// ArgsHelp is cli usage/arguments example, ie "url1..." program name and "[flags]" will be added"
4553
// can include \n for additional details in the Usage() before the flags are dumped.
4654
ArgsHelp string
47-
// Command help will be used instead of purple "command " in help text for cli that have a
55+
// CommandHelp will be used instead of purple "command " in help text for cli that have a
4856
// command before the flags (when [CommandBeforeFlags] is true). For instance you could use
4957
// cli.CommandHelp = "{" + cli.ColorJoin(log.Colors.Purple, "a", "b", "c") + "}"
5058
// for colorize {a|b|c} in the help before [flags].
5159
CommandHelp string
5260
MinArgs int // Minimum number of arguments expected, not counting (optional) command.
5361
MaxArgs int // Maximum number of arguments expected. 0 means same as MinArgs. -1 means no limit.
54-
// If not set to true, will setup static loglevel flag and logger output for client tools.
62+
// ServerMode if not set to true, will setup static loglevel flag and logger output for client tools.
5563
ServerMode = false
56-
// Override this to change the exit function (for testing), will be applied to log.Fatalf too.
64+
// ExitFunction can be overridden to change the exit function (for testing), will be applied to log.Fatalf too.
5765
ExitFunction = os.Exit
58-
// Hook to call before flag.Parse() - for instance to use ChangeFlagDefaults for logger flags etc.
66+
// BeforeFlagParseHook is a hook to call before flag.Parse() - for instance to use ChangeFlagDefaults for logger flags etc.
5967
BeforeFlagParseHook = func() {}
6068
// Calculated base exe name from args (will be used if ProgramName if not set).
6169
baseExe string
62-
// List of functions to call for env help.
70+
// EnvHelpFuncs is a list of functions to call for env help.
6371
EnvHelpFuncs = []func(w io.Writer){log.EnvHelp}
6472
)
6573

@@ -146,9 +154,11 @@ func Main() { //nolint: funlen // just over 70 lines
146154
MaxArgs = MinArgs
147155
}
148156
if ArgsHelp == "" {
157+
var sb strings.Builder
149158
for i := 1; i <= MinArgs; i++ {
150-
ArgsHelp += fmt.Sprintf(" arg%d", i)
159+
sb.WriteString(fmt.Sprintf(" arg%d", i))
151160
}
161+
ArgsHelp += sb.String()
152162
if MaxArgs < 0 {
153163
ArgsHelp += " ..."
154164
} else if MaxArgs > MinArgs {
@@ -235,7 +245,7 @@ func errArgCount(prefix string, expected, actual int) {
235245
ErrUsage("%s %d %s expected, got %d", prefix, expected, Plural(expected, "argument"), actual)
236246
}
237247

238-
// Show usage and error message on stderr and calls [ExitFunction] with code 1.
248+
// ErrUsage shows usage and error message on stderr and calls [ExitFunction] with code 1.
239249
func ErrUsage(msg string, args ...any) {
240250
usage(os.Stderr, log.Colors.BrightRed+msg+log.Colors.Reset, args...)
241251
ExitFunction(1)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.20
44

55
require (
66
fortio.org/duration v1.0.4
7-
fortio.org/log v1.18.1
7+
fortio.org/log v1.18.3
88
fortio.org/version v1.0.4
99
golang.org/x/crypto/x509roots/fallback v0.0.0-20250203165127-fa5273e46196
1010
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
fortio.org/duration v1.0.4 h1:TB07ng4UsMZPDRujJRkTJIcNqMTLM283zob10nb9K24=
22
fortio.org/duration v1.0.4/go.mod h1:RuBVqdcCKRwMmI8WIdVq8kd7ngQPCIe6G7AU0NC0XDw=
3-
fortio.org/log v1.18.1 h1:rqzz/57dGhDg3GAn5yQxVgh5JPQE1OAnNGS58S6dQOI=
4-
fortio.org/log v1.18.1/go.mod h1:vqpyEZd/TP4xO5eAHQaa4buDZDCn1AxCAV+wl3eaTec=
3+
fortio.org/log v1.18.3 h1:2kwEUise3faY4OouueQ/1tC+75Y2YGJjJaX2/ECmu4I=
4+
fortio.org/log v1.18.3/go.mod h1:vqpyEZd/TP4xO5eAHQaa4buDZDCn1AxCAV+wl3eaTec=
55
fortio.org/struct2env v0.4.2 h1:Xh7HlS9vf2ZdRvRfmoGIasNDO8t6z36M713utVODRCo=
66
fortio.org/struct2env v0.4.2/go.mod h1:lENUe70UwA1zDUCX+8AsO663QCFqYaprk5lnPhjD410=
77
fortio.org/version v1.0.4 h1:FWUMpJ+hVTNc4RhvvOJzb0xesrlRmG/a+D6bjbQ4+5U=

0 commit comments

Comments
 (0)