Update cli imports to using local package
Also, rename a bunch of variable to not *shadow* the `opts` package
name.
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Upstream-commit: d7f6563efc
Component: cli
This commit is contained in:
@@ -5,8 +5,8 @@ import (
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/opts"
|
||||
volumetypes "github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/docker/opts"
|
||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
@@ -21,7 +21,7 @@ type createOptions struct {
|
||||
}
|
||||
|
||||
func newCreateCommand(dockerCli command.Cli) *cobra.Command {
|
||||
opts := createOptions{
|
||||
options := createOptions{
|
||||
driverOpts: *opts.NewMapOpts(nil, nil),
|
||||
labels: opts.NewListOpts(opts.ValidateEnv),
|
||||
}
|
||||
@@ -32,32 +32,32 @@ func newCreateCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Args: cli.RequiresMaxArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 1 {
|
||||
if opts.name != "" {
|
||||
if options.name != "" {
|
||||
return errors.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n")
|
||||
}
|
||||
opts.name = args[0]
|
||||
options.name = args[0]
|
||||
}
|
||||
return runCreate(dockerCli, opts)
|
||||
return runCreate(dockerCli, options)
|
||||
},
|
||||
}
|
||||
flags := cmd.Flags()
|
||||
flags.StringVarP(&opts.driver, "driver", "d", "local", "Specify volume driver name")
|
||||
flags.StringVar(&opts.name, "name", "", "Specify volume name")
|
||||
flags.StringVarP(&options.driver, "driver", "d", "local", "Specify volume driver name")
|
||||
flags.StringVar(&options.name, "name", "", "Specify volume name")
|
||||
flags.Lookup("name").Hidden = true
|
||||
flags.VarP(&opts.driverOpts, "opt", "o", "Set driver specific options")
|
||||
flags.Var(&opts.labels, "label", "Set metadata for a volume")
|
||||
flags.VarP(&options.driverOpts, "opt", "o", "Set driver specific options")
|
||||
flags.Var(&options.labels, "label", "Set metadata for a volume")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runCreate(dockerCli command.Cli, opts createOptions) error {
|
||||
func runCreate(dockerCli command.Cli, options createOptions) error {
|
||||
client := dockerCli.Client()
|
||||
|
||||
volReq := volumetypes.VolumesCreateBody{
|
||||
Driver: opts.driver,
|
||||
DriverOpts: opts.driverOpts.GetAll(),
|
||||
Name: opts.name,
|
||||
Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()),
|
||||
Driver: options.driver,
|
||||
DriverOpts: options.driverOpts.GetAll(),
|
||||
Name: options.name,
|
||||
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
|
||||
}
|
||||
|
||||
vol, err := client.VolumeCreate(context.Background(), volReq)
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@@ -27,7 +27,7 @@ type listOptions struct {
|
||||
}
|
||||
|
||||
func newListCommand(dockerCli command.Cli) *cobra.Command {
|
||||
opts := listOptions{filter: opts.NewFilterOpt()}
|
||||
options := listOptions{filter: opts.NewFilterOpt()}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "ls [OPTIONS]",
|
||||
@@ -35,28 +35,28 @@ func newListCommand(dockerCli command.Cli) *cobra.Command {
|
||||
Short: "List volumes",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return runList(dockerCli, opts)
|
||||
return runList(dockerCli, options)
|
||||
},
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Only display volume names")
|
||||
flags.StringVar(&opts.format, "format", "", "Pretty-print volumes using a Go template")
|
||||
flags.VarP(&opts.filter, "filter", "f", "Provide filter values (e.g. 'dangling=true')")
|
||||
flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only display volume names")
|
||||
flags.StringVar(&options.format, "format", "", "Pretty-print volumes using a Go template")
|
||||
flags.VarP(&options.filter, "filter", "f", "Provide filter values (e.g. 'dangling=true')")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func runList(dockerCli command.Cli, opts listOptions) error {
|
||||
func runList(dockerCli command.Cli, options listOptions) error {
|
||||
client := dockerCli.Client()
|
||||
volumes, err := client.VolumeList(context.Background(), opts.filter.Value())
|
||||
volumes, err := client.VolumeList(context.Background(), options.filter.Value())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
format := opts.format
|
||||
format := options.format
|
||||
if len(format) == 0 {
|
||||
if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !opts.quiet {
|
||||
if len(dockerCli.ConfigFile().VolumesFormat) > 0 && !options.quiet {
|
||||
format = dockerCli.ConfigFile().VolumesFormat
|
||||
} else {
|
||||
format = formatter.TableFormatKey
|
||||
@@ -67,7 +67,7 @@ func runList(dockerCli command.Cli, opts listOptions) error {
|
||||
|
||||
volumeCtx := formatter.Context{
|
||||
Output: dockerCli.Out(),
|
||||
Format: formatter.NewVolumeFormat(format, opts.quiet),
|
||||
Format: formatter.NewVolumeFormat(format, options.quiet),
|
||||
}
|
||||
return formatter.VolumeWrite(volumeCtx, volumes.Volumes)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/docker/cli/opts"
|
||||
units "github.com/docker/go-units"
|
||||
"github.com/spf13/cobra"
|
||||
"golang.org/x/net/context"
|
||||
@@ -18,14 +18,14 @@ type pruneOptions struct {
|
||||
|
||||
// NewPruneCommand returns a new cobra prune command for volumes
|
||||
func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||
opts := pruneOptions{filter: opts.NewFilterOpt()}
|
||||
options := pruneOptions{filter: opts.NewFilterOpt()}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "prune [OPTIONS]",
|
||||
Short: "Remove all unused volumes",
|
||||
Args: cli.NoArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
spaceReclaimed, output, err := runPrune(dockerCli, opts)
|
||||
spaceReclaimed, output, err := runPrune(dockerCli, options)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -39,8 +39,8 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||
}
|
||||
|
||||
flags := cmd.Flags()
|
||||
flags.BoolVarP(&opts.force, "force", "f", false, "Do not prompt for confirmation")
|
||||
flags.Var(&opts.filter, "filter", "Provide filter values (e.g. 'label=<label>')")
|
||||
flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
|
||||
flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'label=<label>')")
|
||||
|
||||
return cmd
|
||||
}
|
||||
@@ -48,10 +48,10 @@ func NewPruneCommand(dockerCli command.Cli) *cobra.Command {
|
||||
const warning = `WARNING! This will remove all volumes not used by at least one container.
|
||||
Are you sure you want to continue?`
|
||||
|
||||
func runPrune(dockerCli command.Cli, opts pruneOptions) (spaceReclaimed uint64, output string, err error) {
|
||||
pruneFilters := command.PruneFilters(dockerCli, opts.filter.Value())
|
||||
func runPrune(dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
|
||||
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
|
||||
|
||||
if !opts.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
||||
if !options.force && !command.PromptForConfirmation(dockerCli.In(), dockerCli.Out(), warning) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user