Skip to content

Commit 60eb023

Browse files
avoid redeclaring --type flag on logs cmd (#871)
1 parent 1eaf090 commit 60eb023

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/cmd/cli/command/compose.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ func makeComposeLogsCmd() *cobra.Command {
381381
if !cmd.Flags().Changed("verbose") {
382382
verbose = true // default verbose for explicit tail command
383383
}
384-
var logType logs.LogType
385-
cmd.Flags().Var(&logType, "type", fmt.Sprintf(`show logs of type; one of %v`, logs.AllLogTypes))
384+
logType := cmd.Flag("type").Value.(*logs.LogType) // nolint:forcetypeassert
386385

387386
if utc {
388387
os.Setenv("TZ", "") // used by Go's "time" package, see https://pkg.go.dev/time#Location
@@ -404,8 +403,8 @@ func makeComposeLogsCmd() *cobra.Command {
404403
services = strings.Split(name, ",")
405404
}
406405

407-
if logType == logs.LogTypeUnspecified {
408-
logType = logs.LogTypeRun
406+
if *logType == logs.LogTypeUnspecified {
407+
*logType = logs.LogTypeRun
409408
}
410409

411410
term.Debug("logType", logType)
@@ -416,7 +415,7 @@ func makeComposeLogsCmd() *cobra.Command {
416415
Since: ts,
417416
Raw: raw,
418417
Verbose: verbose,
419-
LogType: logType,
418+
LogType: *logType,
420419
}
421420

422421
loader := configureLoader(cmd)

src/cmd/cli/command/compose_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@ import (
66
"github.com/compose-spec/compose-go/v2/types"
77
)
88

9+
func TestInitializeTailCmd(t *testing.T) {
10+
t.Run("", func(t *testing.T) {
11+
for _, cmd := range RootCmd.Commands() {
12+
if cmd.Use == "logs" {
13+
cmd.Execute()
14+
return
15+
}
16+
}
17+
})
18+
}
19+
920
func TestGetUnreferencedManagedResources(t *testing.T) {
1021
t.Run("no services", func(t *testing.T) {
1122
project := types.Services{}

0 commit comments

Comments
 (0)