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 <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2021-03-01 12:43:00 -03:00
parent bc234bdcdf
commit 98bb20f2d1
1 changed files with 14 additions and 0 deletions

View File

@ -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"