mirror of https://github.com/docker/cli.git
Use spf13/cobra for docker port
This fix is part of the effort to convert commands to spf13/cobra #23211. Thif fix coverted command `docker port` to use spf13/cobra Note: As part of this fix, a new function `RequiresMinMaxArgs(min int, max int)` has been added in cli/required.go. This function restrict the args to be at least min and at most max. Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
This commit is contained in:
parent
fac425608a
commit
c289179c99
|
@ -38,6 +38,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor {
|
||||||
container.NewDiffCommand(dockerCli),
|
container.NewDiffCommand(dockerCli),
|
||||||
container.NewExportCommand(dockerCli),
|
container.NewExportCommand(dockerCli),
|
||||||
container.NewLogsCommand(dockerCli),
|
container.NewLogsCommand(dockerCli),
|
||||||
|
container.NewPortCommand(dockerCli),
|
||||||
container.NewRunCommand(dockerCli),
|
container.NewRunCommand(dockerCli),
|
||||||
container.NewStartCommand(dockerCli),
|
container.NewStartCommand(dockerCli),
|
||||||
container.NewStopCommand(dockerCli),
|
container.NewStopCommand(dockerCli),
|
||||||
|
|
18
required.go
18
required.go
|
@ -43,6 +43,24 @@ func RequiresMinArgs(min int) cobra.PositionalArgs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RequiresMinMaxArgs returns an error if there is not at least min args and at most max args
|
||||||
|
func RequiresMinMaxArgs(min int, max int) cobra.PositionalArgs {
|
||||||
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
|
if len(args) >= min && len(args) <= max {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return fmt.Errorf(
|
||||||
|
"\"%s\" requires at least %d and at most %d argument(s).\nSee '%s --help'.\n\nUsage: %s\n\n%s",
|
||||||
|
cmd.CommandPath(),
|
||||||
|
min,
|
||||||
|
max,
|
||||||
|
cmd.CommandPath(),
|
||||||
|
cmd.UseLine(),
|
||||||
|
cmd.Short,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ExactArgs returns an error if there is not the exact number of args
|
// ExactArgs returns an error if there is not the exact number of args
|
||||||
func ExactArgs(number int) cobra.PositionalArgs {
|
func ExactArgs(number int) cobra.PositionalArgs {
|
||||||
return func(cmd *cobra.Command, args []string) error {
|
return func(cmd *cobra.Command, args []string) error {
|
||||||
|
|
1
usage.go
1
usage.go
|
@ -24,7 +24,6 @@ var DockerCommandUsage = []Command{
|
||||||
{"login", "Log in to a Docker registry"},
|
{"login", "Log in to a Docker registry"},
|
||||||
{"logout", "Log out from a Docker registry"},
|
{"logout", "Log out from a Docker registry"},
|
||||||
{"pause", "Pause all processes within a container"},
|
{"pause", "Pause all processes within a container"},
|
||||||
{"port", "List port mappings or a specific mapping for the CONTAINER"},
|
|
||||||
{"ps", "List containers"},
|
{"ps", "List containers"},
|
||||||
{"pull", "Pull an image or a repository from a registry"},
|
{"pull", "Pull an image or a repository from a registry"},
|
||||||
{"push", "Push an image or a repository to a registry"},
|
{"push", "Push an image or a repository to a registry"},
|
||||||
|
|
Loading…
Reference in New Issue