Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 4cbb33e

Browse files
committed
Add support for --log-level
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent b6b2f29 commit 4cbb33e

File tree

6 files changed

+13
-45
lines changed

6 files changed

+13
-45
lines changed

cli/cmd/login/login.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525

2626
"github.com/docker/compose-cli/api/client"
2727
"github.com/docker/compose-cli/api/errdefs"
28-
"github.com/docker/compose-cli/cli/cmd/mobyflags"
2928
"github.com/docker/compose-cli/cli/mobycli"
3029
)
3130

@@ -43,7 +42,6 @@ func Command() *cobra.Command {
4342
flags.StringP("username", "u", "", "username")
4443
flags.StringP("password", "p", "", "password")
4544
flags.BoolP("password-stdin", "", false, "Take the password from stdin")
46-
mobyflags.AddMobyFlagsForRetrocompatibility(flags)
4745

4846
cmd.AddCommand(AzureLoginCommand())
4947
return cmd

cli/cmd/mobyflags/mobyflags.go

Lines changed: 0 additions & 37 deletions
This file was deleted.

cli/cmd/version.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"github.com/spf13/cobra"
2525

26-
"github.com/docker/compose-cli/cli/cmd/mobyflags"
2726
"github.com/docker/compose-cli/cli/formatter"
2827
"github.com/docker/compose-cli/cli/mobycli"
2928
"github.com/docker/compose-cli/internal"
@@ -45,7 +44,6 @@ func VersionCommand() *cobra.Command {
4544
flags := cmd.Flags()
4645
flags.StringP(formatOpt, "f", "", "Format the output. Values: [pretty | json]. (Default: pretty)")
4746
flags.String("kubeconfig", "", "Kubernetes config file")
48-
mobyflags.AddMobyFlagsForRetrocompatibility(flags)
4947

5048
return cmd
5149
}

cli/main.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ func main() {
146146
helpFunc(cmd, args)
147147
})
148148

149+
root.PersistentFlags().StringVarP(&opts.LogLevel, "log-level", "l", "info", "Set the logging level (\"debug\"|\"info\"|\"warn\"|\"error\"|\"fatal\")")
149150
root.PersistentFlags().BoolVarP(&opts.Debug, "debug", "D", false, "Enable debug output in the logs")
150151
root.PersistentFlags().StringVarP(&opts.Host, "host", "H", "", "Daemon socket(s) to connect to")
151152
opts.AddContextFlags(root.PersistentFlags())
@@ -159,6 +160,13 @@ func main() {
159160
// populate the opts with the global flags
160161
_ = root.PersistentFlags().Parse(os.Args[1:])
161162
_ = root.Flags().Parse(os.Args[1:])
163+
164+
level, err := logrus.ParseLevel(opts.LogLevel)
165+
if err != nil {
166+
fmt.Fprintf(os.Stderr, "Unable to parse logging level: %s\n", opts.LogLevel)
167+
os.Exit(1)
168+
}
169+
logrus.SetLevel(level)
162170
if opts.Debug {
163171
logrus.SetLevel(logrus.DebugLevel)
164172
}

cli/options/options.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import (
2525
type GlobalOpts struct {
2626
apicontext.ContextFlags
2727
cliconfig.ConfigFlags
28-
Debug bool
29-
Version bool
30-
Host string
28+
Debug bool
29+
LogLevel string
30+
Version bool
31+
Host string
3132
}

local/e2e/cli-only/e2e_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ func TestLegacyLogin(t *testing.T) {
453453

454454
t.Run("login help global flags", func(t *testing.T) {
455455
res := c.RunDockerCmd("login", "--help")
456-
assert.Assert(t, !strings.Contains(res.Combined(), "--log-level"))
456+
assert.Assert(t, strings.Contains(res.Combined(), "--log-level"))
457457
})
458458
}
459459

0 commit comments

Comments
 (0)