Add --quiet for some commands

- compose ls
- compose ps
- secret ls // Not implemented on ACI so no e2e-aci tests
- volume ls

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2020-10-12 11:03:43 +02:00
parent a067882b6d
commit 6c1ea32dae
7 changed files with 64 additions and 21 deletions

View file

@ -20,6 +20,7 @@ import (
"context"
"github.com/compose-spec/compose-go/cli"
"github.com/spf13/pflag"
"github.com/spf13/cobra"
@ -35,6 +36,13 @@ type composeOptions struct {
Environment []string
Format string
Detach bool
Quiet bool
}
func addComposeCommonFlags(f *pflag.FlagSet, opts *composeOptions) {
f.StringVarP(&opts.Name, "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) {

View file

@ -24,7 +24,6 @@ import (
"strings"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/docker/compose-cli/api/client"
"github.com/docker/compose-cli/api/compose"
@ -43,11 +42,6 @@ func listCommand() *cobra.Command {
return lsCmd
}
func addComposeCommonFlags(f *pflag.FlagSet, opts *composeOptions) {
f.StringVarP(&opts.Name, "project-name", "p", "", "Project name")
f.StringVar(&opts.Format, "format", "", "Format the output. Values: [pretty | json]. (Default: pretty)")
}
func runList(ctx context.Context, opts composeOptions) error {
c, err := client.New(ctx)
if err != nil {
@ -57,7 +51,12 @@ func runList(ctx context.Context, opts composeOptions) error {
if err != nil {
return err
}
if opts.Quiet {
for _, s := range stackList {
fmt.Println(s.Name)
}
return nil
}
view := viewFromStackList(stackList)
return formatter.Print(view, opts.Format, os.Stdout, func(w io.Writer) {
for _, stack := range view {

View file

@ -58,7 +58,12 @@ func runPs(ctx context.Context, opts composeOptions) error {
if err != nil {
return err
}
if opts.Quiet {
for _, s := range serviceList {
fmt.Println(s.ID)
}
return nil
}
view := viewFromServiceStatusList(serviceList)
return formatter.Print(view, opts.Format, os.Stdout,
func(w io.Writer) {

View file

@ -106,6 +106,7 @@ func inspectSecret() *cobra.Command {
type listSecretsOpts struct {
format string
quiet bool
}
func listSecrets() *cobra.Command {
@ -123,6 +124,12 @@ func listSecrets() *cobra.Command {
if err != nil {
return err
}
if opts.quiet {
for _, s := range secretsList {
fmt.Println(s.ID)
}
return nil
}
view := viewFromSecretList(secretsList)
return formatter.Print(view, opts.format, os.Stdout, func(w io.Writer) {
for _, secret := range view {
@ -132,6 +139,7 @@ func listSecrets() *cobra.Command {
},
}
cmd.Flags().StringVar(&opts.format, "format", "", "Format the output. Values: [pretty | json]. (Default: pretty)")
cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
return cmd
}

View file

@ -30,6 +30,7 @@ import (
type listVolumeOpts struct {
format string
quiet bool
}
func listVolume() *cobra.Command {
@ -47,6 +48,12 @@ func listVolume() *cobra.Command {
if err != nil {
return err
}
if opts.quiet {
for _, v := range vols {
fmt.Println(v.ID)
}
return nil
}
view := viewFromVolumeList(vols)
return formatter.Print(view, opts.format, os.Stdout, func(w io.Writer) {
for _, vol := range view {
@ -56,6 +63,7 @@ func listVolume() *cobra.Command {
},
}
cmd.Flags().StringVar(&opts.format, "format", formatter.PRETTY, "Format the output. Values: [pretty | json]. (Default: pretty)")
cmd.Flags().BoolVarP(&opts.quiet, "quiet", "q", false, "Only display IDs")
return cmd
}