зеркало из https://github.com/docker/compose-cli.git
Refactor ProjectName
This separate project name and service name for command `run` Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Родитель
b560f0cbe9
Коммит
cef7a2d4ce
|
@ -71,7 +71,7 @@ type ConvertOptions struct {
|
|||
|
||||
// RunOptions options to execute compose run
|
||||
type RunOptions struct {
|
||||
Name string
|
||||
Service string
|
||||
Command []string
|
||||
Detach bool
|
||||
AutoRemove bool
|
||||
|
|
|
@ -28,7 +28,7 @@ import (
|
|||
)
|
||||
|
||||
type composeOptions struct {
|
||||
Name string
|
||||
ProjectName string
|
||||
DomainName string
|
||||
WorkingDir string
|
||||
ConfigPaths []string
|
||||
|
@ -40,14 +40,14 @@ type composeOptions struct {
|
|||
}
|
||||
|
||||
func addComposeCommonFlags(f *pflag.FlagSet, opts *composeOptions) {
|
||||
f.StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
||||
f.StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||
f.StringVar(&opts.Format, "format", "", "Format the output. Values: [pretty | json]. (Default: pretty)")
|
||||
f.BoolVarP(&opts.Quiet, "quiet", "q", false, "Only display IDs")
|
||||
}
|
||||
|
||||
func (o *composeOptions) toProjectName() (string, error) {
|
||||
if o.Name != "" {
|
||||
return o.Name, nil
|
||||
if o.ProjectName != "" {
|
||||
return o.ProjectName, nil
|
||||
}
|
||||
|
||||
options, err := o.toProjectOptions()
|
||||
|
@ -68,7 +68,7 @@ func (o *composeOptions) toProjectOptions() (*cli.ProjectOptions, error) {
|
|||
cli.WithDotEnv,
|
||||
cli.WithEnv(o.Environment),
|
||||
cli.WithWorkingDirectory(o.WorkingDir),
|
||||
cli.WithName(o.Name))
|
||||
cli.WithName(o.ProjectName))
|
||||
}
|
||||
|
||||
// Command returns the compose command with its child commands
|
||||
|
|
|
@ -37,7 +37,7 @@ func convertCommand() *cobra.Command {
|
|||
return runConvert(cmd.Context(), opts)
|
||||
},
|
||||
}
|
||||
convertCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
||||
convertCmd.Flags().StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||
convertCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||
convertCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||
convertCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
||||
|
|
|
@ -36,7 +36,7 @@ func downCommand() *cobra.Command {
|
|||
return runDown(cmd.Context(), opts)
|
||||
},
|
||||
}
|
||||
downCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
||||
downCmd.Flags().StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||
downCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||
downCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ func runList(ctx context.Context, opts composeOptions) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
stackList, err := c.ComposeService().List(ctx, opts.Name)
|
||||
stackList, err := c.ComposeService().List(ctx, opts.ProjectName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -20,10 +20,11 @@ import (
|
|||
"context"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/docker/compose-cli/api/client"
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
"github.com/docker/compose-cli/formatter"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func logsCommand() *cobra.Command {
|
||||
|
@ -35,7 +36,7 @@ func logsCommand() *cobra.Command {
|
|||
return runLogs(cmd.Context(), opts, args)
|
||||
},
|
||||
}
|
||||
logsCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
||||
logsCmd.Flags().StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||
logsCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||
logsCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ import (
|
|||
|
||||
type runOptions struct {
|
||||
Name string
|
||||
Service string
|
||||
Command []string
|
||||
WorkingDir string
|
||||
ConfigPaths []string
|
||||
|
@ -48,7 +49,7 @@ func runCommand() *cobra.Command {
|
|||
if len(args) > 1 {
|
||||
opts.Command = args[1:]
|
||||
}
|
||||
opts.Name = args[0]
|
||||
opts.Service = args[0]
|
||||
return runRun(cmd.Context(), opts)
|
||||
},
|
||||
}
|
||||
|
@ -68,14 +69,14 @@ func runRun(ctx context.Context, opts runOptions) error {
|
|||
WorkingDir: opts.WorkingDir,
|
||||
Environment: opts.Environment,
|
||||
}
|
||||
c, project, err := setup(ctx, projectOpts, []string{opts.Name})
|
||||
c, project, err := setup(ctx, projectOpts, []string{opts.Service})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
originalServices := project.Services
|
||||
_, err = progress.Run(ctx, func(ctx context.Context) (string, error) {
|
||||
return "", startDependencies(ctx, c, project, opts.Name)
|
||||
return "", startDependencies(ctx, c, project, opts.Service)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -84,7 +85,7 @@ func runRun(ctx context.Context, opts runOptions) error {
|
|||
project.Services = originalServices
|
||||
// start container and attach to container streams
|
||||
runOpts := compose.RunOptions{
|
||||
Name: opts.Name,
|
||||
Service: opts.Service,
|
||||
Command: opts.Command,
|
||||
Detach: opts.Detach,
|
||||
AutoRemove: opts.Remove,
|
||||
|
|
|
@ -47,7 +47,7 @@ func upCommand(contextType string) *cobra.Command {
|
|||
}
|
||||
},
|
||||
}
|
||||
upCmd.Flags().StringVarP(&opts.Name, "project-name", "p", "", "Project name")
|
||||
upCmd.Flags().StringVarP(&opts.ProjectName, "project-name", "p", "", "Project name")
|
||||
upCmd.Flags().StringVar(&opts.WorkingDir, "workdir", "", "Work dir")
|
||||
upCmd.Flags().StringArrayVarP(&opts.ConfigPaths, "file", "f", []string{}, "Compose configuration files")
|
||||
upCmd.Flags().StringArrayVarP(&opts.Environment, "environment", "e", []string{}, "Environment variables")
|
||||
|
|
|
@ -21,11 +21,12 @@ import (
|
|||
"fmt"
|
||||
|
||||
"github.com/compose-spec/compose-go/types"
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
apitypes "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/docker/compose-cli/api/compose"
|
||||
|
||||
moby "github.com/docker/docker/pkg/stringid"
|
||||
)
|
||||
|
||||
|
@ -33,7 +34,7 @@ func (s *composeService) RunOneOffContainer(ctx context.Context, project *types.
|
|||
originalServices := project.Services
|
||||
var requestedService types.ServiceConfig
|
||||
for _, service := range originalServices {
|
||||
if service.Name == opts.Name {
|
||||
if service.Name == opts.Service {
|
||||
requestedService = service
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,11 +66,11 @@ func (p *proxy) Services(ctx context.Context, request *composev1.ComposeServices
|
|||
/* FIXME need to create `docker service ls` command to re-introduce this feature
|
||||
for _, service := range services {
|
||||
response = append(response, &composev1.Service{
|
||||
Id: service.ID,
|
||||
Name: service.Name,
|
||||
Replicas: uint32(service.Replicas),
|
||||
Desired: uint32(service.Desired),
|
||||
Ports: service.Ports,
|
||||
Id: service.ID,
|
||||
ProjectName: service.ProjectName,
|
||||
Replicas: uint32(service.Replicas),
|
||||
Desired: uint32(service.Desired),
|
||||
Ports: service.Ports,
|
||||
})
|
||||
}*/
|
||||
return &composev1.ComposeServicesResponse{Services: response}, nil
|
||||
|
|
Загрузка…
Ссылка в новой задаче