From 98bb20f2d174851962926a2fc41bd2e95fde444a Mon Sep 17 00:00:00 2001 From: Ulysses Souza Date: Mon, 1 Mar 2021 12:43:00 -0300 Subject: [PATCH] Keep --workdir at compose level for retro compatibility This also checks for conflicts with --project-directory at `docker compose` command level Signed-off-by: Ulysses Souza --- cli/cmd/compose/compose.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cli/cmd/compose/compose.go b/cli/cmd/compose/compose.go index ca3921fc9..7f01f8c5e 100644 --- a/cli/cmd/compose/compose.go +++ b/cli/cmd/compose/compose.go @@ -17,8 +17,12 @@ package compose import ( + "fmt" + "github.com/compose-spec/compose-go/cli" "github.com/compose-spec/compose-go/types" + "github.com/morikuni/aec" + "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -32,6 +36,7 @@ type projectOptions struct { ProjectName string Profiles []string ConfigPaths []string + WorkDir string ProjectDir string EnvFile string } @@ -42,6 +47,8 @@ func (o *projectOptions) addProjectFlags(f *pflag.FlagSet) { f.StringArrayVarP(&o.ConfigPaths, "file", "f", []string{}, "Compose configuration files") f.StringVar(&o.EnvFile, "env-file", "", "Specify an alternate environment file.") f.StringVar(&o.ProjectDir, "project-directory", "", "Specify an alternate working directory\n(default: the path of the Compose file)") + f.StringVar(&o.WorkDir, "workdir", "", "DEPRECATED! USE --project-directory INSTEAD.\nSpecify an alternate working directory\n(default: the path of the Compose file)") + _ = f.MarkHidden("workdir") } func (o *projectOptions) toProjectName() (string, error) { @@ -98,6 +105,13 @@ func Command(contextType string) *cobra.Command { Use: "compose", TraverseChildren: true, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { + if opts.WorkDir != "" { + if opts.ProjectDir != "" { + return errors.New(aec.Apply(`cannot specify DEPRECATED "--workdir" and "--project-directory". Please use only "--project-directory" instead.`, aec.RedF)) + } + opts.ProjectDir = opts.WorkDir + fmt.Println(aec.Apply(`option "--workdir" is DEPRECATED at root level! Please use "--project-directory" instead.`, aec.RedF)) + } if contextType == store.DefaultContextType || contextType == store.LocalContextType { Warning = "The new 'docker compose' command is currently experimental. " + "To provide feedback or request new features please open issues at https://github.com/docker/compose-cli"