From 45750fe104ea94976798d42afd24abe484164a0b Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 19 Jun 2020 12:21:31 +0200 Subject: [PATCH 1/3] =?UTF-8?q?Do=20not=20display=20=E2=80=9Cdocker=20for?= =?UTF-8?q?=20the=202020s=E2=80=9D=20as=20the=20first=20help=20line=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/main.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cli/main.go b/cli/main.go index da02c0708..54c94d8c1 100644 --- a/cli/main.go +++ b/cli/main.go @@ -85,7 +85,6 @@ func main() { var opts cliopts.GlobalOpts root := &cobra.Command{ Use: "docker", - Long: "docker for the 2020s", SilenceErrors: true, SilenceUsage: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { From dbaab41604d0cabd89094e9d2b6e4a5131426c98 Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Mon, 22 Jun 2020 13:11:08 +0200 Subject: [PATCH 2/3] =?UTF-8?q?Changed=20root=20level=20debug=20shorthand?= =?UTF-8?q?=20to=20capital=20D,=20make=20it=20consistent=20with=20Moby=20f?= =?UTF-8?q?lag=20and=20not=20clash=20with=20=E2=80=94detach=20future=20opt?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/main.go b/cli/main.go index 54c94d8c1..792d921a5 100644 --- a/cli/main.go +++ b/cli/main.go @@ -120,7 +120,7 @@ func main() { helpFunc(cmd, args) }) - root.PersistentFlags().BoolVarP(&opts.Debug, "debug", "d", false, "enable debug output in the logs") + root.PersistentFlags().BoolVarP(&opts.Debug, "debug", "D", false, "enable debug output in the logs") opts.AddConfigFlags(root.PersistentFlags()) opts.AddContextFlags(root.PersistentFlags()) From c3924f2e8e701f006b25498d96a387da6200a93f Mon Sep 17 00:00:00 2001 From: Guillaume Tardif Date: Fri, 19 Jun 2020 22:35:39 +0200 Subject: [PATCH 3/3] =?UTF-8?q?Add=20-H=20flag=20to=20our=20own=20version?= =?UTF-8?q?=20command=20&=20login=20command,=20&=20also=20=E2=80=94-log-le?= =?UTF-8?q?vel=20(-l)=20flag.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cli/cmd/login/login.go | 3 +++ cli/cmd/mobyflags/mobyflags.go | 24 ++++++++++++++++++++++++ cli/cmd/version.go | 2 ++ tests/e2e/e2e_test.go | 17 +++++++++++++++++ 4 files changed, 46 insertions(+) create mode 100644 cli/cmd/mobyflags/mobyflags.go diff --git a/cli/cmd/login/login.go b/cli/cmd/login/login.go index ee5439b26..1cff03ac3 100644 --- a/cli/cmd/login/login.go +++ b/cli/cmd/login/login.go @@ -21,6 +21,8 @@ import ( "fmt" "strings" + "github.com/docker/api/cli/cmd/mobyflags" + "github.com/pkg/errors" "github.com/spf13/cobra" @@ -43,6 +45,7 @@ func Command() *cobra.Command { flags.StringP("username", "u", "", "Username") flags.StringP("password", "p", "", "Password") flags.BoolP("password-stdin", "", false, "Take the password from stdin") + mobyflags.AddMobyFlagsForRetrocompatibility(flags) return cmd } diff --git a/cli/cmd/mobyflags/mobyflags.go b/cli/cmd/mobyflags/mobyflags.go new file mode 100644 index 000000000..b094ef537 --- /dev/null +++ b/cli/cmd/mobyflags/mobyflags.go @@ -0,0 +1,24 @@ +package mobyflags + +import ( + "log" + + flag "github.com/spf13/pflag" +) + +// AddMobyFlagsForRetrocompatibility adds retrocompatibility flags to our commands +func AddMobyFlagsForRetrocompatibility(flags *flag.FlagSet) { + const hostFlag = "host" + flags.StringP(hostFlag, "H", "", "Daemon socket(s) to connect to") + markHidden(flags, hostFlag) + const logLevelFlag = "log-level" + flags.StringP(logLevelFlag, "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`) + markHidden(flags, logLevelFlag) +} + +func markHidden(flags *flag.FlagSet, flagName string) { + err := flags.MarkHidden(flagName) + if err != nil { + log.Fatal(err) + } +} diff --git a/cli/cmd/version.go b/cli/cmd/version.go index 58cebf7ce..515f726fc 100644 --- a/cli/cmd/version.go +++ b/cli/cmd/version.go @@ -22,6 +22,7 @@ import ( "github.com/spf13/cobra" + "github.com/docker/api/cli/cmd/mobyflags" "github.com/docker/api/cli/mobycli" ) @@ -39,6 +40,7 @@ func VersionCommand() *cobra.Command { flags := cmd.Flags() flags.String("format", "", "Format the output using the given Go template") flags.String("kubeconfig", "", "Kubernetes config file") + mobyflags.AddMobyFlagsForRetrocompatibility(flags) return cmd } diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index 2519aa7dc..c052893c7 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -173,6 +173,23 @@ func (s *E2eSuite) TestLeaveLegacyErrorMessagesUnchanged() { Expect(err).NotTo(BeNil()) } +func (s *E2eSuite) TestPassThroughRootLegacyFlags() { + output, err := s.NewDockerCommand("-H", "tcp://localhost:123", "version").Exec() + Expect(err).To(BeNil()) + Expect(output).To(ContainSubstring("Client:")) + Expect(output).To(ContainSubstring("localhost:123")) + + output, _ = s.NewDockerCommand("-H", "tcp://localhost:123", "login", "-u", "nouser", "-p", "wrongpasword").Exec() + Expect(output).To(ContainSubstring("WARNING! Using --password via the CLI is insecure")) + + output, _ = s.NewDockerCommand("--log-level", "debug", "login", "-u", "nouser", "-p", "wrongpasword").Exec() + Expect(output).To(ContainSubstring("WARNING! Using --password via the CLI is insecure")) + + output, _ = s.NewDockerCommand("login", "--help").Exec() + Expect(output).NotTo(ContainSubstring("--host")) + Expect(output).NotTo(ContainSubstring("--log-level")) +} + func (s *E2eSuite) TestDisplayFriendlyErrorMessageForLegacyCommands() { s.NewDockerCommand("context", "create", "example", "test-example").ExecOrDie() output, err := s.NewDockerCommand("--context", "test-example", "images").Exec()