This replaces the visitAll recursive function with a test that verifies that the option is set for all commands and subcommands, so that it doesn't have to be modified at runtime. We currently still have to loop over all functions for the setValidateArgs call, but that can be looked at separately. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
30 lines
667 B
Go
30 lines
667 B
Go
package context
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/docker/cli/cli"
|
|
"github.com/docker/cli/cli/command"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// newShowCommand creates a new cobra.Command for `docker context sow`
|
|
func newShowCommand(dockerCLI command.Cli) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "show",
|
|
Short: "Print the name of the current context",
|
|
Args: cli.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
runShow(dockerCLI)
|
|
return nil
|
|
},
|
|
ValidArgsFunction: cobra.NoFileCompletions,
|
|
DisableFlagsInUseLine: true,
|
|
}
|
|
return cmd
|
|
}
|
|
|
|
func runShow(dockerCli command.Cli) {
|
|
fmt.Fprintln(dockerCli.Out(), dockerCli.CurrentContext())
|
|
}
|