mirror of https://github.com/docker/compose.git
Support option —workingdir, -f, no need to check backend support, unimplemented error is returned by backbends.
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
This commit is contained in:
parent
215f50166a
commit
370781e95e
|
@ -26,8 +26,6 @@ import (
|
||||||
"github.com/docker/compose-cli/api/client"
|
"github.com/docker/compose-cli/api/client"
|
||||||
"github.com/docker/compose-cli/api/compose"
|
"github.com/docker/compose-cli/api/compose"
|
||||||
"github.com/docker/compose-cli/api/containers"
|
"github.com/docker/compose-cli/api/containers"
|
||||||
apicontext "github.com/docker/compose-cli/context"
|
|
||||||
"github.com/docker/compose-cli/context/store"
|
|
||||||
"github.com/docker/compose-cli/progress"
|
"github.com/docker/compose-cli/progress"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -35,6 +33,7 @@ type runOptions struct {
|
||||||
Name string
|
Name string
|
||||||
Command []string
|
Command []string
|
||||||
WorkingDir string
|
WorkingDir string
|
||||||
|
ConfigPaths []string
|
||||||
Environment []string
|
Environment []string
|
||||||
Detach bool
|
Detach bool
|
||||||
Publish []string
|
Publish []string
|
||||||
|
@ -51,17 +50,6 @@ func runCommand() *cobra.Command {
|
||||||
Short: "Run a one-off command on a service.",
|
Short: "Run a one-off command on a service.",
|
||||||
Args: cobra.MinimumNArgs(1),
|
Args: cobra.MinimumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
s := store.ContextStore(cmd.Context())
|
|
||||||
currentCtx, err := s.Get(apicontext.CurrentContext(cmd.Context()))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
switch currentCtx.Type() {
|
|
||||||
case store.DefaultContextType:
|
|
||||||
default:
|
|
||||||
return fmt.Errorf(`Command "run" is not yet implemented for %q context type`, currentCtx.Type())
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
opts.Command = args[1:]
|
opts.Command = args[1:]
|
||||||
}
|
}
|
||||||
|
@ -70,7 +58,7 @@ func runCommand() *cobra.Command {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
runCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
runCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||||
|
runCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||||
runCmd.Flags().StringArrayVarP(&opts.Publish, "publish", "p", []string{}, "Publish a container's port(s). [HOST_PORT:]CONTAINER_PORT")
|
runCmd.Flags().StringArrayVarP(&opts.Publish, "publish", "p", []string{}, "Publish a container's port(s). [HOST_PORT:]CONTAINER_PORT")
|
||||||
runCmd.Flags().StringVar(&opts.Name, "name", "", "Assign a name to the container")
|
runCmd.Flags().StringVar(&opts.Name, "name", "", "Assign a name to the container")
|
||||||
runCmd.Flags().BoolVar(&opts.NoDeps, "no-deps", false, "Don't start linked services.")
|
runCmd.Flags().BoolVar(&opts.NoDeps, "no-deps", false, "Don't start linked services.")
|
||||||
|
@ -85,10 +73,11 @@ func runCommand() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func runRun(ctx context.Context, opts runOptions) error {
|
func runRun(ctx context.Context, opts runOptions) error {
|
||||||
// target service
|
projectOpts := composeOptions{
|
||||||
services := []string{opts.Name}
|
ConfigPaths: opts.ConfigPaths,
|
||||||
|
WorkingDir: opts.WorkingDir,
|
||||||
projectOpts := composeOptions{}
|
Environment: opts.Environment,
|
||||||
|
}
|
||||||
options, err := projectOpts.toProjectOptions()
|
options, err := projectOpts.toProjectOptions()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -98,7 +87,7 @@ func runRun(ctx context.Context, opts runOptions) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = filter(project, services)
|
err = filter(project, []string{opts.Name})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue