@@ -7,30 +7,33 @@ import (
77
88 "github.com/docker/cli/cli"
99 "github.com/docker/cli/cli/command"
10+ "github.com/docker/cli/cli/command/formatter"
1011 "github.com/docker/cli/cli/command/service"
11- "github.com/docker/cli/cli/command/stack/formatter"
12- "github.com/docker/cli/cli/command/stack/options"
13- "github.com/docker/cli/cli/command/stack/swarm"
1412 flagsHelper "github.com/docker/cli/cli/flags"
1513 cliopts "github.com/docker/cli/opts"
1614 "github.com/fvbommel/sortorder"
17- swarmtypes "github.com/moby/moby/api/types/swarm"
15+ "github.com/moby/moby/api/types/swarm"
1816 "github.com/spf13/cobra"
1917)
2018
21- // servicesOptions holds docker stack services options
22- type servicesOptions = options.Services
19+ // serviceListOptions holds docker stack services options
20+ type serviceListOptions = struct {
21+ quiet bool
22+ format string
23+ filter cliopts.FilterOpt
24+ namespace string
25+ }
2326
2427func newServicesCommand (dockerCLI command.Cli ) * cobra.Command {
25- opts := servicesOptions { Filter : cliopts .NewFilterOpt ()}
28+ opts := serviceListOptions { filter : cliopts .NewFilterOpt ()}
2629
2730 cmd := & cobra.Command {
2831 Use : "services [OPTIONS] STACK" ,
2932 Short : "List the services in the stack" ,
3033 Args : cli .ExactArgs (1 ),
3134 RunE : func (cmd * cobra.Command , args []string ) error {
32- opts .Namespace = args [0 ]
33- if err := validateStackName (opts .Namespace ); err != nil {
35+ opts .namespace = args [0 ]
36+ if err := validateStackName (opts .namespace ); err != nil {
3437 return err
3538 }
3639 return runServices (cmd .Context (), dockerCLI , opts )
@@ -40,41 +43,34 @@ func newServicesCommand(dockerCLI command.Cli) *cobra.Command {
4043 },
4144 }
4245 flags := cmd .Flags ()
43- flags .BoolVarP (& opts .Quiet , "quiet" , "q" , false , "Only display IDs" )
44- flags .StringVar (& opts .Format , "format" , "" , flagsHelper .FormatHelp )
45- flags .VarP (& opts .Filter , "filter" , "f" , "Filter output based on conditions provided" )
46+ flags .BoolVarP (& opts .quiet , "quiet" , "q" , false , "Only display IDs" )
47+ flags .StringVar (& opts .format , "format" , "" , flagsHelper .FormatHelp )
48+ flags .VarP (& opts .filter , "filter" , "f" , "Filter output based on conditions provided" )
4649 return cmd
4750}
4851
49- // RunServices performs a stack services against the specified swarm cluster
50- //
51- // Deprecated: this function was for internal use and will be removed in the next release.
52- func RunServices (ctx context.Context , dockerCLI command.Cli , opts options.Services ) error {
53- return runServices (ctx , dockerCLI , opts )
54- }
55-
5652// runServices performs a stack services against the specified swarm cluster
57- func runServices (ctx context.Context , dockerCLI command.Cli , opts servicesOptions ) error {
58- services , err := swarm . GetServices (ctx , dockerCLI , opts )
53+ func runServices (ctx context.Context , dockerCLI command.Cli , opts serviceListOptions ) error {
54+ services , err := getServices (ctx , dockerCLI . Client () , opts )
5955 if err != nil {
6056 return err
6157 }
6258 return formatWrite (dockerCLI , services , opts )
6359}
6460
65- func formatWrite (dockerCLI command.Cli , services []swarmtypes .Service , opts servicesOptions ) error {
61+ func formatWrite (dockerCLI command.Cli , services []swarm .Service , opts serviceListOptions ) error {
6662 // if no services in the stack, print message and exit 0
6763 if len (services ) == 0 {
68- _ , _ = fmt .Fprintln (dockerCLI .Err (), "Nothing found in stack:" , opts .Namespace )
64+ _ , _ = fmt .Fprintln (dockerCLI .Err (), "Nothing found in stack:" , opts .namespace )
6965 return nil
7066 }
7167 sort .Slice (services , func (i , j int ) bool {
7268 return sortorder .NaturalLess (services [i ].Spec .Name , services [j ].Spec .Name )
7369 })
7470
75- f := opts .Format
71+ f := opts .format
7672 if len (f ) == 0 {
77- if len (dockerCLI .ConfigFile ().ServicesFormat ) > 0 && ! opts .Quiet {
73+ if len (dockerCLI .ConfigFile ().ServicesFormat ) > 0 && ! opts .quiet {
7874 f = dockerCLI .ConfigFile ().ServicesFormat
7975 } else {
8076 f = formatter .TableFormatKey
@@ -83,7 +79,7 @@ func formatWrite(dockerCLI command.Cli, services []swarmtypes.Service, opts serv
8379
8480 servicesCtx := formatter.Context {
8581 Output : dockerCLI .Out (),
86- Format : service .NewListFormat (f , opts .Quiet ),
82+ Format : service .NewListFormat (f , opts .quiet ),
8783 }
8884 return service .ListFormatWrite (servicesCtx , services )
8985}
0 commit comments