mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Refactor utils/flags.go, fixes #11892
Signed-off-by: Antonio Murdaca <me@runcom.ninja>
This commit is contained in:
parent
61069d8b69
commit
5670c6c695
41 changed files with 75 additions and 112 deletions
|
@ -23,7 +23,7 @@ func (cli *DockerCli) CmdAttach(args ...string) error {
|
|||
)
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
name := cmd.Arg(0)
|
||||
|
||||
stream, _, err := cli.call("GET", "/containers/"+name+"/json", nil, nil)
|
||||
|
|
|
@ -58,8 +58,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
|
|||
flCPUSetCpus := cmd.String([]string{"-cpuset-cpus"}, "", "CPUs in which to allow execution (0-3, 0,1)")
|
||||
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
context archive.Archive
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdCommit creates a new image from a container's changes.
|
||||
|
@ -28,7 +27,7 @@ func (cli *DockerCli) CmdCommit(args ...string) error {
|
|||
flConfig := cmd.String([]string{"#run", "#-run"}, "", "This option is deprecated and will be removed in a future version in favor of inline Dockerfile-compatible commands")
|
||||
cmd.Require(flag.Max, 2)
|
||||
cmd.Require(flag.Min, 1)
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
name = cmd.Arg(0)
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdCp copies files/folders from a path on the container to a directory on the host running the command.
|
||||
|
@ -20,7 +19,7 @@ func (cli *DockerCli) CmdCp(args ...string) error {
|
|||
cmd := cli.Subcmd("cp", "CONTAINER:PATH HOSTDIR|-", "Copy files/folders from a PATH on the container to a HOSTDIR on the host\nrunning the command. Use '-' to write the data\nas a tar file to STDOUT.", true)
|
||||
cmd.Require(flag.Exact, 2)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var copyData engine.Env
|
||||
info := strings.Split(cmd.Arg(0), ":")
|
||||
|
|
|
@ -142,7 +142,7 @@ func (cli *DockerCli) CmdCreate(args ...string) error {
|
|||
|
||||
config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
|
||||
if err != nil {
|
||||
utils.ReportError(cmd, err.Error(), true)
|
||||
cmd.ReportError(err.Error(), true)
|
||||
}
|
||||
if config.Image == "" {
|
||||
cmd.Usage()
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdDiff shows changes on a container's filesystem.
|
||||
|
@ -18,7 +17,7 @@ func (cli *DockerCli) CmdDiff(args ...string) error {
|
|||
cmd := cli.Subcmd("diff", "CONTAINER", "Inspect changes on a container's filesystem", true)
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
body, _, err := readBody(cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil, nil))
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
"github.com/docker/docker/pkg/timeutils"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdEvents prints a live stream of real time events from the server.
|
||||
|
@ -23,7 +22,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error {
|
|||
cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
|
||||
cmd.Require(flag.Exact, 0)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
v = url.Values{}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdExport exports a filesystem as a tar archive.
|
||||
|
@ -20,7 +19,7 @@ func (cli *DockerCli) CmdExport(args ...string) error {
|
|||
outfile := cmd.String([]string{"o", "-output"}, "", "Write to a file, instead of STDOUT")
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
output io.Writer = cli.out
|
||||
|
|
|
@ -21,7 +21,7 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
|
|||
noTrunc := cmd.Bool([]string{"#notrunc", "-no-trunc"}, false, "Don't truncate output")
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
body, _, err := readBody(cli.call("GET", "/images/"+cmd.Arg(0)+"/history", nil, nil))
|
||||
if err != nil {
|
||||
|
|
|
@ -102,7 +102,7 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
|||
cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
|
||||
cmd.Require(flag.Max, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
// Consolidate all filter flags, and sanity check them early.
|
||||
// They'll get process in the daemon/server.
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdImport creates an empty filesystem image, imports the contents of the tarball into the image, and optionally tags the image.
|
||||
|
@ -23,7 +22,7 @@ func (cli *DockerCli) CmdImport(args ...string) error {
|
|||
cmd.Var(&flChanges, []string{"c", "-change"}, "Apply Dockerfile instruction to the created image")
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
v = url.Values{}
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/docker/docker/engine"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/units"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdInfo displays system-wide information.
|
||||
|
@ -18,7 +17,7 @@ import (
|
|||
func (cli *DockerCli) CmdInfo(args ...string) error {
|
||||
cmd := cli.Subcmd("info", "", "Display system-wide information", true)
|
||||
cmd.Require(flag.Exact, 0)
|
||||
utils.ParseFlags(cmd, args, false)
|
||||
cmd.ParseFlags(args, false)
|
||||
|
||||
body, _, err := readBody(cli.call("GET", "/info", nil, nil))
|
||||
if err != nil {
|
||||
|
|
|
@ -20,7 +20,7 @@ func (cli *DockerCli) CmdInspect(args ...string) error {
|
|||
tmplStr := cmd.String([]string{"f", "#format", "-format"}, "", "Format the output using the given go template")
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var tmpl *template.Template
|
||||
if *tmplStr != "" {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdKill kills one or more running container using SIGKILL or a specified signal.
|
||||
|
@ -15,7 +14,7 @@ func (cli *DockerCli) CmdKill(args ...string) error {
|
|||
signal := cmd.String([]string{"s", "-signal"}, "KILL", "Signal to send to the container")
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var encounteredError error
|
||||
for _, name := range cmd.Args() {
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"os"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdLoad loads an image from a tar archive.
|
||||
|
@ -18,7 +17,7 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
|
|||
infile := cmd.String([]string{"i", "-input"}, "", "Read from a tar archive file, instead of STDIN")
|
||||
cmd.Require(flag.Exact, 0)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
input io.Reader = cli.in
|
||||
|
|
|
@ -14,7 +14,6 @@ import (
|
|||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdLogin logs in or registers a user to a Docker registry service.
|
||||
|
@ -32,7 +31,7 @@ func (cli *DockerCli) CmdLogin(args ...string) error {
|
|||
cmd.StringVar(&password, []string{"p", "-password"}, "", "Password")
|
||||
cmd.StringVar(&email, []string{"e", "-email"}, "", "Email")
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
serverAddress := registry.IndexServerAddress()
|
||||
if len(cmd.Args()) > 0 {
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdLogout logs a user out from a Docker registry.
|
||||
|
@ -17,7 +16,7 @@ func (cli *DockerCli) CmdLogout(args ...string) error {
|
|||
cmd := cli.Subcmd("logout", "[SERVER]", "Log out from a Docker registry, if no server is\nspecified \""+registry.IndexServerAddress()+"\" is the default.", true)
|
||||
cmd.Require(flag.Max, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, false)
|
||||
cmd.ParseFlags(args, false)
|
||||
serverAddress := registry.IndexServerAddress()
|
||||
if len(cmd.Args()) > 0 {
|
||||
serverAddress = cmd.Arg(0)
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/docker/docker/engine"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdLogs fetches the logs of a given container.
|
||||
|
@ -21,7 +20,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
|
|||
)
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
name := cmd.Arg(0)
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdPause pauses all processes within one or more containers.
|
||||
|
@ -13,7 +12,7 @@ import (
|
|||
func (cli *DockerCli) CmdPause(args ...string) error {
|
||||
cmd := cli.Subcmd("pause", "CONTAINER [CONTAINER...]", "Pause all processes within a container", true)
|
||||
cmd.Require(flag.Min, 1)
|
||||
utils.ParseFlags(cmd, args, false)
|
||||
cmd.ParseFlags(args, false)
|
||||
|
||||
var encounteredError error
|
||||
for _, name := range cmd.Args() {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/nat"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdPort lists port mappings for a container.
|
||||
|
@ -17,7 +16,7 @@ import (
|
|||
func (cli *DockerCli) CmdPort(args ...string) error {
|
||||
cmd := cli.Subcmd("port", "CONTAINER [PRIVATE_PORT[/PROTO]]", "List port mappings for the CONTAINER, or lookup the public-facing port that\nis NAT-ed to the PRIVATE_PORT", true)
|
||||
cmd.Require(flag.Min, 1)
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
stream, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/json", nil, nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -43,7 +43,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
|
|||
|
||||
cmd.Var(&flFilter, []string{"f", "-filter"}, "Filter output based on conditions provided")
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
if *last == -1 && *nLatest {
|
||||
*last = 1
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func (cli *DockerCli) CmdPull(args ...string) error {
|
|||
allTags := cmd.Bool([]string{"a", "-all-tags"}, false, "Download all tagged images in the repository")
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
v = url.Values{}
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdPush pushes an image or repository to the registry.
|
||||
|
@ -17,7 +16,7 @@ func (cli *DockerCli) CmdPush(args ...string) error {
|
|||
cmd := cli.Subcmd("push", "NAME[:TAG]", "Push an image or a repository to the registry", true)
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
name := cmd.Arg(0)
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"strconv"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdRestart restarts one or more running containers.
|
||||
|
@ -17,7 +16,7 @@ func (cli *DockerCli) CmdRestart(args ...string) error {
|
|||
nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing the container")
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
v := url.Values{}
|
||||
v.Set("t", strconv.Itoa(*nSeconds))
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"net/url"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
func (cli *DockerCli) CmdRm(args ...string) error {
|
||||
|
@ -15,7 +14,7 @@ func (cli *DockerCli) CmdRm(args ...string) error {
|
|||
force := cmd.Bool([]string{"f", "-force"}, false, "Force the removal of a running container (uses SIGKILL)")
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
val := url.Values{}
|
||||
if *v {
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
"github.com/docker/docker/engine"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdRmi removes all images with the specified name(s).
|
||||
|
@ -20,7 +19,7 @@ func (cli *DockerCli) CmdRmi(args ...string) error {
|
|||
)
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
v := url.Values{}
|
||||
if *force {
|
||||
|
|
|
@ -58,7 +58,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
|||
config, hostConfig, cmd, err := runconfig.Parse(cmd, args)
|
||||
// just in case the Parse does not exit
|
||||
if err != nil {
|
||||
utils.ReportError(cmd, err.Error(), true)
|
||||
cmd.ReportError(err.Error(), true)
|
||||
}
|
||||
|
||||
if len(hostConfig.Dns) > 0 {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"os"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdSave saves one or more images to a tar archive.
|
||||
|
@ -20,7 +19,7 @@ func (cli *DockerCli) CmdSave(args ...string) error {
|
|||
outfile := cmd.String([]string{"o", "-output"}, "", "Write to an file, instead of STDOUT")
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
output io.Writer = cli.out
|
||||
|
|
|
@ -24,7 +24,7 @@ func (cli *DockerCli) CmdSearch(args ...string) error {
|
|||
stars := cmd.Int([]string{"s", "#stars", "-stars"}, 0, "Only displays with at least x stars")
|
||||
cmd.Require(flag.Exact, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
name := cmd.Arg(0)
|
||||
v := url.Values{}
|
||||
|
|
|
@ -54,7 +54,7 @@ func (cli *DockerCli) CmdStart(args ...string) error {
|
|||
)
|
||||
|
||||
cmd.Require(flag.Min, 1)
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
if *attach || *openStdin {
|
||||
if cmd.NArg() > 1 {
|
||||
|
|
|
@ -13,7 +13,6 @@ import (
|
|||
"github.com/docker/docker/api/types"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/units"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
type containerStats struct {
|
||||
|
@ -114,7 +113,7 @@ func (s *containerStats) Display(w io.Writer) error {
|
|||
func (cli *DockerCli) CmdStats(args ...string) error {
|
||||
cmd := cli.Subcmd("stats", "CONTAINER [CONTAINER...]", "Display a live stream of one or more containers' resource usage statistics", true)
|
||||
cmd.Require(flag.Min, 1)
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
names := cmd.Args()
|
||||
sort.Strings(names)
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"strconv"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdStop stops one or more running containers.
|
||||
|
@ -19,7 +18,7 @@ func (cli *DockerCli) CmdStop(args ...string) error {
|
|||
nSeconds := cmd.Int([]string{"t", "-time"}, 10, "Seconds to wait for stop before killing it")
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
v := url.Values{}
|
||||
v.Set("t", strconv.Itoa(*nSeconds))
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdTag tags an image into a repository.
|
||||
|
@ -17,7 +16,7 @@ func (cli *DockerCli) CmdTag(args ...string) error {
|
|||
force := cmd.Bool([]string{"f", "#force", "-force"}, false, "Force")
|
||||
cmd.Require(flag.Exact, 2)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var (
|
||||
repository, tag = parsers.ParseRepositoryTag(cmd.Arg(1))
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
|
||||
"github.com/docker/docker/engine"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdTop displays the running processes of a container.
|
||||
|
@ -18,7 +17,7 @@ func (cli *DockerCli) CmdTop(args ...string) error {
|
|||
cmd := cli.Subcmd("top", "CONTAINER [ps OPTIONS]", "Display the running processes of a container", true)
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
val := url.Values{}
|
||||
if cmd.NArg() > 1 {
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdUnpause unpauses all processes within a container, for one or more containers.
|
||||
|
@ -13,7 +12,7 @@ import (
|
|||
func (cli *DockerCli) CmdUnpause(args ...string) error {
|
||||
cmd := cli.Subcmd("unpause", "CONTAINER [CONTAINER...]", "Unpause all processes within a container", true)
|
||||
cmd.Require(flag.Min, 1)
|
||||
utils.ParseFlags(cmd, args, false)
|
||||
cmd.ParseFlags(args, false)
|
||||
|
||||
var encounteredError error
|
||||
for _, name := range cmd.Args() {
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/docker/docker/autogen/dockerversion"
|
||||
"github.com/docker/docker/engine"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdVersion shows Docker version information.
|
||||
|
@ -21,7 +20,7 @@ func (cli *DockerCli) CmdVersion(args ...string) error {
|
|||
cmd := cli.Subcmd("version", "", "Show the Docker version information.", true)
|
||||
cmd.Require(flag.Exact, 0)
|
||||
|
||||
utils.ParseFlags(cmd, args, false)
|
||||
cmd.ParseFlags(args, false)
|
||||
|
||||
if dockerversion.VERSION != "" {
|
||||
fmt.Fprintf(cli.out, "Client version: %s\n", dockerversion.VERSION)
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"fmt"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// CmdWait blocks until a container stops, then prints its exit code.
|
||||
|
@ -16,7 +15,7 @@ func (cli *DockerCli) CmdWait(args ...string) error {
|
|||
cmd := cli.Subcmd("wait", "CONTAINER [CONTAINER...]", "Block until a container stops, then print its exit code.", true)
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
utils.ParseFlags(cmd, args, true)
|
||||
cmd.ParseFlags(args, true)
|
||||
|
||||
var encounteredError error
|
||||
for _, name := range cmd.Args() {
|
||||
|
|
|
@ -1054,6 +1054,42 @@ func (f *FlagSet) Parse(arguments []string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// ParseFlags is a utility function that adds a help flag if withHelp is true,
|
||||
// calls cmd.Parse(args) and prints a relevant error message if there are
|
||||
// incorrect number of arguments. It returns error only if error handling is
|
||||
// set to ContinueOnError and parsing fails. If error handling is set to
|
||||
// ExitOnError, it's safe to ignore the return value.
|
||||
func (cmd *FlagSet) ParseFlags(args []string, withHelp bool) error {
|
||||
var help *bool
|
||||
if withHelp {
|
||||
help = cmd.Bool([]string{"#help", "-help"}, false, "Print usage")
|
||||
}
|
||||
if err := cmd.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if help != nil && *help {
|
||||
cmd.Usage()
|
||||
// just in case Usage does not exit
|
||||
os.Exit(0)
|
||||
}
|
||||
if str := cmd.CheckArgs(); str != "" {
|
||||
cmd.ReportError(str, withHelp)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (cmd *FlagSet) ReportError(str string, withHelp bool) {
|
||||
if withHelp {
|
||||
if os.Args[0] == cmd.Name() {
|
||||
str += ". See '" + os.Args[0] + " --help'"
|
||||
} else {
|
||||
str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Parsed reports whether f.Parse has been called.
|
||||
func (f *FlagSet) Parsed() bool {
|
||||
return f.parsed
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"github.com/docker/docker/engine"
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
type ExecConfig struct {
|
||||
|
@ -50,7 +49,7 @@ func ParseExec(cmd *flag.FlagSet, args []string) (*ExecConfig, error) {
|
|||
container string
|
||||
)
|
||||
cmd.Require(flag.Min, 2)
|
||||
if err := utils.ParseFlags(cmd, args, true); err != nil {
|
||||
if err := cmd.ParseFlags(args, true); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
container = cmd.Arg(0)
|
||||
|
|
|
@ -96,7 +96,7 @@ func Parse(cmd *flag.FlagSet, args []string) (*Config, *HostConfig, *flag.FlagSe
|
|||
|
||||
cmd.Require(flag.Min, 1)
|
||||
|
||||
if err := utils.ParseFlags(cmd, args, true); err != nil {
|
||||
if err := cmd.ParseFlags(args, true); err != nil {
|
||||
return nil, nil, cmd, err
|
||||
}
|
||||
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
flag "github.com/docker/docker/pkg/mflag"
|
||||
)
|
||||
|
||||
// ParseFlags is a utility function that adds a help flag if withHelp is true,
|
||||
// calls cmd.Parse(args) and prints a relevant error message if there are
|
||||
// incorrect number of arguments. It returns error only if error handling is
|
||||
// set to ContinueOnError and parsing fails. If error handling is set to
|
||||
// ExitOnError, it's safe to ignore the return value.
|
||||
// TODO: move this to a better package than utils
|
||||
func ParseFlags(cmd *flag.FlagSet, args []string, withHelp bool) error {
|
||||
var help *bool
|
||||
if withHelp {
|
||||
help = cmd.Bool([]string{"#help", "-help"}, false, "Print usage")
|
||||
}
|
||||
if err := cmd.Parse(args); err != nil {
|
||||
return err
|
||||
}
|
||||
if help != nil && *help {
|
||||
cmd.Usage()
|
||||
// just in case Usage does not exit
|
||||
os.Exit(0)
|
||||
}
|
||||
if str := cmd.CheckArgs(); str != "" {
|
||||
ReportError(cmd, str, withHelp)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ReportError(cmd *flag.FlagSet, str string, withHelp bool) {
|
||||
if withHelp {
|
||||
if os.Args[0] == cmd.Name() {
|
||||
str += ". See '" + os.Args[0] + " --help'"
|
||||
} else {
|
||||
str += ". See '" + os.Args[0] + " " + cmd.Name() + " --help'"
|
||||
}
|
||||
}
|
||||
fmt.Fprintf(cmd.Out(), "docker: %s.\n", str)
|
||||
os.Exit(1)
|
||||
}
|
Loading…
Reference in a new issue