repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
sequence
docstring
stringlengths
6
2.61k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
85
252
partition
stringclasses
1 value
docker/cli
cli/command/builder/cmd.go
NewBuilderCommand
func NewBuilderCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "builder", Short: "Manage builds", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{"version": "1.31"}, } cmd.AddCommand( NewPruneCommand(dockerCli), image.NewBuildCommand(dockerCli), ) return cmd }
go
func NewBuilderCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "builder", Short: "Manage builds", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{"version": "1.31"}, } cmd.AddCommand( NewPruneCommand(dockerCli), image.NewBuildCommand(dockerCli), ) return cmd }
[ "func", "NewBuilderCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "command", ".", "ShowHelp", "(", "dockerCli", ".", "Err", "(", ")", ")", ",", "Annotations", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", "}", ",", "}", "\n", "cmd", ".", "AddCommand", "(", "NewPruneCommand", "(", "dockerCli", ")", ",", "image", ".", "NewBuildCommand", "(", "dockerCli", ")", ",", ")", "\n", "return", "cmd", "\n", "}" ]
// NewBuilderCommand returns a cobra command for `builder` subcommands
[ "NewBuilderCommand", "returns", "a", "cobra", "command", "for", "builder", "subcommands" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/builder/cmd.go#L12-L25
train
docker/cli
cli/command/context/remove.go
RunRemove
func RunRemove(dockerCli command.Cli, opts RemoveOptions, names []string) error { var errs []string currentCtx := dockerCli.CurrentContext() for _, name := range names { if name == "default" { errs = append(errs, `default: context "default" cannot be removed`) } else if err := doRemove(dockerCli, name, name == currentCtx, opts.Force); err != nil { errs = append(errs, fmt.Sprintf("%s: %s", name, err)) } else { fmt.Fprintln(dockerCli.Out(), name) } } if len(errs) > 0 { return errors.New(strings.Join(errs, "\n")) } return nil }
go
func RunRemove(dockerCli command.Cli, opts RemoveOptions, names []string) error { var errs []string currentCtx := dockerCli.CurrentContext() for _, name := range names { if name == "default" { errs = append(errs, `default: context "default" cannot be removed`) } else if err := doRemove(dockerCli, name, name == currentCtx, opts.Force); err != nil { errs = append(errs, fmt.Sprintf("%s: %s", name, err)) } else { fmt.Fprintln(dockerCli.Out(), name) } } if len(errs) > 0 { return errors.New(strings.Join(errs, "\n")) } return nil }
[ "func", "RunRemove", "(", "dockerCli", "command", ".", "Cli", ",", "opts", "RemoveOptions", ",", "names", "[", "]", "string", ")", "error", "{", "var", "errs", "[", "]", "string", "\n", "currentCtx", ":=", "dockerCli", ".", "CurrentContext", "(", ")", "\n", "for", "_", ",", "name", ":=", "range", "names", "{", "if", "name", "==", "\"", "\"", "{", "errs", "=", "append", "(", "errs", ",", "`default: context \"default\" cannot be removed`", ")", "\n", "}", "else", "if", "err", ":=", "doRemove", "(", "dockerCli", ",", "name", ",", "name", "==", "currentCtx", ",", "opts", ".", "Force", ")", ";", "err", "!=", "nil", "{", "errs", "=", "append", "(", "errs", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ",", "err", ")", ")", "\n", "}", "else", "{", "fmt", ".", "Fprintln", "(", "dockerCli", ".", "Out", "(", ")", ",", "name", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "errs", ")", ">", "0", "{", "return", "errors", ".", "New", "(", "strings", ".", "Join", "(", "errs", ",", "\"", "\\n", "\"", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RunRemove removes one or more contexts
[ "RunRemove", "removes", "one", "or", "more", "contexts" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/context/remove.go#L34-L50
train
docker/cli
cli/command/container/rename.go
NewRenameCommand
func NewRenameCommand(dockerCli command.Cli) *cobra.Command { var opts renameOptions cmd := &cobra.Command{ Use: "rename CONTAINER NEW_NAME", Short: "Rename a container", Args: cli.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { opts.oldName = args[0] opts.newName = args[1] return runRename(dockerCli, &opts) }, } return cmd }
go
func NewRenameCommand(dockerCli command.Cli) *cobra.Command { var opts renameOptions cmd := &cobra.Command{ Use: "rename CONTAINER NEW_NAME", Short: "Rename a container", Args: cli.ExactArgs(2), RunE: func(cmd *cobra.Command, args []string) error { opts.oldName = args[0] opts.newName = args[1] return runRename(dockerCli, &opts) }, } return cmd }
[ "func", "NewRenameCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "opts", "renameOptions", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "ExactArgs", "(", "2", ")", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "opts", ".", "oldName", "=", "args", "[", "0", "]", "\n", "opts", ".", "newName", "=", "args", "[", "1", "]", "\n", "return", "runRename", "(", "dockerCli", ",", "&", "opts", ")", "\n", "}", ",", "}", "\n", "return", "cmd", "\n", "}" ]
// NewRenameCommand creates a new cobra.Command for `docker rename`
[ "NewRenameCommand", "creates", "a", "new", "cobra", ".", "Command", "for", "docker", "rename" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/rename.go#L20-L34
train
docker/cli
cli/command/orchestrator.go
GetStackOrchestrator
func GetStackOrchestrator(flagValue, contextValue, globalDefault string, stderr io.Writer) (Orchestrator, error) { // Check flag if o, err := normalize(flagValue); o != orchestratorUnset { return o, err } // Check environment variable env := os.Getenv(envVarDockerStackOrchestrator) if env == "" && os.Getenv(envVarDockerOrchestrator) != "" { fmt.Fprintf(stderr, "WARNING: experimental environment variable %s is set. Please use %s instead\n", envVarDockerOrchestrator, envVarDockerStackOrchestrator) } if o, err := normalize(env); o != orchestratorUnset { return o, err } if o, err := normalize(contextValue); o != orchestratorUnset { return o, err } if o, err := normalize(globalDefault); o != orchestratorUnset { return o, err } // Nothing set, use default orchestrator return defaultOrchestrator, nil }
go
func GetStackOrchestrator(flagValue, contextValue, globalDefault string, stderr io.Writer) (Orchestrator, error) { // Check flag if o, err := normalize(flagValue); o != orchestratorUnset { return o, err } // Check environment variable env := os.Getenv(envVarDockerStackOrchestrator) if env == "" && os.Getenv(envVarDockerOrchestrator) != "" { fmt.Fprintf(stderr, "WARNING: experimental environment variable %s is set. Please use %s instead\n", envVarDockerOrchestrator, envVarDockerStackOrchestrator) } if o, err := normalize(env); o != orchestratorUnset { return o, err } if o, err := normalize(contextValue); o != orchestratorUnset { return o, err } if o, err := normalize(globalDefault); o != orchestratorUnset { return o, err } // Nothing set, use default orchestrator return defaultOrchestrator, nil }
[ "func", "GetStackOrchestrator", "(", "flagValue", ",", "contextValue", ",", "globalDefault", "string", ",", "stderr", "io", ".", "Writer", ")", "(", "Orchestrator", ",", "error", ")", "{", "// Check flag", "if", "o", ",", "err", ":=", "normalize", "(", "flagValue", ")", ";", "o", "!=", "orchestratorUnset", "{", "return", "o", ",", "err", "\n", "}", "\n", "// Check environment variable", "env", ":=", "os", ".", "Getenv", "(", "envVarDockerStackOrchestrator", ")", "\n", "if", "env", "==", "\"", "\"", "&&", "os", ".", "Getenv", "(", "envVarDockerOrchestrator", ")", "!=", "\"", "\"", "{", "fmt", ".", "Fprintf", "(", "stderr", ",", "\"", "\\n", "\"", ",", "envVarDockerOrchestrator", ",", "envVarDockerStackOrchestrator", ")", "\n", "}", "\n", "if", "o", ",", "err", ":=", "normalize", "(", "env", ")", ";", "o", "!=", "orchestratorUnset", "{", "return", "o", ",", "err", "\n", "}", "\n", "if", "o", ",", "err", ":=", "normalize", "(", "contextValue", ")", ";", "o", "!=", "orchestratorUnset", "{", "return", "o", ",", "err", "\n", "}", "\n", "if", "o", ",", "err", ":=", "normalize", "(", "globalDefault", ")", ";", "o", "!=", "orchestratorUnset", "{", "return", "o", ",", "err", "\n", "}", "\n", "// Nothing set, use default orchestrator", "return", "defaultOrchestrator", ",", "nil", "\n", "}" ]
// GetStackOrchestrator checks DOCKER_STACK_ORCHESTRATOR environment variable and configuration file // orchestrator value and returns user defined Orchestrator.
[ "GetStackOrchestrator", "checks", "DOCKER_STACK_ORCHESTRATOR", "environment", "variable", "and", "configuration", "file", "orchestrator", "value", "and", "returns", "user", "defined", "Orchestrator", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/orchestrator.go#L63-L84
train
docker/cli
cli/streams/out.go
GetTtySize
func (o *Out) GetTtySize() (uint, uint) { if !o.isTerminal { return 0, 0 } ws, err := term.GetWinsize(o.fd) if err != nil { logrus.Debugf("Error getting size: %s", err) if ws == nil { return 0, 0 } } return uint(ws.Height), uint(ws.Width) }
go
func (o *Out) GetTtySize() (uint, uint) { if !o.isTerminal { return 0, 0 } ws, err := term.GetWinsize(o.fd) if err != nil { logrus.Debugf("Error getting size: %s", err) if ws == nil { return 0, 0 } } return uint(ws.Height), uint(ws.Width) }
[ "func", "(", "o", "*", "Out", ")", "GetTtySize", "(", ")", "(", "uint", ",", "uint", ")", "{", "if", "!", "o", ".", "isTerminal", "{", "return", "0", ",", "0", "\n", "}", "\n", "ws", ",", "err", ":=", "term", ".", "GetWinsize", "(", "o", ".", "fd", ")", "\n", "if", "err", "!=", "nil", "{", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "err", ")", "\n", "if", "ws", "==", "nil", "{", "return", "0", ",", "0", "\n", "}", "\n", "}", "\n", "return", "uint", "(", "ws", ".", "Height", ")", ",", "uint", "(", "ws", ".", "Width", ")", "\n", "}" ]
// GetTtySize returns the height and width in characters of the tty
[ "GetTtySize", "returns", "the", "height", "and", "width", "in", "characters", "of", "the", "tty" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/streams/out.go#L32-L44
train
docker/cli
cli/streams/out.go
NewOut
func NewOut(out io.Writer) *Out { fd, isTerminal := term.GetFdInfo(out) return &Out{commonStream: commonStream{fd: fd, isTerminal: isTerminal}, out: out} }
go
func NewOut(out io.Writer) *Out { fd, isTerminal := term.GetFdInfo(out) return &Out{commonStream: commonStream{fd: fd, isTerminal: isTerminal}, out: out} }
[ "func", "NewOut", "(", "out", "io", ".", "Writer", ")", "*", "Out", "{", "fd", ",", "isTerminal", ":=", "term", ".", "GetFdInfo", "(", "out", ")", "\n", "return", "&", "Out", "{", "commonStream", ":", "commonStream", "{", "fd", ":", "fd", ",", "isTerminal", ":", "isTerminal", "}", ",", "out", ":", "out", "}", "\n", "}" ]
// NewOut returns a new Out object from a Writer
[ "NewOut", "returns", "a", "new", "Out", "object", "from", "a", "Writer" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/streams/out.go#L47-L50
train
docker/cli
cli/compose/loader/loader.go
GetUnsupportedProperties
func GetUnsupportedProperties(configDicts ...map[string]interface{}) []string { unsupported := map[string]bool{} for _, configDict := range configDicts { for _, service := range getServices(configDict) { serviceDict := service.(map[string]interface{}) for _, property := range types.UnsupportedProperties { if _, isSet := serviceDict[property]; isSet { unsupported[property] = true } } } } return sortedKeys(unsupported) }
go
func GetUnsupportedProperties(configDicts ...map[string]interface{}) []string { unsupported := map[string]bool{} for _, configDict := range configDicts { for _, service := range getServices(configDict) { serviceDict := service.(map[string]interface{}) for _, property := range types.UnsupportedProperties { if _, isSet := serviceDict[property]; isSet { unsupported[property] = true } } } } return sortedKeys(unsupported) }
[ "func", "GetUnsupportedProperties", "(", "configDicts", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "[", "]", "string", "{", "unsupported", ":=", "map", "[", "string", "]", "bool", "{", "}", "\n\n", "for", "_", ",", "configDict", ":=", "range", "configDicts", "{", "for", "_", ",", "service", ":=", "range", "getServices", "(", "configDict", ")", "{", "serviceDict", ":=", "service", ".", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "_", ",", "property", ":=", "range", "types", ".", "UnsupportedProperties", "{", "if", "_", ",", "isSet", ":=", "serviceDict", "[", "property", "]", ";", "isSet", "{", "unsupported", "[", "property", "]", "=", "true", "\n", "}", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "sortedKeys", "(", "unsupported", ")", "\n", "}" ]
// GetUnsupportedProperties returns the list of any unsupported properties that are // used in the Compose files.
[ "GetUnsupportedProperties", "returns", "the", "list", "of", "any", "unsupported", "properties", "that", "are", "used", "in", "the", "Compose", "files", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/loader/loader.go#L192-L207
train
docker/cli
cli/compose/loader/loader.go
GetDeprecatedProperties
func GetDeprecatedProperties(configDicts ...map[string]interface{}) map[string]string { deprecated := map[string]string{} for _, configDict := range configDicts { deprecatedProperties := getProperties(getServices(configDict), types.DeprecatedProperties) for key, value := range deprecatedProperties { deprecated[key] = value } } return deprecated }
go
func GetDeprecatedProperties(configDicts ...map[string]interface{}) map[string]string { deprecated := map[string]string{} for _, configDict := range configDicts { deprecatedProperties := getProperties(getServices(configDict), types.DeprecatedProperties) for key, value := range deprecatedProperties { deprecated[key] = value } } return deprecated }
[ "func", "GetDeprecatedProperties", "(", "configDicts", "...", "map", "[", "string", "]", "interface", "{", "}", ")", "map", "[", "string", "]", "string", "{", "deprecated", ":=", "map", "[", "string", "]", "string", "{", "}", "\n\n", "for", "_", ",", "configDict", ":=", "range", "configDicts", "{", "deprecatedProperties", ":=", "getProperties", "(", "getServices", "(", "configDict", ")", ",", "types", ".", "DeprecatedProperties", ")", "\n", "for", "key", ",", "value", ":=", "range", "deprecatedProperties", "{", "deprecated", "[", "key", "]", "=", "value", "\n", "}", "\n", "}", "\n\n", "return", "deprecated", "\n", "}" ]
// GetDeprecatedProperties returns the list of any deprecated properties that // are used in the compose files.
[ "GetDeprecatedProperties", "returns", "the", "list", "of", "any", "deprecated", "properties", "that", "are", "used", "in", "the", "compose", "files", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/loader/loader.go#L220-L231
train
docker/cli
cli/compose/loader/loader.go
Transform
func Transform(source interface{}, target interface{}, additionalTransformers ...Transformer) error { data := mapstructure.Metadata{} config := &mapstructure.DecoderConfig{ DecodeHook: mapstructure.ComposeDecodeHookFunc( createTransformHook(additionalTransformers...), mapstructure.StringToTimeDurationHookFunc()), Result: target, Metadata: &data, } decoder, err := mapstructure.NewDecoder(config) if err != nil { return err } return decoder.Decode(source) }
go
func Transform(source interface{}, target interface{}, additionalTransformers ...Transformer) error { data := mapstructure.Metadata{} config := &mapstructure.DecoderConfig{ DecodeHook: mapstructure.ComposeDecodeHookFunc( createTransformHook(additionalTransformers...), mapstructure.StringToTimeDurationHookFunc()), Result: target, Metadata: &data, } decoder, err := mapstructure.NewDecoder(config) if err != nil { return err } return decoder.Decode(source) }
[ "func", "Transform", "(", "source", "interface", "{", "}", ",", "target", "interface", "{", "}", ",", "additionalTransformers", "...", "Transformer", ")", "error", "{", "data", ":=", "mapstructure", ".", "Metadata", "{", "}", "\n", "config", ":=", "&", "mapstructure", ".", "DecoderConfig", "{", "DecodeHook", ":", "mapstructure", ".", "ComposeDecodeHookFunc", "(", "createTransformHook", "(", "additionalTransformers", "...", ")", ",", "mapstructure", ".", "StringToTimeDurationHookFunc", "(", ")", ")", ",", "Result", ":", "target", ",", "Metadata", ":", "&", "data", ",", "}", "\n", "decoder", ",", "err", ":=", "mapstructure", ".", "NewDecoder", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "decoder", ".", "Decode", "(", "source", ")", "\n", "}" ]
// Transform converts the source into the target struct with compose types transformer // and the specified transformers if any.
[ "Transform", "converts", "the", "source", "into", "the", "target", "struct", "with", "compose", "types", "transformer", "and", "the", "specified", "transformers", "if", "any", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/loader/loader.go#L271-L285
train
docker/cli
cli/compose/loader/loader.go
convertToStringKeysRecursive
func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interface{}, error) { if mapping, ok := value.(map[interface{}]interface{}); ok { dict := make(map[string]interface{}) for key, entry := range mapping { str, ok := key.(string) if !ok { return nil, formatInvalidKeyError(keyPrefix, key) } var newKeyPrefix string if keyPrefix == "" { newKeyPrefix = str } else { newKeyPrefix = fmt.Sprintf("%s.%s", keyPrefix, str) } convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix) if err != nil { return nil, err } dict[str] = convertedEntry } return dict, nil } if list, ok := value.([]interface{}); ok { var convertedList []interface{} for index, entry := range list { newKeyPrefix := fmt.Sprintf("%s[%d]", keyPrefix, index) convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix) if err != nil { return nil, err } convertedList = append(convertedList, convertedEntry) } return convertedList, nil } return value, nil }
go
func convertToStringKeysRecursive(value interface{}, keyPrefix string) (interface{}, error) { if mapping, ok := value.(map[interface{}]interface{}); ok { dict := make(map[string]interface{}) for key, entry := range mapping { str, ok := key.(string) if !ok { return nil, formatInvalidKeyError(keyPrefix, key) } var newKeyPrefix string if keyPrefix == "" { newKeyPrefix = str } else { newKeyPrefix = fmt.Sprintf("%s.%s", keyPrefix, str) } convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix) if err != nil { return nil, err } dict[str] = convertedEntry } return dict, nil } if list, ok := value.([]interface{}); ok { var convertedList []interface{} for index, entry := range list { newKeyPrefix := fmt.Sprintf("%s[%d]", keyPrefix, index) convertedEntry, err := convertToStringKeysRecursive(entry, newKeyPrefix) if err != nil { return nil, err } convertedList = append(convertedList, convertedEntry) } return convertedList, nil } return value, nil }
[ "func", "convertToStringKeysRecursive", "(", "value", "interface", "{", "}", ",", "keyPrefix", "string", ")", "(", "interface", "{", "}", ",", "error", ")", "{", "if", "mapping", ",", "ok", ":=", "value", ".", "(", "map", "[", "interface", "{", "}", "]", "interface", "{", "}", ")", ";", "ok", "{", "dict", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "for", "key", ",", "entry", ":=", "range", "mapping", "{", "str", ",", "ok", ":=", "key", ".", "(", "string", ")", "\n", "if", "!", "ok", "{", "return", "nil", ",", "formatInvalidKeyError", "(", "keyPrefix", ",", "key", ")", "\n", "}", "\n", "var", "newKeyPrefix", "string", "\n", "if", "keyPrefix", "==", "\"", "\"", "{", "newKeyPrefix", "=", "str", "\n", "}", "else", "{", "newKeyPrefix", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "keyPrefix", ",", "str", ")", "\n", "}", "\n", "convertedEntry", ",", "err", ":=", "convertToStringKeysRecursive", "(", "entry", ",", "newKeyPrefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "dict", "[", "str", "]", "=", "convertedEntry", "\n", "}", "\n", "return", "dict", ",", "nil", "\n", "}", "\n", "if", "list", ",", "ok", ":=", "value", ".", "(", "[", "]", "interface", "{", "}", ")", ";", "ok", "{", "var", "convertedList", "[", "]", "interface", "{", "}", "\n", "for", "index", ",", "entry", ":=", "range", "list", "{", "newKeyPrefix", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "keyPrefix", ",", "index", ")", "\n", "convertedEntry", ",", "err", ":=", "convertToStringKeysRecursive", "(", "entry", ",", "newKeyPrefix", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "convertedList", "=", "append", "(", "convertedList", ",", "convertedEntry", ")", "\n", "}", "\n", "return", "convertedList", ",", "nil", "\n", "}", "\n", "return", "value", ",", "nil", "\n", "}" ]
// keys needs to be converted to strings for jsonschema
[ "keys", "needs", "to", "be", "converted", "to", "strings", "for", "jsonschema" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/loader/loader.go#L331-L366
train
docker/cli
cli/command/stack/kubernetes/deploy.go
RunDeploy
func RunDeploy(dockerCli *KubeCli, opts options.Deploy, cfg *composetypes.Config) error { cmdOut := dockerCli.Out() // Initialize clients composeClient, err := dockerCli.composeClient() if err != nil { return err } stacks, err := composeClient.Stacks(false) if err != nil { return err } stack, err := stacks.FromCompose(dockerCli.Err(), opts.Namespace, cfg) if err != nil { return err } configMaps := composeClient.ConfigMaps() secrets := composeClient.Secrets() services := composeClient.Services() if err := stacks.IsColliding(services, stack); err != nil { return err } if err := createResources(stack, stacks, configMaps, secrets); err != nil { return err } fmt.Fprintln(cmdOut, "Waiting for the stack to be stable and running...") v1beta1Cli, err := dockerCli.stacksv1beta1() if err != nil { return err } pods := composeClient.Pods() watcher := &deployWatcher{ stacks: v1beta1Cli, pods: pods, } statusUpdates := make(chan serviceStatus) displayDone := make(chan struct{}) go func() { defer close(displayDone) display := newStatusDisplay(dockerCli.Out()) for status := range statusUpdates { display.OnStatus(status) } }() err = watcher.Watch(stack.Name, stack.getServices(), statusUpdates) close(statusUpdates) <-displayDone if err != nil { return err } fmt.Fprintf(cmdOut, "\nStack %s is stable and running\n\n", stack.Name) return nil }
go
func RunDeploy(dockerCli *KubeCli, opts options.Deploy, cfg *composetypes.Config) error { cmdOut := dockerCli.Out() // Initialize clients composeClient, err := dockerCli.composeClient() if err != nil { return err } stacks, err := composeClient.Stacks(false) if err != nil { return err } stack, err := stacks.FromCompose(dockerCli.Err(), opts.Namespace, cfg) if err != nil { return err } configMaps := composeClient.ConfigMaps() secrets := composeClient.Secrets() services := composeClient.Services() if err := stacks.IsColliding(services, stack); err != nil { return err } if err := createResources(stack, stacks, configMaps, secrets); err != nil { return err } fmt.Fprintln(cmdOut, "Waiting for the stack to be stable and running...") v1beta1Cli, err := dockerCli.stacksv1beta1() if err != nil { return err } pods := composeClient.Pods() watcher := &deployWatcher{ stacks: v1beta1Cli, pods: pods, } statusUpdates := make(chan serviceStatus) displayDone := make(chan struct{}) go func() { defer close(displayDone) display := newStatusDisplay(dockerCli.Out()) for status := range statusUpdates { display.OnStatus(status) } }() err = watcher.Watch(stack.Name, stack.getServices(), statusUpdates) close(statusUpdates) <-displayDone if err != nil { return err } fmt.Fprintf(cmdOut, "\nStack %s is stable and running\n\n", stack.Name) return nil }
[ "func", "RunDeploy", "(", "dockerCli", "*", "KubeCli", ",", "opts", "options", ".", "Deploy", ",", "cfg", "*", "composetypes", ".", "Config", ")", "error", "{", "cmdOut", ":=", "dockerCli", ".", "Out", "(", ")", "\n\n", "// Initialize clients", "composeClient", ",", "err", ":=", "dockerCli", ".", "composeClient", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "stacks", ",", "err", ":=", "composeClient", ".", "Stacks", "(", "false", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "stack", ",", "err", ":=", "stacks", ".", "FromCompose", "(", "dockerCli", ".", "Err", "(", ")", ",", "opts", ".", "Namespace", ",", "cfg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "configMaps", ":=", "composeClient", ".", "ConfigMaps", "(", ")", "\n", "secrets", ":=", "composeClient", ".", "Secrets", "(", ")", "\n", "services", ":=", "composeClient", ".", "Services", "(", ")", "\n\n", "if", "err", ":=", "stacks", ".", "IsColliding", "(", "services", ",", "stack", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "err", ":=", "createResources", "(", "stack", ",", "stacks", ",", "configMaps", ",", "secrets", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "fmt", ".", "Fprintln", "(", "cmdOut", ",", "\"", "\"", ")", "\n", "v1beta1Cli", ",", "err", ":=", "dockerCli", ".", "stacksv1beta1", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "pods", ":=", "composeClient", ".", "Pods", "(", ")", "\n", "watcher", ":=", "&", "deployWatcher", "{", "stacks", ":", "v1beta1Cli", ",", "pods", ":", "pods", ",", "}", "\n", "statusUpdates", ":=", "make", "(", "chan", "serviceStatus", ")", "\n", "displayDone", ":=", "make", "(", "chan", "struct", "{", "}", ")", "\n", "go", "func", "(", ")", "{", "defer", "close", "(", "displayDone", ")", "\n", "display", ":=", "newStatusDisplay", "(", "dockerCli", ".", "Out", "(", ")", ")", "\n", "for", "status", ":=", "range", "statusUpdates", "{", "display", ".", "OnStatus", "(", "status", ")", "\n", "}", "\n", "}", "(", ")", "\n\n", "err", "=", "watcher", ".", "Watch", "(", "stack", ".", "Name", ",", "stack", ".", "getServices", "(", ")", ",", "statusUpdates", ")", "\n", "close", "(", "statusUpdates", ")", "\n", "<-", "displayDone", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "fmt", ".", "Fprintf", "(", "cmdOut", ",", "\"", "\\n", "\\n", "\\n", "\"", ",", "stack", ".", "Name", ")", "\n", "return", "nil", "\n\n", "}" ]
// RunDeploy is the kubernetes implementation of docker stack deploy
[ "RunDeploy", "is", "the", "kubernetes", "implementation", "of", "docker", "stack", "deploy" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/deploy.go#L15-L75
train
docker/cli
cli/command/network/prune.go
RunPrune
func RunPrune(dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error) { output, err := runPrune(dockerCli, pruneOptions{force: true, filter: filter}) return 0, output, err }
go
func RunPrune(dockerCli command.Cli, all bool, filter opts.FilterOpt) (uint64, string, error) { output, err := runPrune(dockerCli, pruneOptions{force: true, filter: filter}) return 0, output, err }
[ "func", "RunPrune", "(", "dockerCli", "command", ".", "Cli", ",", "all", "bool", ",", "filter", "opts", ".", "FilterOpt", ")", "(", "uint64", ",", "string", ",", "error", ")", "{", "output", ",", "err", ":=", "runPrune", "(", "dockerCli", ",", "pruneOptions", "{", "force", ":", "true", ",", "filter", ":", "filter", "}", ")", "\n", "return", "0", ",", "output", ",", "err", "\n", "}" ]
// RunPrune calls the Network Prune API // This returns the amount of space reclaimed and a detailed output string
[ "RunPrune", "calls", "the", "Network", "Prune", "API", "This", "returns", "the", "amount", "of", "space", "reclaimed", "and", "a", "detailed", "output", "string" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/network/prune.go#L73-L76
train
docker/cli
cli/command/image/list.go
NewImagesCommand
func NewImagesCommand(dockerCli command.Cli) *cobra.Command { options := imagesOptions{filter: opts.NewFilterOpt()} cmd := &cobra.Command{ Use: "images [OPTIONS] [REPOSITORY[:TAG]]", Short: "List images", Args: cli.RequiresMaxArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) > 0 { options.matchName = args[0] } return runImages(dockerCli, options) }, } flags := cmd.Flags() flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only show numeric IDs") flags.BoolVarP(&options.all, "all", "a", false, "Show all images (default hides intermediate images)") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output") flags.BoolVar(&options.showDigests, "digests", false, "Show digests") flags.StringVar(&options.format, "format", "", "Pretty-print images using a Go template") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") return cmd }
go
func NewImagesCommand(dockerCli command.Cli) *cobra.Command { options := imagesOptions{filter: opts.NewFilterOpt()} cmd := &cobra.Command{ Use: "images [OPTIONS] [REPOSITORY[:TAG]]", Short: "List images", Args: cli.RequiresMaxArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if len(args) > 0 { options.matchName = args[0] } return runImages(dockerCli, options) }, } flags := cmd.Flags() flags.BoolVarP(&options.quiet, "quiet", "q", false, "Only show numeric IDs") flags.BoolVarP(&options.all, "all", "a", false, "Show all images (default hides intermediate images)") flags.BoolVar(&options.noTrunc, "no-trunc", false, "Don't truncate output") flags.BoolVar(&options.showDigests, "digests", false, "Show digests") flags.StringVar(&options.format, "format", "", "Pretty-print images using a Go template") flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided") return cmd }
[ "func", "NewImagesCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "options", ":=", "imagesOptions", "{", "filter", ":", "opts", ".", "NewFilterOpt", "(", ")", "}", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "RequiresMaxArgs", "(", "1", ")", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "if", "len", "(", "args", ")", ">", "0", "{", "options", ".", "matchName", "=", "args", "[", "0", "]", "\n", "}", "\n", "return", "runImages", "(", "dockerCli", ",", "options", ")", "\n", "}", ",", "}", "\n\n", "flags", ":=", "cmd", ".", "Flags", "(", ")", "\n\n", "flags", ".", "BoolVarP", "(", "&", "options", ".", "quiet", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVarP", "(", "&", "options", ".", "all", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVar", "(", "&", "options", ".", "noTrunc", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVar", "(", "&", "options", ".", "showDigests", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVar", "(", "&", "options", ".", "format", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "VarP", "(", "&", "options", ".", "filter", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "return", "cmd", "\n", "}" ]
// NewImagesCommand creates a new `docker images` command
[ "NewImagesCommand", "creates", "a", "new", "docker", "images", "command" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/list.go#L26-L51
train
docker/cli
cli/command/config/formatter.go
NewFormat
func NewFormat(source string, quiet bool) formatter.Format { switch source { case formatter.PrettyFormatKey: return configInspectPrettyTemplate case formatter.TableFormatKey: if quiet { return formatter.DefaultQuietFormat } return defaultConfigTableFormat } return formatter.Format(source) }
go
func NewFormat(source string, quiet bool) formatter.Format { switch source { case formatter.PrettyFormatKey: return configInspectPrettyTemplate case formatter.TableFormatKey: if quiet { return formatter.DefaultQuietFormat } return defaultConfigTableFormat } return formatter.Format(source) }
[ "func", "NewFormat", "(", "source", "string", ",", "quiet", "bool", ")", "formatter", ".", "Format", "{", "switch", "source", "{", "case", "formatter", ".", "PrettyFormatKey", ":", "return", "configInspectPrettyTemplate", "\n", "case", "formatter", ".", "TableFormatKey", ":", "if", "quiet", "{", "return", "formatter", ".", "DefaultQuietFormat", "\n", "}", "\n", "return", "defaultConfigTableFormat", "\n", "}", "\n", "return", "formatter", ".", "Format", "(", "source", ")", "\n", "}" ]
// NewFormat returns a Format for rendering using a config Context
[ "NewFormat", "returns", "a", "Format", "for", "rendering", "using", "a", "config", "Context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/config/formatter.go#L34-L45
train
docker/cli
cli/command/config/formatter.go
InspectFormatWrite
func InspectFormatWrite(ctx formatter.Context, refs []string, getRef inspect.GetRefFunc) error { if ctx.Format != configInspectPrettyTemplate { return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef) } render := func(format func(subContext formatter.SubContext) error) error { for _, ref := range refs { configI, _, err := getRef(ref) if err != nil { return err } config, ok := configI.(swarm.Config) if !ok { return fmt.Errorf("got wrong object to inspect :%v", ok) } if err := format(&configInspectContext{Config: config}); err != nil { return err } } return nil } return ctx.Write(&configInspectContext{}, render) }
go
func InspectFormatWrite(ctx formatter.Context, refs []string, getRef inspect.GetRefFunc) error { if ctx.Format != configInspectPrettyTemplate { return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef) } render := func(format func(subContext formatter.SubContext) error) error { for _, ref := range refs { configI, _, err := getRef(ref) if err != nil { return err } config, ok := configI.(swarm.Config) if !ok { return fmt.Errorf("got wrong object to inspect :%v", ok) } if err := format(&configInspectContext{Config: config}); err != nil { return err } } return nil } return ctx.Write(&configInspectContext{}, render) }
[ "func", "InspectFormatWrite", "(", "ctx", "formatter", ".", "Context", ",", "refs", "[", "]", "string", ",", "getRef", "inspect", ".", "GetRefFunc", ")", "error", "{", "if", "ctx", ".", "Format", "!=", "configInspectPrettyTemplate", "{", "return", "inspect", ".", "Inspect", "(", "ctx", ".", "Output", ",", "refs", ",", "string", "(", "ctx", ".", "Format", ")", ",", "getRef", ")", "\n", "}", "\n", "render", ":=", "func", "(", "format", "func", "(", "subContext", "formatter", ".", "SubContext", ")", "error", ")", "error", "{", "for", "_", ",", "ref", ":=", "range", "refs", "{", "configI", ",", "_", ",", "err", ":=", "getRef", "(", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "config", ",", "ok", ":=", "configI", ".", "(", "swarm", ".", "Config", ")", "\n", "if", "!", "ok", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ok", ")", "\n", "}", "\n", "if", "err", ":=", "format", "(", "&", "configInspectContext", "{", "Config", ":", "config", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "return", "ctx", ".", "Write", "(", "&", "configInspectContext", "{", "}", ",", "render", ")", "\n", "}" ]
// InspectFormatWrite renders the context for a list of configs
[ "InspectFormatWrite", "renders", "the", "context", "for", "a", "list", "of", "configs" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/config/formatter.go#L119-L140
train
docker/cli
cli/command/formatter/disk_usage.go
NewDiskUsageFormat
func NewDiskUsageFormat(source string, verbose bool) Format { switch { case verbose && source == RawFormatKey: format := `{{range .Images}}type: Image ` + NewImageFormat(source, false, true) + ` {{end -}} {{range .Containers}}type: Container ` + NewContainerFormat(source, false, true) + ` {{end -}} {{range .Volumes}}type: Volume ` + NewVolumeFormat(source, false) + ` {{end -}} {{range .BuildCache}}type: Build Cache ` + NewBuildCacheFormat(source, false) + ` {{end -}}` return format case !verbose && source == TableFormatKey: return Format(defaultDiskUsageTableFormat) case !verbose && source == RawFormatKey: format := `type: {{.Type}} total: {{.TotalCount}} active: {{.Active}} size: {{.Size}} reclaimable: {{.Reclaimable}} ` return Format(format) default: return Format(source) } }
go
func NewDiskUsageFormat(source string, verbose bool) Format { switch { case verbose && source == RawFormatKey: format := `{{range .Images}}type: Image ` + NewImageFormat(source, false, true) + ` {{end -}} {{range .Containers}}type: Container ` + NewContainerFormat(source, false, true) + ` {{end -}} {{range .Volumes}}type: Volume ` + NewVolumeFormat(source, false) + ` {{end -}} {{range .BuildCache}}type: Build Cache ` + NewBuildCacheFormat(source, false) + ` {{end -}}` return format case !verbose && source == TableFormatKey: return Format(defaultDiskUsageTableFormat) case !verbose && source == RawFormatKey: format := `type: {{.Type}} total: {{.TotalCount}} active: {{.Active}} size: {{.Size}} reclaimable: {{.Reclaimable}} ` return Format(format) default: return Format(source) } }
[ "func", "NewDiskUsageFormat", "(", "source", "string", ",", "verbose", "bool", ")", "Format", "{", "switch", "{", "case", "verbose", "&&", "source", "==", "RawFormatKey", ":", "format", ":=", "`{{range .Images}}type: Image\n`", "+", "NewImageFormat", "(", "source", ",", "false", ",", "true", ")", "+", "`\n{{end -}}\n{{range .Containers}}type: Container\n`", "+", "NewContainerFormat", "(", "source", ",", "false", ",", "true", ")", "+", "`\n{{end -}}\n{{range .Volumes}}type: Volume\n`", "+", "NewVolumeFormat", "(", "source", ",", "false", ")", "+", "`\n{{end -}}\n{{range .BuildCache}}type: Build Cache\n`", "+", "NewBuildCacheFormat", "(", "source", ",", "false", ")", "+", "`\n{{end -}}`", "\n", "return", "format", "\n", "case", "!", "verbose", "&&", "source", "==", "TableFormatKey", ":", "return", "Format", "(", "defaultDiskUsageTableFormat", ")", "\n", "case", "!", "verbose", "&&", "source", "==", "RawFormatKey", ":", "format", ":=", "`type: {{.Type}}\ntotal: {{.TotalCount}}\nactive: {{.Active}}\nsize: {{.Size}}\nreclaimable: {{.Reclaimable}}\n`", "\n", "return", "Format", "(", "format", ")", "\n", "default", ":", "return", "Format", "(", "source", ")", "\n", "}", "\n", "}" ]
// NewDiskUsageFormat returns a format for rendering an DiskUsageContext
[ "NewDiskUsageFormat", "returns", "a", "format", "for", "rendering", "an", "DiskUsageContext" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/formatter/disk_usage.go#L52-L81
train
docker/cli
cli/command/container/diff.go
NewDiffCommand
func NewDiffCommand(dockerCli command.Cli) *cobra.Command { var opts diffOptions return &cobra.Command{ Use: "diff CONTAINER", Short: "Inspect changes to files or directories on a container's filesystem", Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.container = args[0] return runDiff(dockerCli, &opts) }, } }
go
func NewDiffCommand(dockerCli command.Cli) *cobra.Command { var opts diffOptions return &cobra.Command{ Use: "diff CONTAINER", Short: "Inspect changes to files or directories on a container's filesystem", Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.container = args[0] return runDiff(dockerCli, &opts) }, } }
[ "func", "NewDiffCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "opts", "diffOptions", "\n\n", "return", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "ExactArgs", "(", "1", ")", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "opts", ".", "container", "=", "args", "[", "0", "]", "\n", "return", "runDiff", "(", "dockerCli", ",", "&", "opts", ")", "\n", "}", ",", "}", "\n", "}" ]
// NewDiffCommand creates a new cobra.Command for `docker diff`
[ "NewDiffCommand", "creates", "a", "new", "cobra", ".", "Command", "for", "docker", "diff" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/diff.go#L18-L30
train
docker/cli
cli/compose/schema/bindata.go
_escDir
func _escDir(useLocal bool, name string) http.FileSystem { if useLocal { return _escDirectory{fs: _escLocal, name: name} } return _escDirectory{fs: _escStatic, name: name} }
go
func _escDir(useLocal bool, name string) http.FileSystem { if useLocal { return _escDirectory{fs: _escLocal, name: name} } return _escDirectory{fs: _escStatic, name: name} }
[ "func", "_escDir", "(", "useLocal", "bool", ",", "name", "string", ")", "http", ".", "FileSystem", "{", "if", "useLocal", "{", "return", "_escDirectory", "{", "fs", ":", "_escLocal", ",", "name", ":", "name", "}", "\n", "}", "\n", "return", "_escDirectory", "{", "fs", ":", "_escStatic", ",", "name", ":", "name", "}", "\n", "}" ]
// _escDir returns a http.Filesystem for the embedded assets on a given prefix dir. // If useLocal is true, the filesystem's contents are instead used.
[ "_escDir", "returns", "a", "http", ".", "Filesystem", "for", "the", "embedded", "assets", "on", "a", "given", "prefix", "dir", ".", "If", "useLocal", "is", "true", "the", "filesystem", "s", "contents", "are", "instead", "used", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/schema/bindata.go#L145-L150
train
docker/cli
cli/compose/schema/bindata.go
_escFSMustByte
func _escFSMustByte(useLocal bool, name string) []byte { b, err := _escFSByte(useLocal, name) if err != nil { panic(err) } return b }
go
func _escFSMustByte(useLocal bool, name string) []byte { b, err := _escFSByte(useLocal, name) if err != nil { panic(err) } return b }
[ "func", "_escFSMustByte", "(", "useLocal", "bool", ",", "name", "string", ")", "[", "]", "byte", "{", "b", ",", "err", ":=", "_escFSByte", "(", "useLocal", ",", "name", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "b", "\n", "}" ]
// _escFSMustByte is the same as _escFSByte, but panics if name is not present.
[ "_escFSMustByte", "is", "the", "same", "as", "_escFSByte", "but", "panics", "if", "name", "is", "not", "present", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/schema/bindata.go#L172-L178
train
docker/cli
cli/compose/schema/bindata.go
_escFSString
func _escFSString(useLocal bool, name string) (string, error) { b, err := _escFSByte(useLocal, name) return string(b), err }
go
func _escFSString(useLocal bool, name string) (string, error) { b, err := _escFSByte(useLocal, name) return string(b), err }
[ "func", "_escFSString", "(", "useLocal", "bool", ",", "name", "string", ")", "(", "string", ",", "error", ")", "{", "b", ",", "err", ":=", "_escFSByte", "(", "useLocal", ",", "name", ")", "\n", "return", "string", "(", "b", ")", ",", "err", "\n", "}" ]
// _escFSString is the string version of _escFSByte.
[ "_escFSString", "is", "the", "string", "version", "of", "_escFSByte", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/schema/bindata.go#L181-L184
train
docker/cli
cli/compose/schema/bindata.go
_escFSMustString
func _escFSMustString(useLocal bool, name string) string { return string(_escFSMustByte(useLocal, name)) }
go
func _escFSMustString(useLocal bool, name string) string { return string(_escFSMustByte(useLocal, name)) }
[ "func", "_escFSMustString", "(", "useLocal", "bool", ",", "name", "string", ")", "string", "{", "return", "string", "(", "_escFSMustByte", "(", "useLocal", ",", "name", ")", ")", "\n", "}" ]
// _escFSMustString is the string version of _escFSMustByte.
[ "_escFSMustString", "is", "the", "string", "version", "of", "_escFSMustByte", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/schema/bindata.go#L187-L189
train
docker/cli
cli/flags/common.go
InstallFlags
func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) { if dockerCertPath == "" { dockerCertPath = cliconfig.Dir() } flags.BoolVarP(&commonOpts.Debug, "debug", "D", false, "Enable debug mode") flags.StringVarP(&commonOpts.LogLevel, "log-level", "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`) flags.BoolVar(&commonOpts.TLS, "tls", dockerTLS, "Use TLS; implied by --tlsverify") flags.BoolVar(&commonOpts.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote") // TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file") commonOpts.TLSOptions = &tlsconfig.Options{ CAFile: filepath.Join(dockerCertPath, DefaultCaFile), CertFile: filepath.Join(dockerCertPath, DefaultCertFile), KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile), } tlsOptions := commonOpts.TLSOptions flags.Var(opts.NewQuotedString(&tlsOptions.CAFile), "tlscacert", "Trust certs signed only by this CA") flags.Var(opts.NewQuotedString(&tlsOptions.CertFile), "tlscert", "Path to TLS certificate file") flags.Var(opts.NewQuotedString(&tlsOptions.KeyFile), "tlskey", "Path to TLS key file") // opts.ValidateHost is not used here, so as to allow connection helpers hostOpt := opts.NewNamedListOptsRef("hosts", &commonOpts.Hosts, nil) flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to") flags.StringVarP(&commonOpts.Context, "context", "c", "", `Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")`) }
go
func (commonOpts *CommonOptions) InstallFlags(flags *pflag.FlagSet) { if dockerCertPath == "" { dockerCertPath = cliconfig.Dir() } flags.BoolVarP(&commonOpts.Debug, "debug", "D", false, "Enable debug mode") flags.StringVarP(&commonOpts.LogLevel, "log-level", "l", "info", `Set the logging level ("debug"|"info"|"warn"|"error"|"fatal")`) flags.BoolVar(&commonOpts.TLS, "tls", dockerTLS, "Use TLS; implied by --tlsverify") flags.BoolVar(&commonOpts.TLSVerify, FlagTLSVerify, dockerTLSVerify, "Use TLS and verify the remote") // TODO use flag flags.String("identity"}, "i", "", "Path to libtrust key file") commonOpts.TLSOptions = &tlsconfig.Options{ CAFile: filepath.Join(dockerCertPath, DefaultCaFile), CertFile: filepath.Join(dockerCertPath, DefaultCertFile), KeyFile: filepath.Join(dockerCertPath, DefaultKeyFile), } tlsOptions := commonOpts.TLSOptions flags.Var(opts.NewQuotedString(&tlsOptions.CAFile), "tlscacert", "Trust certs signed only by this CA") flags.Var(opts.NewQuotedString(&tlsOptions.CertFile), "tlscert", "Path to TLS certificate file") flags.Var(opts.NewQuotedString(&tlsOptions.KeyFile), "tlskey", "Path to TLS key file") // opts.ValidateHost is not used here, so as to allow connection helpers hostOpt := opts.NewNamedListOptsRef("hosts", &commonOpts.Hosts, nil) flags.VarP(hostOpt, "host", "H", "Daemon socket(s) to connect to") flags.StringVarP(&commonOpts.Context, "context", "c", "", `Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")`) }
[ "func", "(", "commonOpts", "*", "CommonOptions", ")", "InstallFlags", "(", "flags", "*", "pflag", ".", "FlagSet", ")", "{", "if", "dockerCertPath", "==", "\"", "\"", "{", "dockerCertPath", "=", "cliconfig", ".", "Dir", "(", ")", "\n", "}", "\n\n", "flags", ".", "BoolVarP", "(", "&", "commonOpts", ".", "Debug", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVarP", "(", "&", "commonOpts", ".", "LogLevel", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "`Set the logging level (\"debug\"|\"info\"|\"warn\"|\"error\"|\"fatal\")`", ")", "\n", "flags", ".", "BoolVar", "(", "&", "commonOpts", ".", "TLS", ",", "\"", "\"", ",", "dockerTLS", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVar", "(", "&", "commonOpts", ".", "TLSVerify", ",", "FlagTLSVerify", ",", "dockerTLSVerify", ",", "\"", "\"", ")", "\n\n", "// TODO use flag flags.String(\"identity\"}, \"i\", \"\", \"Path to libtrust key file\")", "commonOpts", ".", "TLSOptions", "=", "&", "tlsconfig", ".", "Options", "{", "CAFile", ":", "filepath", ".", "Join", "(", "dockerCertPath", ",", "DefaultCaFile", ")", ",", "CertFile", ":", "filepath", ".", "Join", "(", "dockerCertPath", ",", "DefaultCertFile", ")", ",", "KeyFile", ":", "filepath", ".", "Join", "(", "dockerCertPath", ",", "DefaultKeyFile", ")", ",", "}", "\n", "tlsOptions", ":=", "commonOpts", ".", "TLSOptions", "\n", "flags", ".", "Var", "(", "opts", ".", "NewQuotedString", "(", "&", "tlsOptions", ".", "CAFile", ")", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "Var", "(", "opts", ".", "NewQuotedString", "(", "&", "tlsOptions", ".", "CertFile", ")", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "Var", "(", "opts", ".", "NewQuotedString", "(", "&", "tlsOptions", ".", "KeyFile", ")", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "// opts.ValidateHost is not used here, so as to allow connection helpers", "hostOpt", ":=", "opts", ".", "NewNamedListOptsRef", "(", "\"", "\"", ",", "&", "commonOpts", ".", "Hosts", ",", "nil", ")", "\n", "flags", ".", "VarP", "(", "hostOpt", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVarP", "(", "&", "commonOpts", ".", "Context", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "`Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with \"docker context use\")`", ")", "\n", "}" ]
// InstallFlags adds flags for the common options on the FlagSet
[ "InstallFlags", "adds", "flags", "for", "the", "common", "options", "on", "the", "FlagSet" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/flags/common.go#L49-L76
train
docker/cli
cli/flags/common.go
SetDefaultOptions
func (commonOpts *CommonOptions) SetDefaultOptions(flags *pflag.FlagSet) { // Regardless of whether the user sets it to true or false, if they // specify --tlsverify at all then we need to turn on TLS // TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need // to check that here as well if flags.Changed(FlagTLSVerify) || commonOpts.TLSVerify { commonOpts.TLS = true } if !commonOpts.TLS { commonOpts.TLSOptions = nil } else { tlsOptions := commonOpts.TLSOptions tlsOptions.InsecureSkipVerify = !commonOpts.TLSVerify // Reset CertFile and KeyFile to empty string if the user did not specify // the respective flags and the respective default files were not found. if !flags.Changed("tlscert") { if _, err := os.Stat(tlsOptions.CertFile); os.IsNotExist(err) { tlsOptions.CertFile = "" } } if !flags.Changed("tlskey") { if _, err := os.Stat(tlsOptions.KeyFile); os.IsNotExist(err) { tlsOptions.KeyFile = "" } } } }
go
func (commonOpts *CommonOptions) SetDefaultOptions(flags *pflag.FlagSet) { // Regardless of whether the user sets it to true or false, if they // specify --tlsverify at all then we need to turn on TLS // TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need // to check that here as well if flags.Changed(FlagTLSVerify) || commonOpts.TLSVerify { commonOpts.TLS = true } if !commonOpts.TLS { commonOpts.TLSOptions = nil } else { tlsOptions := commonOpts.TLSOptions tlsOptions.InsecureSkipVerify = !commonOpts.TLSVerify // Reset CertFile and KeyFile to empty string if the user did not specify // the respective flags and the respective default files were not found. if !flags.Changed("tlscert") { if _, err := os.Stat(tlsOptions.CertFile); os.IsNotExist(err) { tlsOptions.CertFile = "" } } if !flags.Changed("tlskey") { if _, err := os.Stat(tlsOptions.KeyFile); os.IsNotExist(err) { tlsOptions.KeyFile = "" } } } }
[ "func", "(", "commonOpts", "*", "CommonOptions", ")", "SetDefaultOptions", "(", "flags", "*", "pflag", ".", "FlagSet", ")", "{", "// Regardless of whether the user sets it to true or false, if they", "// specify --tlsverify at all then we need to turn on TLS", "// TLSVerify can be true even if not set due to DOCKER_TLS_VERIFY env var, so we need", "// to check that here as well", "if", "flags", ".", "Changed", "(", "FlagTLSVerify", ")", "||", "commonOpts", ".", "TLSVerify", "{", "commonOpts", ".", "TLS", "=", "true", "\n", "}", "\n\n", "if", "!", "commonOpts", ".", "TLS", "{", "commonOpts", ".", "TLSOptions", "=", "nil", "\n", "}", "else", "{", "tlsOptions", ":=", "commonOpts", ".", "TLSOptions", "\n", "tlsOptions", ".", "InsecureSkipVerify", "=", "!", "commonOpts", ".", "TLSVerify", "\n\n", "// Reset CertFile and KeyFile to empty string if the user did not specify", "// the respective flags and the respective default files were not found.", "if", "!", "flags", ".", "Changed", "(", "\"", "\"", ")", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "tlsOptions", ".", "CertFile", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "tlsOptions", ".", "CertFile", "=", "\"", "\"", "\n", "}", "\n", "}", "\n", "if", "!", "flags", ".", "Changed", "(", "\"", "\"", ")", "{", "if", "_", ",", "err", ":=", "os", ".", "Stat", "(", "tlsOptions", ".", "KeyFile", ")", ";", "os", ".", "IsNotExist", "(", "err", ")", "{", "tlsOptions", ".", "KeyFile", "=", "\"", "\"", "\n", "}", "\n", "}", "\n", "}", "\n", "}" ]
// SetDefaultOptions sets default values for options after flag parsing is // complete
[ "SetDefaultOptions", "sets", "default", "values", "for", "options", "after", "flag", "parsing", "is", "complete" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/flags/common.go#L80-L108
train
docker/cli
cli/context/tlsdata.go
ToStoreTLSData
func (data *TLSData) ToStoreTLSData() *store.EndpointTLSData { if data == nil { return nil } result := store.EndpointTLSData{ Files: make(map[string][]byte), } if data.CA != nil { result.Files[caKey] = data.CA } if data.Cert != nil { result.Files[certKey] = data.Cert } if data.Key != nil { result.Files[keyKey] = data.Key } return &result }
go
func (data *TLSData) ToStoreTLSData() *store.EndpointTLSData { if data == nil { return nil } result := store.EndpointTLSData{ Files: make(map[string][]byte), } if data.CA != nil { result.Files[caKey] = data.CA } if data.Cert != nil { result.Files[certKey] = data.Cert } if data.Key != nil { result.Files[keyKey] = data.Key } return &result }
[ "func", "(", "data", "*", "TLSData", ")", "ToStoreTLSData", "(", ")", "*", "store", ".", "EndpointTLSData", "{", "if", "data", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "result", ":=", "store", ".", "EndpointTLSData", "{", "Files", ":", "make", "(", "map", "[", "string", "]", "[", "]", "byte", ")", ",", "}", "\n", "if", "data", ".", "CA", "!=", "nil", "{", "result", ".", "Files", "[", "caKey", "]", "=", "data", ".", "CA", "\n", "}", "\n", "if", "data", ".", "Cert", "!=", "nil", "{", "result", ".", "Files", "[", "certKey", "]", "=", "data", ".", "Cert", "\n", "}", "\n", "if", "data", ".", "Key", "!=", "nil", "{", "result", ".", "Files", "[", "keyKey", "]", "=", "data", ".", "Key", "\n", "}", "\n", "return", "&", "result", "\n", "}" ]
// ToStoreTLSData converts TLSData to the store representation
[ "ToStoreTLSData", "converts", "TLSData", "to", "the", "store", "representation" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/context/tlsdata.go#L25-L42
train
docker/cli
cli/context/tlsdata.go
LoadTLSData
func LoadTLSData(s store.Reader, contextName, endpointName string) (*TLSData, error) { tlsFiles, err := s.ListTLSFiles(contextName) if err != nil { return nil, errors.Wrapf(err, "failed to retrieve context tls files for context %q", contextName) } if epTLSFiles, ok := tlsFiles[endpointName]; ok { var tlsData TLSData for _, f := range epTLSFiles { data, err := s.GetTLSData(contextName, endpointName, f) if err != nil { return nil, errors.Wrapf(err, "failed to retrieve context tls data for file %q of context %q", f, contextName) } switch f { case caKey: tlsData.CA = data case certKey: tlsData.Cert = data case keyKey: tlsData.Key = data default: logrus.Warnf("unknown file %s in context %s tls bundle", f, contextName) } } return &tlsData, nil } return nil, nil }
go
func LoadTLSData(s store.Reader, contextName, endpointName string) (*TLSData, error) { tlsFiles, err := s.ListTLSFiles(contextName) if err != nil { return nil, errors.Wrapf(err, "failed to retrieve context tls files for context %q", contextName) } if epTLSFiles, ok := tlsFiles[endpointName]; ok { var tlsData TLSData for _, f := range epTLSFiles { data, err := s.GetTLSData(contextName, endpointName, f) if err != nil { return nil, errors.Wrapf(err, "failed to retrieve context tls data for file %q of context %q", f, contextName) } switch f { case caKey: tlsData.CA = data case certKey: tlsData.Cert = data case keyKey: tlsData.Key = data default: logrus.Warnf("unknown file %s in context %s tls bundle", f, contextName) } } return &tlsData, nil } return nil, nil }
[ "func", "LoadTLSData", "(", "s", "store", ".", "Reader", ",", "contextName", ",", "endpointName", "string", ")", "(", "*", "TLSData", ",", "error", ")", "{", "tlsFiles", ",", "err", ":=", "s", ".", "ListTLSFiles", "(", "contextName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "contextName", ")", "\n", "}", "\n", "if", "epTLSFiles", ",", "ok", ":=", "tlsFiles", "[", "endpointName", "]", ";", "ok", "{", "var", "tlsData", "TLSData", "\n", "for", "_", ",", "f", ":=", "range", "epTLSFiles", "{", "data", ",", "err", ":=", "s", ".", "GetTLSData", "(", "contextName", ",", "endpointName", ",", "f", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "f", ",", "contextName", ")", "\n", "}", "\n", "switch", "f", "{", "case", "caKey", ":", "tlsData", ".", "CA", "=", "data", "\n", "case", "certKey", ":", "tlsData", ".", "Cert", "=", "data", "\n", "case", "keyKey", ":", "tlsData", ".", "Key", "=", "data", "\n", "default", ":", "logrus", ".", "Warnf", "(", "\"", "\"", ",", "f", ",", "contextName", ")", "\n", "}", "\n", "}", "\n", "return", "&", "tlsData", ",", "nil", "\n", "}", "\n", "return", "nil", ",", "nil", "\n", "}" ]
// LoadTLSData loads TLS data from the store
[ "LoadTLSData", "loads", "TLS", "data", "from", "the", "store" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/context/tlsdata.go#L45-L71
train
docker/cli
cli/command/image/prune.go
NewPruneCommand
func NewPruneCommand(dockerCli command.Cli) *cobra.Command { options := pruneOptions{filter: opts.NewFilterOpt()} cmd := &cobra.Command{ Use: "prune [OPTIONS]", Short: "Remove unused images", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { spaceReclaimed, output, err := runPrune(dockerCli, options) if err != nil { return err } if output != "" { fmt.Fprintln(dockerCli.Out(), output) } fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) return nil }, Annotations: map[string]string{"version": "1.25"}, } flags := cmd.Flags() flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images, not just dangling ones") flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')") return cmd }
go
func NewPruneCommand(dockerCli command.Cli) *cobra.Command { options := pruneOptions{filter: opts.NewFilterOpt()} cmd := &cobra.Command{ Use: "prune [OPTIONS]", Short: "Remove unused images", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { spaceReclaimed, output, err := runPrune(dockerCli, options) if err != nil { return err } if output != "" { fmt.Fprintln(dockerCli.Out(), output) } fmt.Fprintln(dockerCli.Out(), "Total reclaimed space:", units.HumanSize(float64(spaceReclaimed))) return nil }, Annotations: map[string]string{"version": "1.25"}, } flags := cmd.Flags() flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation") flags.BoolVarP(&options.all, "all", "a", false, "Remove all unused images, not just dangling ones") flags.Var(&options.filter, "filter", "Provide filter values (e.g. 'until=<timestamp>')") return cmd }
[ "func", "NewPruneCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "options", ":=", "pruneOptions", "{", "filter", ":", "opts", ".", "NewFilterOpt", "(", ")", "}", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "spaceReclaimed", ",", "output", ",", "err", ":=", "runPrune", "(", "dockerCli", ",", "options", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "output", "!=", "\"", "\"", "{", "fmt", ".", "Fprintln", "(", "dockerCli", ".", "Out", "(", ")", ",", "output", ")", "\n", "}", "\n", "fmt", ".", "Fprintln", "(", "dockerCli", ".", "Out", "(", ")", ",", "\"", "\"", ",", "units", ".", "HumanSize", "(", "float64", "(", "spaceReclaimed", ")", ")", ")", "\n", "return", "nil", "\n", "}", ",", "Annotations", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", "}", ",", "}", "\n\n", "flags", ":=", "cmd", ".", "Flags", "(", ")", "\n", "flags", ".", "BoolVarP", "(", "&", "options", ".", "force", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVarP", "(", "&", "options", ".", "all", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "Var", "(", "&", "options", ".", "filter", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "return", "cmd", "\n", "}" ]
// NewPruneCommand returns a new cobra prune command for images
[ "NewPruneCommand", "returns", "a", "new", "cobra", "prune", "command", "for", "images" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/prune.go#L22-L49
train
docker/cli
cli/command/stack/kubernetes/client.go
NewFactory
func NewFactory(namespace string, config *restclient.Config, clientSet *kubeclient.Clientset, experimental bool) (*Factory, error) { coreClientSet, err := corev1.NewForConfig(config) if err != nil { return nil, err } appsClientSet, err := appsv1beta2.NewForConfig(config) if err != nil { return nil, err } return &Factory{ namespace: namespace, config: config, coreClientSet: coreClientSet, appsClientSet: appsClientSet, clientSet: clientSet, experimental: experimental, }, nil }
go
func NewFactory(namespace string, config *restclient.Config, clientSet *kubeclient.Clientset, experimental bool) (*Factory, error) { coreClientSet, err := corev1.NewForConfig(config) if err != nil { return nil, err } appsClientSet, err := appsv1beta2.NewForConfig(config) if err != nil { return nil, err } return &Factory{ namespace: namespace, config: config, coreClientSet: coreClientSet, appsClientSet: appsClientSet, clientSet: clientSet, experimental: experimental, }, nil }
[ "func", "NewFactory", "(", "namespace", "string", ",", "config", "*", "restclient", ".", "Config", ",", "clientSet", "*", "kubeclient", ".", "Clientset", ",", "experimental", "bool", ")", "(", "*", "Factory", ",", "error", ")", "{", "coreClientSet", ",", "err", ":=", "corev1", ".", "NewForConfig", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "appsClientSet", ",", "err", ":=", "appsv1beta2", ".", "NewForConfig", "(", "config", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "&", "Factory", "{", "namespace", ":", "namespace", ",", "config", ":", "config", ",", "coreClientSet", ":", "coreClientSet", ",", "appsClientSet", ":", "appsClientSet", ",", "clientSet", ":", "clientSet", ",", "experimental", ":", "experimental", ",", "}", ",", "nil", "\n", "}" ]
// NewFactory creates a kubernetes client factory
[ "NewFactory", "creates", "a", "kubernetes", "client", "factory" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L25-L44
train
docker/cli
cli/command/stack/kubernetes/client.go
ConfigMaps
func (s *Factory) ConfigMaps() corev1.ConfigMapInterface { return s.coreClientSet.ConfigMaps(s.namespace) }
go
func (s *Factory) ConfigMaps() corev1.ConfigMapInterface { return s.coreClientSet.ConfigMaps(s.namespace) }
[ "func", "(", "s", "*", "Factory", ")", "ConfigMaps", "(", ")", "corev1", ".", "ConfigMapInterface", "{", "return", "s", ".", "coreClientSet", ".", "ConfigMaps", "(", "s", ".", "namespace", ")", "\n", "}" ]
// ConfigMaps returns a client for kubernetes's config maps
[ "ConfigMaps", "returns", "a", "client", "for", "kubernetes", "s", "config", "maps" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L47-L49
train
docker/cli
cli/command/stack/kubernetes/client.go
Secrets
func (s *Factory) Secrets() corev1.SecretInterface { return s.coreClientSet.Secrets(s.namespace) }
go
func (s *Factory) Secrets() corev1.SecretInterface { return s.coreClientSet.Secrets(s.namespace) }
[ "func", "(", "s", "*", "Factory", ")", "Secrets", "(", ")", "corev1", ".", "SecretInterface", "{", "return", "s", ".", "coreClientSet", ".", "Secrets", "(", "s", ".", "namespace", ")", "\n", "}" ]
// Secrets returns a client for kubernetes's secrets
[ "Secrets", "returns", "a", "client", "for", "kubernetes", "s", "secrets" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L52-L54
train
docker/cli
cli/command/stack/kubernetes/client.go
Services
func (s *Factory) Services() corev1.ServiceInterface { return s.coreClientSet.Services(s.namespace) }
go
func (s *Factory) Services() corev1.ServiceInterface { return s.coreClientSet.Services(s.namespace) }
[ "func", "(", "s", "*", "Factory", ")", "Services", "(", ")", "corev1", ".", "ServiceInterface", "{", "return", "s", ".", "coreClientSet", ".", "Services", "(", "s", ".", "namespace", ")", "\n", "}" ]
// Services returns a client for kubernetes's secrets
[ "Services", "returns", "a", "client", "for", "kubernetes", "s", "secrets" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L57-L59
train
docker/cli
cli/command/stack/kubernetes/client.go
Pods
func (s *Factory) Pods() corev1.PodInterface { return s.coreClientSet.Pods(s.namespace) }
go
func (s *Factory) Pods() corev1.PodInterface { return s.coreClientSet.Pods(s.namespace) }
[ "func", "(", "s", "*", "Factory", ")", "Pods", "(", ")", "corev1", ".", "PodInterface", "{", "return", "s", ".", "coreClientSet", ".", "Pods", "(", "s", ".", "namespace", ")", "\n", "}" ]
// Pods returns a client for kubernetes's pods
[ "Pods", "returns", "a", "client", "for", "kubernetes", "s", "pods" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L62-L64
train
docker/cli
cli/command/stack/kubernetes/client.go
ReplicationControllers
func (s *Factory) ReplicationControllers() corev1.ReplicationControllerInterface { return s.coreClientSet.ReplicationControllers(s.namespace) }
go
func (s *Factory) ReplicationControllers() corev1.ReplicationControllerInterface { return s.coreClientSet.ReplicationControllers(s.namespace) }
[ "func", "(", "s", "*", "Factory", ")", "ReplicationControllers", "(", ")", "corev1", ".", "ReplicationControllerInterface", "{", "return", "s", ".", "coreClientSet", ".", "ReplicationControllers", "(", "s", ".", "namespace", ")", "\n", "}" ]
// ReplicationControllers returns a client for kubernetes replication controllers
[ "ReplicationControllers", "returns", "a", "client", "for", "kubernetes", "replication", "controllers" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L72-L74
train
docker/cli
cli/command/stack/kubernetes/client.go
ReplicaSets
func (s *Factory) ReplicaSets() typesappsv1beta2.ReplicaSetInterface { return s.appsClientSet.ReplicaSets(s.namespace) }
go
func (s *Factory) ReplicaSets() typesappsv1beta2.ReplicaSetInterface { return s.appsClientSet.ReplicaSets(s.namespace) }
[ "func", "(", "s", "*", "Factory", ")", "ReplicaSets", "(", ")", "typesappsv1beta2", ".", "ReplicaSetInterface", "{", "return", "s", ".", "appsClientSet", ".", "ReplicaSets", "(", "s", ".", "namespace", ")", "\n", "}" ]
// ReplicaSets returns a client for kubernetes replace sets
[ "ReplicaSets", "returns", "a", "client", "for", "kubernetes", "replace", "sets" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L77-L79
train
docker/cli
cli/command/stack/kubernetes/client.go
DaemonSets
func (s *Factory) DaemonSets() typesappsv1beta2.DaemonSetInterface { return s.appsClientSet.DaemonSets(s.namespace) }
go
func (s *Factory) DaemonSets() typesappsv1beta2.DaemonSetInterface { return s.appsClientSet.DaemonSets(s.namespace) }
[ "func", "(", "s", "*", "Factory", ")", "DaemonSets", "(", ")", "typesappsv1beta2", ".", "DaemonSetInterface", "{", "return", "s", ".", "appsClientSet", ".", "DaemonSets", "(", "s", ".", "namespace", ")", "\n", "}" ]
// DaemonSets returns a client for kubernetes daemon sets
[ "DaemonSets", "returns", "a", "client", "for", "kubernetes", "daemon", "sets" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L82-L84
train
docker/cli
cli/command/stack/kubernetes/client.go
Stacks
func (s *Factory) Stacks(allNamespaces bool) (StackClient, error) { version, err := kubernetes.GetStackAPIVersion(s.clientSet.Discovery(), s.experimental) if err != nil { return nil, err } namespace := s.namespace if allNamespaces { namespace = metav1.NamespaceAll } switch version { case kubernetes.StackAPIV1Beta1: return newStackV1Beta1(s.config, namespace) case kubernetes.StackAPIV1Beta2: return newStackV1Beta2(s.config, namespace) case kubernetes.StackAPIV1Alpha3: return newStackV1Alpha3(s.config, namespace) default: return nil, errors.Errorf("unsupported stack API version: %q", version) } }
go
func (s *Factory) Stacks(allNamespaces bool) (StackClient, error) { version, err := kubernetes.GetStackAPIVersion(s.clientSet.Discovery(), s.experimental) if err != nil { return nil, err } namespace := s.namespace if allNamespaces { namespace = metav1.NamespaceAll } switch version { case kubernetes.StackAPIV1Beta1: return newStackV1Beta1(s.config, namespace) case kubernetes.StackAPIV1Beta2: return newStackV1Beta2(s.config, namespace) case kubernetes.StackAPIV1Alpha3: return newStackV1Alpha3(s.config, namespace) default: return nil, errors.Errorf("unsupported stack API version: %q", version) } }
[ "func", "(", "s", "*", "Factory", ")", "Stacks", "(", "allNamespaces", "bool", ")", "(", "StackClient", ",", "error", ")", "{", "version", ",", "err", ":=", "kubernetes", ".", "GetStackAPIVersion", "(", "s", ".", "clientSet", ".", "Discovery", "(", ")", ",", "s", ".", "experimental", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "namespace", ":=", "s", ".", "namespace", "\n", "if", "allNamespaces", "{", "namespace", "=", "metav1", ".", "NamespaceAll", "\n", "}", "\n\n", "switch", "version", "{", "case", "kubernetes", ".", "StackAPIV1Beta1", ":", "return", "newStackV1Beta1", "(", "s", ".", "config", ",", "namespace", ")", "\n", "case", "kubernetes", ".", "StackAPIV1Beta2", ":", "return", "newStackV1Beta2", "(", "s", ".", "config", ",", "namespace", ")", "\n", "case", "kubernetes", ".", "StackAPIV1Alpha3", ":", "return", "newStackV1Alpha3", "(", "s", ".", "config", ",", "namespace", ")", "\n", "default", ":", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "version", ")", "\n", "}", "\n", "}" ]
// Stacks returns a client for Docker's Stack on Kubernetes
[ "Stacks", "returns", "a", "client", "for", "Docker", "s", "Stack", "on", "Kubernetes" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/client.go#L87-L107
train
docker/cli
cli/command/trust.go
AddTrustVerificationFlags
func AddTrustVerificationFlags(fs *pflag.FlagSet, v *bool, trusted bool) { fs.BoolVar(v, "disable-content-trust", !trusted, "Skip image verification") }
go
func AddTrustVerificationFlags(fs *pflag.FlagSet, v *bool, trusted bool) { fs.BoolVar(v, "disable-content-trust", !trusted, "Skip image verification") }
[ "func", "AddTrustVerificationFlags", "(", "fs", "*", "pflag", ".", "FlagSet", ",", "v", "*", "bool", ",", "trusted", "bool", ")", "{", "fs", ".", "BoolVar", "(", "v", ",", "\"", "\"", ",", "!", "trusted", ",", "\"", "\"", ")", "\n", "}" ]
// AddTrustVerificationFlags adds content trust flags to the provided flagset
[ "AddTrustVerificationFlags", "adds", "content", "trust", "flags", "to", "the", "provided", "flagset" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust.go#L8-L10
train
docker/cli
cli/command/trust.go
AddTrustSigningFlags
func AddTrustSigningFlags(fs *pflag.FlagSet, v *bool, trusted bool) { fs.BoolVar(v, "disable-content-trust", !trusted, "Skip image signing") }
go
func AddTrustSigningFlags(fs *pflag.FlagSet, v *bool, trusted bool) { fs.BoolVar(v, "disable-content-trust", !trusted, "Skip image signing") }
[ "func", "AddTrustSigningFlags", "(", "fs", "*", "pflag", ".", "FlagSet", ",", "v", "*", "bool", ",", "trusted", "bool", ")", "{", "fs", ".", "BoolVar", "(", "v", ",", "\"", "\"", ",", "!", "trusted", ",", "\"", "\"", ")", "\n", "}" ]
// AddTrustSigningFlags adds "signing" flags to the provided flagset
[ "AddTrustSigningFlags", "adds", "signing", "flags", "to", "the", "provided", "flagset" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust.go#L13-L15
train
docker/cli
cli/command/engine/updates.go
NewUpdatesFormat
func NewUpdatesFormat(source string, quiet bool) formatter.Format { switch source { case formatter.TableFormatKey: if quiet { return defaultUpdatesQuietFormat } return defaultUpdatesTableFormat case formatter.RawFormatKey: if quiet { return `update_version: {{.Version}}` } return `update_version: {{.Version}}\ntype: {{.Type}}\nnotes: {{.Notes}}\n` } return formatter.Format(source) }
go
func NewUpdatesFormat(source string, quiet bool) formatter.Format { switch source { case formatter.TableFormatKey: if quiet { return defaultUpdatesQuietFormat } return defaultUpdatesTableFormat case formatter.RawFormatKey: if quiet { return `update_version: {{.Version}}` } return `update_version: {{.Version}}\ntype: {{.Type}}\nnotes: {{.Notes}}\n` } return formatter.Format(source) }
[ "func", "NewUpdatesFormat", "(", "source", "string", ",", "quiet", "bool", ")", "formatter", ".", "Format", "{", "switch", "source", "{", "case", "formatter", ".", "TableFormatKey", ":", "if", "quiet", "{", "return", "defaultUpdatesQuietFormat", "\n", "}", "\n", "return", "defaultUpdatesTableFormat", "\n", "case", "formatter", ".", "RawFormatKey", ":", "if", "quiet", "{", "return", "`update_version: {{.Version}}`", "\n", "}", "\n", "return", "`update_version: {{.Version}}\\ntype: {{.Type}}\\nnotes: {{.Notes}}\\n`", "\n", "}", "\n", "return", "formatter", ".", "Format", "(", "source", ")", "\n", "}" ]
// NewUpdatesFormat returns a Format for rendering using a updates context
[ "NewUpdatesFormat", "returns", "a", "Format", "for", "rendering", "using", "a", "updates", "context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/engine/updates.go#L18-L32
train
docker/cli
cli/command/engine/updates.go
UpdatesWrite
func UpdatesWrite(ctx formatter.Context, availableUpdates []clitypes.Update) error { render := func(format func(subContext formatter.SubContext) error) error { for _, update := range availableUpdates { updatesCtx := &updateContext{trunc: ctx.Trunc, u: update} if err := format(updatesCtx); err != nil { return err } } return nil } updatesCtx := updateContext{} updatesCtx.Header = map[string]string{ "Type": updatesTypeHeader, "Version": versionHeader, "Notes": notesHeader, } return ctx.Write(&updatesCtx, render) }
go
func UpdatesWrite(ctx formatter.Context, availableUpdates []clitypes.Update) error { render := func(format func(subContext formatter.SubContext) error) error { for _, update := range availableUpdates { updatesCtx := &updateContext{trunc: ctx.Trunc, u: update} if err := format(updatesCtx); err != nil { return err } } return nil } updatesCtx := updateContext{} updatesCtx.Header = map[string]string{ "Type": updatesTypeHeader, "Version": versionHeader, "Notes": notesHeader, } return ctx.Write(&updatesCtx, render) }
[ "func", "UpdatesWrite", "(", "ctx", "formatter", ".", "Context", ",", "availableUpdates", "[", "]", "clitypes", ".", "Update", ")", "error", "{", "render", ":=", "func", "(", "format", "func", "(", "subContext", "formatter", ".", "SubContext", ")", "error", ")", "error", "{", "for", "_", ",", "update", ":=", "range", "availableUpdates", "{", "updatesCtx", ":=", "&", "updateContext", "{", "trunc", ":", "ctx", ".", "Trunc", ",", "u", ":", "update", "}", "\n", "if", "err", ":=", "format", "(", "updatesCtx", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "updatesCtx", ":=", "updateContext", "{", "}", "\n", "updatesCtx", ".", "Header", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "updatesTypeHeader", ",", "\"", "\"", ":", "versionHeader", ",", "\"", "\"", ":", "notesHeader", ",", "}", "\n", "return", "ctx", ".", "Write", "(", "&", "updatesCtx", ",", "render", ")", "\n", "}" ]
// UpdatesWrite writes the context
[ "UpdatesWrite", "writes", "the", "context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/engine/updates.go#L35-L52
train
docker/cli
cli/command/container/wait.go
NewWaitCommand
func NewWaitCommand(dockerCli command.Cli) *cobra.Command { var opts waitOptions cmd := &cobra.Command{ Use: "wait CONTAINER [CONTAINER...]", Short: "Block until one or more containers stop, then print their exit codes", Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.containers = args return runWait(dockerCli, &opts) }, } return cmd }
go
func NewWaitCommand(dockerCli command.Cli) *cobra.Command { var opts waitOptions cmd := &cobra.Command{ Use: "wait CONTAINER [CONTAINER...]", Short: "Block until one or more containers stop, then print their exit codes", Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.containers = args return runWait(dockerCli, &opts) }, } return cmd }
[ "func", "NewWaitCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "opts", "waitOptions", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "RequiresMinArgs", "(", "1", ")", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "opts", ".", "containers", "=", "args", "\n", "return", "runWait", "(", "dockerCli", ",", "&", "opts", ")", "\n", "}", ",", "}", "\n\n", "return", "cmd", "\n", "}" ]
// NewWaitCommand creates a new cobra.Command for `docker wait`
[ "NewWaitCommand", "creates", "a", "new", "cobra", ".", "Command", "for", "docker", "wait" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/wait.go#L19-L33
train
docker/cli
opts/weightdevice.go
ValidateWeightDevice
func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) { split := strings.SplitN(val, ":", 2) if len(split) != 2 { return nil, fmt.Errorf("bad format: %s", val) } if !strings.HasPrefix(split[0], "/dev/") { return nil, fmt.Errorf("bad format for device path: %s", val) } weight, err := strconv.ParseUint(split[1], 10, 0) if err != nil { return nil, fmt.Errorf("invalid weight for device: %s", val) } if weight > 0 && (weight < 10 || weight > 1000) { return nil, fmt.Errorf("invalid weight for device: %s", val) } return &blkiodev.WeightDevice{ Path: split[0], Weight: uint16(weight), }, nil }
go
func ValidateWeightDevice(val string) (*blkiodev.WeightDevice, error) { split := strings.SplitN(val, ":", 2) if len(split) != 2 { return nil, fmt.Errorf("bad format: %s", val) } if !strings.HasPrefix(split[0], "/dev/") { return nil, fmt.Errorf("bad format for device path: %s", val) } weight, err := strconv.ParseUint(split[1], 10, 0) if err != nil { return nil, fmt.Errorf("invalid weight for device: %s", val) } if weight > 0 && (weight < 10 || weight > 1000) { return nil, fmt.Errorf("invalid weight for device: %s", val) } return &blkiodev.WeightDevice{ Path: split[0], Weight: uint16(weight), }, nil }
[ "func", "ValidateWeightDevice", "(", "val", "string", ")", "(", "*", "blkiodev", ".", "WeightDevice", ",", "error", ")", "{", "split", ":=", "strings", ".", "SplitN", "(", "val", ",", "\"", "\"", ",", "2", ")", "\n", "if", "len", "(", "split", ")", "!=", "2", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "val", ")", "\n", "}", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "split", "[", "0", "]", ",", "\"", "\"", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "val", ")", "\n", "}", "\n", "weight", ",", "err", ":=", "strconv", ".", "ParseUint", "(", "split", "[", "1", "]", ",", "10", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "val", ")", "\n", "}", "\n", "if", "weight", ">", "0", "&&", "(", "weight", "<", "10", "||", "weight", ">", "1000", ")", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "val", ")", "\n", "}", "\n\n", "return", "&", "blkiodev", ".", "WeightDevice", "{", "Path", ":", "split", "[", "0", "]", ",", "Weight", ":", "uint16", "(", "weight", ")", ",", "}", ",", "nil", "\n", "}" ]
// ValidateWeightDevice validates that the specified string has a valid device-weight format.
[ "ValidateWeightDevice", "validates", "that", "the", "specified", "string", "has", "a", "valid", "device", "-", "weight", "format", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/weightdevice.go#L15-L35
train
docker/cli
opts/weightdevice.go
NewWeightdeviceOpt
func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt { values := []*blkiodev.WeightDevice{} return WeightdeviceOpt{ values: values, validator: validator, } }
go
func NewWeightdeviceOpt(validator ValidatorWeightFctType) WeightdeviceOpt { values := []*blkiodev.WeightDevice{} return WeightdeviceOpt{ values: values, validator: validator, } }
[ "func", "NewWeightdeviceOpt", "(", "validator", "ValidatorWeightFctType", ")", "WeightdeviceOpt", "{", "values", ":=", "[", "]", "*", "blkiodev", ".", "WeightDevice", "{", "}", "\n", "return", "WeightdeviceOpt", "{", "values", ":", "values", ",", "validator", ":", "validator", ",", "}", "\n", "}" ]
// NewWeightdeviceOpt creates a new WeightdeviceOpt
[ "NewWeightdeviceOpt", "creates", "a", "new", "WeightdeviceOpt" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/weightdevice.go#L44-L50
train
docker/cli
opts/weightdevice.go
Set
func (opt *WeightdeviceOpt) Set(val string) error { var value *blkiodev.WeightDevice if opt.validator != nil { v, err := opt.validator(val) if err != nil { return err } value = v } (opt.values) = append((opt.values), value) return nil }
go
func (opt *WeightdeviceOpt) Set(val string) error { var value *blkiodev.WeightDevice if opt.validator != nil { v, err := opt.validator(val) if err != nil { return err } value = v } (opt.values) = append((opt.values), value) return nil }
[ "func", "(", "opt", "*", "WeightdeviceOpt", ")", "Set", "(", "val", "string", ")", "error", "{", "var", "value", "*", "blkiodev", ".", "WeightDevice", "\n", "if", "opt", ".", "validator", "!=", "nil", "{", "v", ",", "err", ":=", "opt", ".", "validator", "(", "val", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "value", "=", "v", "\n", "}", "\n", "(", "opt", ".", "values", ")", "=", "append", "(", "(", "opt", ".", "values", ")", ",", "value", ")", "\n", "return", "nil", "\n", "}" ]
// Set validates a WeightDevice and sets its name as a key in WeightdeviceOpt
[ "Set", "validates", "a", "WeightDevice", "and", "sets", "its", "name", "as", "a", "key", "in", "WeightdeviceOpt" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/weightdevice.go#L53-L64
train
docker/cli
cli/command/stack/swarm/remove.go
RunRemove
func RunRemove(dockerCli command.Cli, opts options.Remove) error { client := dockerCli.Client() ctx := context.Background() var errs []string for _, namespace := range opts.Namespaces { services, err := getStackServices(ctx, client, namespace) if err != nil { return err } networks, err := getStackNetworks(ctx, client, namespace) if err != nil { return err } var secrets []swarm.Secret if versions.GreaterThanOrEqualTo(client.ClientVersion(), "1.25") { secrets, err = getStackSecrets(ctx, client, namespace) if err != nil { return err } } var configs []swarm.Config if versions.GreaterThanOrEqualTo(client.ClientVersion(), "1.30") { configs, err = getStackConfigs(ctx, client, namespace) if err != nil { return err } } if len(services)+len(networks)+len(secrets)+len(configs) == 0 { fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", namespace) continue } hasError := removeServices(ctx, dockerCli, services) hasError = removeSecrets(ctx, dockerCli, secrets) || hasError hasError = removeConfigs(ctx, dockerCli, configs) || hasError hasError = removeNetworks(ctx, dockerCli, networks) || hasError if hasError { errs = append(errs, fmt.Sprintf("Failed to remove some resources from stack: %s", namespace)) } } if len(errs) > 0 { return errors.Errorf(strings.Join(errs, "\n")) } return nil }
go
func RunRemove(dockerCli command.Cli, opts options.Remove) error { client := dockerCli.Client() ctx := context.Background() var errs []string for _, namespace := range opts.Namespaces { services, err := getStackServices(ctx, client, namespace) if err != nil { return err } networks, err := getStackNetworks(ctx, client, namespace) if err != nil { return err } var secrets []swarm.Secret if versions.GreaterThanOrEqualTo(client.ClientVersion(), "1.25") { secrets, err = getStackSecrets(ctx, client, namespace) if err != nil { return err } } var configs []swarm.Config if versions.GreaterThanOrEqualTo(client.ClientVersion(), "1.30") { configs, err = getStackConfigs(ctx, client, namespace) if err != nil { return err } } if len(services)+len(networks)+len(secrets)+len(configs) == 0 { fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", namespace) continue } hasError := removeServices(ctx, dockerCli, services) hasError = removeSecrets(ctx, dockerCli, secrets) || hasError hasError = removeConfigs(ctx, dockerCli, configs) || hasError hasError = removeNetworks(ctx, dockerCli, networks) || hasError if hasError { errs = append(errs, fmt.Sprintf("Failed to remove some resources from stack: %s", namespace)) } } if len(errs) > 0 { return errors.Errorf(strings.Join(errs, "\n")) } return nil }
[ "func", "RunRemove", "(", "dockerCli", "command", ".", "Cli", ",", "opts", "options", ".", "Remove", ")", "error", "{", "client", ":=", "dockerCli", ".", "Client", "(", ")", "\n", "ctx", ":=", "context", ".", "Background", "(", ")", "\n\n", "var", "errs", "[", "]", "string", "\n", "for", "_", ",", "namespace", ":=", "range", "opts", ".", "Namespaces", "{", "services", ",", "err", ":=", "getStackServices", "(", "ctx", ",", "client", ",", "namespace", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "networks", ",", "err", ":=", "getStackNetworks", "(", "ctx", ",", "client", ",", "namespace", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "secrets", "[", "]", "swarm", ".", "Secret", "\n", "if", "versions", ".", "GreaterThanOrEqualTo", "(", "client", ".", "ClientVersion", "(", ")", ",", "\"", "\"", ")", "{", "secrets", ",", "err", "=", "getStackSecrets", "(", "ctx", ",", "client", ",", "namespace", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "var", "configs", "[", "]", "swarm", ".", "Config", "\n", "if", "versions", ".", "GreaterThanOrEqualTo", "(", "client", ".", "ClientVersion", "(", ")", ",", "\"", "\"", ")", "{", "configs", ",", "err", "=", "getStackConfigs", "(", "ctx", ",", "client", ",", "namespace", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "services", ")", "+", "len", "(", "networks", ")", "+", "len", "(", "secrets", ")", "+", "len", "(", "configs", ")", "==", "0", "{", "fmt", ".", "Fprintf", "(", "dockerCli", ".", "Err", "(", ")", ",", "\"", "\\n", "\"", ",", "namespace", ")", "\n", "continue", "\n", "}", "\n\n", "hasError", ":=", "removeServices", "(", "ctx", ",", "dockerCli", ",", "services", ")", "\n", "hasError", "=", "removeSecrets", "(", "ctx", ",", "dockerCli", ",", "secrets", ")", "||", "hasError", "\n", "hasError", "=", "removeConfigs", "(", "ctx", ",", "dockerCli", ",", "configs", ")", "||", "hasError", "\n", "hasError", "=", "removeNetworks", "(", "ctx", ",", "dockerCli", ",", "networks", ")", "||", "hasError", "\n\n", "if", "hasError", "{", "errs", "=", "append", "(", "errs", ",", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "namespace", ")", ")", "\n", "}", "\n", "}", "\n\n", "if", "len", "(", "errs", ")", ">", "0", "{", "return", "errors", ".", "Errorf", "(", "strings", ".", "Join", "(", "errs", ",", "\"", "\\n", "\"", ")", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RunRemove is the swarm implementation of docker stack remove
[ "RunRemove", "is", "the", "swarm", "implementation", "of", "docker", "stack", "remove" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/swarm/remove.go#L18-L69
train
docker/cli
cli/manifest/store/store.go
Remove
func (s *fsStore) Remove(listRef reference.Reference) error { path := filepath.Join(s.root, makeFilesafeName(listRef.String())) return os.RemoveAll(path) }
go
func (s *fsStore) Remove(listRef reference.Reference) error { path := filepath.Join(s.root, makeFilesafeName(listRef.String())) return os.RemoveAll(path) }
[ "func", "(", "s", "*", "fsStore", ")", "Remove", "(", "listRef", "reference", ".", "Reference", ")", "error", "{", "path", ":=", "filepath", ".", "Join", "(", "s", ".", "root", ",", "makeFilesafeName", "(", "listRef", ".", "String", "(", ")", ")", ")", "\n", "return", "os", ".", "RemoveAll", "(", "path", ")", "\n", "}" ]
// Remove a manifest list from local storage
[ "Remove", "a", "manifest", "list", "from", "local", "storage" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/manifest/store/store.go#L38-L41
train
docker/cli
cli/manifest/store/store.go
Get
func (s *fsStore) Get(listRef reference.Reference, manifest reference.Reference) (types.ImageManifest, error) { filename := manifestToFilename(s.root, listRef.String(), manifest.String()) return s.getFromFilename(manifest, filename) }
go
func (s *fsStore) Get(listRef reference.Reference, manifest reference.Reference) (types.ImageManifest, error) { filename := manifestToFilename(s.root, listRef.String(), manifest.String()) return s.getFromFilename(manifest, filename) }
[ "func", "(", "s", "*", "fsStore", ")", "Get", "(", "listRef", "reference", ".", "Reference", ",", "manifest", "reference", ".", "Reference", ")", "(", "types", ".", "ImageManifest", ",", "error", ")", "{", "filename", ":=", "manifestToFilename", "(", "s", ".", "root", ",", "listRef", ".", "String", "(", ")", ",", "manifest", ".", "String", "(", ")", ")", "\n", "return", "s", ".", "getFromFilename", "(", "manifest", ",", "filename", ")", "\n", "}" ]
// Get returns the local manifest
[ "Get", "returns", "the", "local", "manifest" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/manifest/store/store.go#L44-L47
train
docker/cli
cli/manifest/store/store.go
GetList
func (s *fsStore) GetList(listRef reference.Reference) ([]types.ImageManifest, error) { filenames, err := s.listManifests(listRef.String()) switch { case err != nil: return nil, err case filenames == nil: return nil, newNotFoundError(listRef.String()) } manifests := []types.ImageManifest{} for _, filename := range filenames { filename = filepath.Join(s.root, makeFilesafeName(listRef.String()), filename) manifest, err := s.getFromFilename(listRef, filename) if err != nil { return nil, err } manifests = append(manifests, manifest) } return manifests, nil }
go
func (s *fsStore) GetList(listRef reference.Reference) ([]types.ImageManifest, error) { filenames, err := s.listManifests(listRef.String()) switch { case err != nil: return nil, err case filenames == nil: return nil, newNotFoundError(listRef.String()) } manifests := []types.ImageManifest{} for _, filename := range filenames { filename = filepath.Join(s.root, makeFilesafeName(listRef.String()), filename) manifest, err := s.getFromFilename(listRef, filename) if err != nil { return nil, err } manifests = append(manifests, manifest) } return manifests, nil }
[ "func", "(", "s", "*", "fsStore", ")", "GetList", "(", "listRef", "reference", ".", "Reference", ")", "(", "[", "]", "types", ".", "ImageManifest", ",", "error", ")", "{", "filenames", ",", "err", ":=", "s", ".", "listManifests", "(", "listRef", ".", "String", "(", ")", ")", "\n", "switch", "{", "case", "err", "!=", "nil", ":", "return", "nil", ",", "err", "\n", "case", "filenames", "==", "nil", ":", "return", "nil", ",", "newNotFoundError", "(", "listRef", ".", "String", "(", ")", ")", "\n", "}", "\n\n", "manifests", ":=", "[", "]", "types", ".", "ImageManifest", "{", "}", "\n", "for", "_", ",", "filename", ":=", "range", "filenames", "{", "filename", "=", "filepath", ".", "Join", "(", "s", ".", "root", ",", "makeFilesafeName", "(", "listRef", ".", "String", "(", ")", ")", ",", "filename", ")", "\n", "manifest", ",", "err", ":=", "s", ".", "getFromFilename", "(", "listRef", ",", "filename", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "manifests", "=", "append", "(", "manifests", ",", "manifest", ")", "\n", "}", "\n", "return", "manifests", ",", "nil", "\n", "}" ]
// GetList returns all the local manifests for a transaction
[ "GetList", "returns", "all", "the", "local", "manifests", "for", "a", "transaction" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/manifest/store/store.go#L91-L110
train
docker/cli
cli/manifest/store/store.go
listManifests
func (s *fsStore) listManifests(transaction string) ([]string, error) { transactionDir := filepath.Join(s.root, makeFilesafeName(transaction)) fileInfos, err := ioutil.ReadDir(transactionDir) switch { case os.IsNotExist(err): return nil, nil case err != nil: return nil, err } filenames := []string{} for _, info := range fileInfos { filenames = append(filenames, info.Name()) } return filenames, nil }
go
func (s *fsStore) listManifests(transaction string) ([]string, error) { transactionDir := filepath.Join(s.root, makeFilesafeName(transaction)) fileInfos, err := ioutil.ReadDir(transactionDir) switch { case os.IsNotExist(err): return nil, nil case err != nil: return nil, err } filenames := []string{} for _, info := range fileInfos { filenames = append(filenames, info.Name()) } return filenames, nil }
[ "func", "(", "s", "*", "fsStore", ")", "listManifests", "(", "transaction", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "transactionDir", ":=", "filepath", ".", "Join", "(", "s", ".", "root", ",", "makeFilesafeName", "(", "transaction", ")", ")", "\n", "fileInfos", ",", "err", ":=", "ioutil", ".", "ReadDir", "(", "transactionDir", ")", "\n", "switch", "{", "case", "os", ".", "IsNotExist", "(", "err", ")", ":", "return", "nil", ",", "nil", "\n", "case", "err", "!=", "nil", ":", "return", "nil", ",", "err", "\n", "}", "\n\n", "filenames", ":=", "[", "]", "string", "{", "}", "\n", "for", "_", ",", "info", ":=", "range", "fileInfos", "{", "filenames", "=", "append", "(", "filenames", ",", "info", ".", "Name", "(", ")", ")", "\n", "}", "\n", "return", "filenames", ",", "nil", "\n", "}" ]
// listManifests stored in a transaction
[ "listManifests", "stored", "in", "a", "transaction" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/manifest/store/store.go#L113-L128
train
docker/cli
cli/manifest/store/store.go
Save
func (s *fsStore) Save(listRef reference.Reference, manifest reference.Reference, image types.ImageManifest) error { if err := s.createManifestListDirectory(listRef.String()); err != nil { return err } filename := manifestToFilename(s.root, listRef.String(), manifest.String()) bytes, err := json.Marshal(image) if err != nil { return err } return ioutil.WriteFile(filename, bytes, 0644) }
go
func (s *fsStore) Save(listRef reference.Reference, manifest reference.Reference, image types.ImageManifest) error { if err := s.createManifestListDirectory(listRef.String()); err != nil { return err } filename := manifestToFilename(s.root, listRef.String(), manifest.String()) bytes, err := json.Marshal(image) if err != nil { return err } return ioutil.WriteFile(filename, bytes, 0644) }
[ "func", "(", "s", "*", "fsStore", ")", "Save", "(", "listRef", "reference", ".", "Reference", ",", "manifest", "reference", ".", "Reference", ",", "image", "types", ".", "ImageManifest", ")", "error", "{", "if", "err", ":=", "s", ".", "createManifestListDirectory", "(", "listRef", ".", "String", "(", ")", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "filename", ":=", "manifestToFilename", "(", "s", ".", "root", ",", "listRef", ".", "String", "(", ")", ",", "manifest", ".", "String", "(", ")", ")", "\n", "bytes", ",", "err", ":=", "json", ".", "Marshal", "(", "image", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "ioutil", ".", "WriteFile", "(", "filename", ",", "bytes", ",", "0644", ")", "\n", "}" ]
// Save a manifest as part of a local manifest list
[ "Save", "a", "manifest", "as", "part", "of", "a", "local", "manifest", "list" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/manifest/store/store.go#L131-L141
train
docker/cli
cli/connhelper/commandconn/commandconn.go
New
func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) { var ( c commandConn err error ) c.cmd = exec.CommandContext(ctx, cmd, args...) // we assume that args never contains sensitive information logrus.Debugf("commandconn: starting %s with %v", cmd, args) c.cmd.Env = os.Environ() c.cmd.SysProcAttr = &syscall.SysProcAttr{} setPdeathsig(c.cmd) createSession(c.cmd) c.stdin, err = c.cmd.StdinPipe() if err != nil { return nil, err } c.stdout, err = c.cmd.StdoutPipe() if err != nil { return nil, err } c.cmd.Stderr = &stderrWriter{ stderrMu: &c.stderrMu, stderr: &c.stderr, debugPrefix: fmt.Sprintf("commandconn (%s):", cmd), } c.localAddr = dummyAddr{network: "dummy", s: "dummy-0"} c.remoteAddr = dummyAddr{network: "dummy", s: "dummy-1"} return &c, c.cmd.Start() }
go
func New(ctx context.Context, cmd string, args ...string) (net.Conn, error) { var ( c commandConn err error ) c.cmd = exec.CommandContext(ctx, cmd, args...) // we assume that args never contains sensitive information logrus.Debugf("commandconn: starting %s with %v", cmd, args) c.cmd.Env = os.Environ() c.cmd.SysProcAttr = &syscall.SysProcAttr{} setPdeathsig(c.cmd) createSession(c.cmd) c.stdin, err = c.cmd.StdinPipe() if err != nil { return nil, err } c.stdout, err = c.cmd.StdoutPipe() if err != nil { return nil, err } c.cmd.Stderr = &stderrWriter{ stderrMu: &c.stderrMu, stderr: &c.stderr, debugPrefix: fmt.Sprintf("commandconn (%s):", cmd), } c.localAddr = dummyAddr{network: "dummy", s: "dummy-0"} c.remoteAddr = dummyAddr{network: "dummy", s: "dummy-1"} return &c, c.cmd.Start() }
[ "func", "New", "(", "ctx", "context", ".", "Context", ",", "cmd", "string", ",", "args", "...", "string", ")", "(", "net", ".", "Conn", ",", "error", ")", "{", "var", "(", "c", "commandConn", "\n", "err", "error", "\n", ")", "\n", "c", ".", "cmd", "=", "exec", ".", "CommandContext", "(", "ctx", ",", "cmd", ",", "args", "...", ")", "\n", "// we assume that args never contains sensitive information", "logrus", ".", "Debugf", "(", "\"", "\"", ",", "cmd", ",", "args", ")", "\n", "c", ".", "cmd", ".", "Env", "=", "os", ".", "Environ", "(", ")", "\n", "c", ".", "cmd", ".", "SysProcAttr", "=", "&", "syscall", ".", "SysProcAttr", "{", "}", "\n", "setPdeathsig", "(", "c", ".", "cmd", ")", "\n", "createSession", "(", "c", ".", "cmd", ")", "\n", "c", ".", "stdin", ",", "err", "=", "c", ".", "cmd", ".", "StdinPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "stdout", ",", "err", "=", "c", ".", "cmd", ".", "StdoutPipe", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "c", ".", "cmd", ".", "Stderr", "=", "&", "stderrWriter", "{", "stderrMu", ":", "&", "c", ".", "stderrMu", ",", "stderr", ":", "&", "c", ".", "stderr", ",", "debugPrefix", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "cmd", ")", ",", "}", "\n", "c", ".", "localAddr", "=", "dummyAddr", "{", "network", ":", "\"", "\"", ",", "s", ":", "\"", "\"", "}", "\n", "c", ".", "remoteAddr", "=", "dummyAddr", "{", "network", ":", "\"", "\"", ",", "s", ":", "\"", "\"", "}", "\n", "return", "&", "c", ",", "c", ".", "cmd", ".", "Start", "(", ")", "\n", "}" ]
// New returns net.Conn
[ "New", "returns", "net", ".", "Conn" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/connhelper/commandconn/commandconn.go#L35-L63
train
docker/cli
cli/connhelper/commandconn/commandconn.go
killIfStdioClosed
func (c *commandConn) killIfStdioClosed() error { c.stdioClosedMu.Lock() stdioClosed := c.stdoutClosed && c.stdinClosed c.stdioClosedMu.Unlock() if !stdioClosed { return nil } return c.kill() }
go
func (c *commandConn) killIfStdioClosed() error { c.stdioClosedMu.Lock() stdioClosed := c.stdoutClosed && c.stdinClosed c.stdioClosedMu.Unlock() if !stdioClosed { return nil } return c.kill() }
[ "func", "(", "c", "*", "commandConn", ")", "killIfStdioClosed", "(", ")", "error", "{", "c", ".", "stdioClosedMu", ".", "Lock", "(", ")", "\n", "stdioClosed", ":=", "c", ".", "stdoutClosed", "&&", "c", ".", "stdinClosed", "\n", "c", ".", "stdioClosedMu", ".", "Unlock", "(", ")", "\n", "if", "!", "stdioClosed", "{", "return", "nil", "\n", "}", "\n", "return", "c", ".", "kill", "(", ")", "\n", "}" ]
// killIfStdioClosed kills the cmd if both stdin and stdout are closed.
[ "killIfStdioClosed", "kills", "the", "cmd", "if", "both", "stdin", "and", "stdout", "are", "closed", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/connhelper/commandconn/commandconn.go#L83-L91
train
docker/cli
cli/connhelper/commandconn/commandconn.go
killAndWait
func killAndWait(cmd *exec.Cmd) error { var werr error if runtime.GOOS != "windows" { werrCh := make(chan error) go func() { werrCh <- cmd.Wait() }() cmd.Process.Signal(syscall.SIGTERM) select { case werr = <-werrCh: case <-time.After(3 * time.Second): cmd.Process.Kill() werr = <-werrCh } } else { cmd.Process.Kill() werr = cmd.Wait() } return werr }
go
func killAndWait(cmd *exec.Cmd) error { var werr error if runtime.GOOS != "windows" { werrCh := make(chan error) go func() { werrCh <- cmd.Wait() }() cmd.Process.Signal(syscall.SIGTERM) select { case werr = <-werrCh: case <-time.After(3 * time.Second): cmd.Process.Kill() werr = <-werrCh } } else { cmd.Process.Kill() werr = cmd.Wait() } return werr }
[ "func", "killAndWait", "(", "cmd", "*", "exec", ".", "Cmd", ")", "error", "{", "var", "werr", "error", "\n", "if", "runtime", ".", "GOOS", "!=", "\"", "\"", "{", "werrCh", ":=", "make", "(", "chan", "error", ")", "\n", "go", "func", "(", ")", "{", "werrCh", "<-", "cmd", ".", "Wait", "(", ")", "}", "(", ")", "\n", "cmd", ".", "Process", ".", "Signal", "(", "syscall", ".", "SIGTERM", ")", "\n", "select", "{", "case", "werr", "=", "<-", "werrCh", ":", "case", "<-", "time", ".", "After", "(", "3", "*", "time", ".", "Second", ")", ":", "cmd", ".", "Process", ".", "Kill", "(", ")", "\n", "werr", "=", "<-", "werrCh", "\n", "}", "\n", "}", "else", "{", "cmd", ".", "Process", ".", "Kill", "(", ")", "\n", "werr", "=", "cmd", ".", "Wait", "(", ")", "\n", "}", "\n", "return", "werr", "\n", "}" ]
// killAndWait tries sending SIGTERM to the process before sending SIGKILL.
[ "killAndWait", "tries", "sending", "SIGTERM", "to", "the", "process", "before", "sending", "SIGKILL", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/connhelper/commandconn/commandconn.go#L94-L111
train
docker/cli
cli/connhelper/commandconn/commandconn.go
kill
func (c *commandConn) kill() error { var werr error c.cmdMutex.Lock() if c.cmdExited { werr = c.cmdWaitErr } else { werr = killAndWait(c.cmd) c.cmdWaitErr = werr c.cmdExited = true } c.cmdMutex.Unlock() if werr == nil { return nil } wExitErr, ok := werr.(*exec.ExitError) if ok { if wExitErr.ProcessState.Exited() { return nil } } return errors.Wrapf(werr, "commandconn: failed to wait") }
go
func (c *commandConn) kill() error { var werr error c.cmdMutex.Lock() if c.cmdExited { werr = c.cmdWaitErr } else { werr = killAndWait(c.cmd) c.cmdWaitErr = werr c.cmdExited = true } c.cmdMutex.Unlock() if werr == nil { return nil } wExitErr, ok := werr.(*exec.ExitError) if ok { if wExitErr.ProcessState.Exited() { return nil } } return errors.Wrapf(werr, "commandconn: failed to wait") }
[ "func", "(", "c", "*", "commandConn", ")", "kill", "(", ")", "error", "{", "var", "werr", "error", "\n", "c", ".", "cmdMutex", ".", "Lock", "(", ")", "\n", "if", "c", ".", "cmdExited", "{", "werr", "=", "c", ".", "cmdWaitErr", "\n", "}", "else", "{", "werr", "=", "killAndWait", "(", "c", ".", "cmd", ")", "\n", "c", ".", "cmdWaitErr", "=", "werr", "\n", "c", ".", "cmdExited", "=", "true", "\n", "}", "\n", "c", ".", "cmdMutex", ".", "Unlock", "(", ")", "\n", "if", "werr", "==", "nil", "{", "return", "nil", "\n", "}", "\n", "wExitErr", ",", "ok", ":=", "werr", ".", "(", "*", "exec", ".", "ExitError", ")", "\n", "if", "ok", "{", "if", "wExitErr", ".", "ProcessState", ".", "Exited", "(", ")", "{", "return", "nil", "\n", "}", "\n", "}", "\n", "return", "errors", ".", "Wrapf", "(", "werr", ",", "\"", "\"", ")", "\n", "}" ]
// kill returns nil if the command terminated, regardless to the exit status.
[ "kill", "returns", "nil", "if", "the", "command", "terminated", "regardless", "to", "the", "exit", "status", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/connhelper/commandconn/commandconn.go#L114-L135
train
docker/cli
cli/command/manifest/util.go
getManifest
func getManifest(ctx context.Context, dockerCli command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) { data, err := dockerCli.ManifestStore().Get(listRef, namedRef) switch { case store.IsNotFound(err): return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef) case err != nil: return types.ImageManifest{}, err default: return data, nil } }
go
func getManifest(ctx context.Context, dockerCli command.Cli, listRef, namedRef reference.Named, insecure bool) (types.ImageManifest, error) { data, err := dockerCli.ManifestStore().Get(listRef, namedRef) switch { case store.IsNotFound(err): return dockerCli.RegistryClient(insecure).GetManifest(ctx, namedRef) case err != nil: return types.ImageManifest{}, err default: return data, nil } }
[ "func", "getManifest", "(", "ctx", "context", ".", "Context", ",", "dockerCli", "command", ".", "Cli", ",", "listRef", ",", "namedRef", "reference", ".", "Named", ",", "insecure", "bool", ")", "(", "types", ".", "ImageManifest", ",", "error", ")", "{", "data", ",", "err", ":=", "dockerCli", ".", "ManifestStore", "(", ")", ".", "Get", "(", "listRef", ",", "namedRef", ")", "\n", "switch", "{", "case", "store", ".", "IsNotFound", "(", "err", ")", ":", "return", "dockerCli", ".", "RegistryClient", "(", "insecure", ")", ".", "GetManifest", "(", "ctx", ",", "namedRef", ")", "\n", "case", "err", "!=", "nil", ":", "return", "types", ".", "ImageManifest", "{", "}", ",", "err", "\n", "default", ":", "return", "data", ",", "nil", "\n", "}", "\n", "}" ]
// getManifest from the local store, and fallback to the remote registry if it // doesn't exist locally
[ "getManifest", "from", "the", "local", "store", "and", "fallback", "to", "the", "remote", "registry", "if", "it", "doesn", "t", "exist", "locally" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/manifest/util.go#L71-L81
train
docker/cli
cli/command/network/formatter.go
NewFormat
func NewFormat(source string, quiet bool) formatter.Format { switch source { case formatter.TableFormatKey: if quiet { return formatter.DefaultQuietFormat } return defaultNetworkTableFormat case formatter.RawFormatKey: if quiet { return `network_id: {{.ID}}` } return `network_id: {{.ID}}\nname: {{.Name}}\ndriver: {{.Driver}}\nscope: {{.Scope}}\n` } return formatter.Format(source) }
go
func NewFormat(source string, quiet bool) formatter.Format { switch source { case formatter.TableFormatKey: if quiet { return formatter.DefaultQuietFormat } return defaultNetworkTableFormat case formatter.RawFormatKey: if quiet { return `network_id: {{.ID}}` } return `network_id: {{.ID}}\nname: {{.Name}}\ndriver: {{.Driver}}\nscope: {{.Scope}}\n` } return formatter.Format(source) }
[ "func", "NewFormat", "(", "source", "string", ",", "quiet", "bool", ")", "formatter", ".", "Format", "{", "switch", "source", "{", "case", "formatter", ".", "TableFormatKey", ":", "if", "quiet", "{", "return", "formatter", ".", "DefaultQuietFormat", "\n", "}", "\n", "return", "defaultNetworkTableFormat", "\n", "case", "formatter", ".", "RawFormatKey", ":", "if", "quiet", "{", "return", "`network_id: {{.ID}}`", "\n", "}", "\n", "return", "`network_id: {{.ID}}\\nname: {{.Name}}\\ndriver: {{.Driver}}\\nscope: {{.Scope}}\\n`", "\n", "}", "\n", "return", "formatter", ".", "Format", "(", "source", ")", "\n", "}" ]
// NewFormat returns a Format for rendering using a network Context
[ "NewFormat", "returns", "a", "Format", "for", "rendering", "using", "a", "network", "Context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/network/formatter.go#L21-L35
train
docker/cli
cli/command/stack/kubernetes/convert.go
stackFromV1beta1
func stackFromV1beta1(in *v1beta1.Stack) (Stack, error) { cfg, err := loadStackData(in.Spec.ComposeFile) if err != nil { return Stack{}, err } spec, err := fromComposeConfig(ioutil.Discard, cfg, v1beta1Capabilities) if err != nil { return Stack{}, err } return Stack{ Name: in.ObjectMeta.Name, Namespace: in.ObjectMeta.Namespace, ComposeFile: in.Spec.ComposeFile, Spec: spec, }, nil }
go
func stackFromV1beta1(in *v1beta1.Stack) (Stack, error) { cfg, err := loadStackData(in.Spec.ComposeFile) if err != nil { return Stack{}, err } spec, err := fromComposeConfig(ioutil.Discard, cfg, v1beta1Capabilities) if err != nil { return Stack{}, err } return Stack{ Name: in.ObjectMeta.Name, Namespace: in.ObjectMeta.Namespace, ComposeFile: in.Spec.ComposeFile, Spec: spec, }, nil }
[ "func", "stackFromV1beta1", "(", "in", "*", "v1beta1", ".", "Stack", ")", "(", "Stack", ",", "error", ")", "{", "cfg", ",", "err", ":=", "loadStackData", "(", "in", ".", "Spec", ".", "ComposeFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Stack", "{", "}", ",", "err", "\n", "}", "\n", "spec", ",", "err", ":=", "fromComposeConfig", "(", "ioutil", ".", "Discard", ",", "cfg", ",", "v1beta1Capabilities", ")", "\n", "if", "err", "!=", "nil", "{", "return", "Stack", "{", "}", ",", "err", "\n", "}", "\n", "return", "Stack", "{", "Name", ":", "in", ".", "ObjectMeta", ".", "Name", ",", "Namespace", ":", "in", ".", "ObjectMeta", ".", "Namespace", ",", "ComposeFile", ":", "in", ".", "Spec", ".", "ComposeFile", ",", "Spec", ":", "spec", ",", "}", ",", "nil", "\n", "}" ]
// Conversions from internal stack to different stack compose component versions.
[ "Conversions", "from", "internal", "stack", "to", "different", "stack", "compose", "component", "versions", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/convert.go#L113-L128
train
docker/cli
cli/command/container/formatter_diff.go
NewDiffFormat
func NewDiffFormat(source string) formatter.Format { switch source { case formatter.TableFormatKey: return defaultDiffTableFormat } return formatter.Format(source) }
go
func NewDiffFormat(source string) formatter.Format { switch source { case formatter.TableFormatKey: return defaultDiffTableFormat } return formatter.Format(source) }
[ "func", "NewDiffFormat", "(", "source", "string", ")", "formatter", ".", "Format", "{", "switch", "source", "{", "case", "formatter", ".", "TableFormatKey", ":", "return", "defaultDiffTableFormat", "\n", "}", "\n", "return", "formatter", ".", "Format", "(", "source", ")", "\n", "}" ]
// NewDiffFormat returns a format for use with a diff Context
[ "NewDiffFormat", "returns", "a", "format", "for", "use", "with", "a", "diff", "Context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_diff.go#L17-L23
train
docker/cli
cli/command/container/formatter_diff.go
DiffFormatWrite
func DiffFormatWrite(ctx formatter.Context, changes []container.ContainerChangeResponseItem) error { render := func(format func(subContext formatter.SubContext) error) error { for _, change := range changes { if err := format(&diffContext{c: change}); err != nil { return err } } return nil } return ctx.Write(newDiffContext(), render) }
go
func DiffFormatWrite(ctx formatter.Context, changes []container.ContainerChangeResponseItem) error { render := func(format func(subContext formatter.SubContext) error) error { for _, change := range changes { if err := format(&diffContext{c: change}); err != nil { return err } } return nil } return ctx.Write(newDiffContext(), render) }
[ "func", "DiffFormatWrite", "(", "ctx", "formatter", ".", "Context", ",", "changes", "[", "]", "container", ".", "ContainerChangeResponseItem", ")", "error", "{", "render", ":=", "func", "(", "format", "func", "(", "subContext", "formatter", ".", "SubContext", ")", "error", ")", "error", "{", "for", "_", ",", "change", ":=", "range", "changes", "{", "if", "err", ":=", "format", "(", "&", "diffContext", "{", "c", ":", "change", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "return", "ctx", ".", "Write", "(", "newDiffContext", "(", ")", ",", "render", ")", "\n", "}" ]
// DiffFormatWrite writes formatted diff using the Context
[ "DiffFormatWrite", "writes", "formatted", "diff", "using", "the", "Context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/formatter_diff.go#L26-L37
train
docker/cli
cli/command/trust/cmd.go
NewTrustCommand
func NewTrustCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "trust", Short: "Manage trust on Docker images", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), } cmd.AddCommand( newRevokeCommand(dockerCli), newSignCommand(dockerCli), newTrustKeyCommand(dockerCli), newTrustSignerCommand(dockerCli), newInspectCommand(dockerCli), ) return cmd }
go
func NewTrustCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "trust", Short: "Manage trust on Docker images", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), } cmd.AddCommand( newRevokeCommand(dockerCli), newSignCommand(dockerCli), newTrustKeyCommand(dockerCli), newTrustSignerCommand(dockerCli), newInspectCommand(dockerCli), ) return cmd }
[ "func", "NewTrustCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "command", ".", "ShowHelp", "(", "dockerCli", ".", "Err", "(", ")", ")", ",", "}", "\n", "cmd", ".", "AddCommand", "(", "newRevokeCommand", "(", "dockerCli", ")", ",", "newSignCommand", "(", "dockerCli", ")", ",", "newTrustKeyCommand", "(", "dockerCli", ")", ",", "newTrustSignerCommand", "(", "dockerCli", ")", ",", "newInspectCommand", "(", "dockerCli", ")", ",", ")", "\n", "return", "cmd", "\n", "}" ]
// NewTrustCommand returns a cobra command for `trust` subcommands
[ "NewTrustCommand", "returns", "a", "cobra", "command", "for", "trust", "subcommands" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust/cmd.go#L10-L25
train
docker/cli
cli/command/plugin/cmd.go
NewPluginCommand
func NewPluginCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "plugin", Short: "Manage plugins", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{"version": "1.25"}, } cmd.AddCommand( newDisableCommand(dockerCli), newEnableCommand(dockerCli), newInspectCommand(dockerCli), newInstallCommand(dockerCli), newListCommand(dockerCli), newRemoveCommand(dockerCli), newSetCommand(dockerCli), newPushCommand(dockerCli), newCreateCommand(dockerCli), newUpgradeCommand(dockerCli), ) return cmd }
go
func NewPluginCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "plugin", Short: "Manage plugins", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{"version": "1.25"}, } cmd.AddCommand( newDisableCommand(dockerCli), newEnableCommand(dockerCli), newInspectCommand(dockerCli), newInstallCommand(dockerCli), newListCommand(dockerCli), newRemoveCommand(dockerCli), newSetCommand(dockerCli), newPushCommand(dockerCli), newCreateCommand(dockerCli), newUpgradeCommand(dockerCli), ) return cmd }
[ "func", "NewPluginCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "command", ".", "ShowHelp", "(", "dockerCli", ".", "Err", "(", ")", ")", ",", "Annotations", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", "}", ",", "}", "\n\n", "cmd", ".", "AddCommand", "(", "newDisableCommand", "(", "dockerCli", ")", ",", "newEnableCommand", "(", "dockerCli", ")", ",", "newInspectCommand", "(", "dockerCli", ")", ",", "newInstallCommand", "(", "dockerCli", ")", ",", "newListCommand", "(", "dockerCli", ")", ",", "newRemoveCommand", "(", "dockerCli", ")", ",", "newSetCommand", "(", "dockerCli", ")", ",", "newPushCommand", "(", "dockerCli", ")", ",", "newCreateCommand", "(", "dockerCli", ")", ",", "newUpgradeCommand", "(", "dockerCli", ")", ",", ")", "\n", "return", "cmd", "\n", "}" ]
// NewPluginCommand returns a cobra command for `plugin` subcommands
[ "NewPluginCommand", "returns", "a", "cobra", "command", "for", "plugin", "subcommands" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/plugin/cmd.go#L10-L32
train
docker/cli
cli/command/inspect/inspector.go
NewTemplateInspector
func NewTemplateInspector(outputStream io.Writer, tmpl *template.Template) Inspector { return &TemplateInspector{ outputStream: outputStream, buffer: new(bytes.Buffer), tmpl: tmpl, } }
go
func NewTemplateInspector(outputStream io.Writer, tmpl *template.Template) Inspector { return &TemplateInspector{ outputStream: outputStream, buffer: new(bytes.Buffer), tmpl: tmpl, } }
[ "func", "NewTemplateInspector", "(", "outputStream", "io", ".", "Writer", ",", "tmpl", "*", "template", ".", "Template", ")", "Inspector", "{", "return", "&", "TemplateInspector", "{", "outputStream", ":", "outputStream", ",", "buffer", ":", "new", "(", "bytes", ".", "Buffer", ")", ",", "tmpl", ":", "tmpl", ",", "}", "\n", "}" ]
// NewTemplateInspector creates a new inspector with a template.
[ "NewTemplateInspector", "creates", "a", "new", "inspector", "with", "a", "template", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/inspect/inspector.go#L30-L36
train
docker/cli
cli/command/inspect/inspector.go
NewTemplateInspectorFromString
func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, error) { if tmplStr == "" { return NewIndentedInspector(out), nil } tmpl, err := templates.Parse(tmplStr) if err != nil { return nil, errors.Errorf("Template parsing error: %s", err) } return NewTemplateInspector(out, tmpl), nil }
go
func NewTemplateInspectorFromString(out io.Writer, tmplStr string) (Inspector, error) { if tmplStr == "" { return NewIndentedInspector(out), nil } tmpl, err := templates.Parse(tmplStr) if err != nil { return nil, errors.Errorf("Template parsing error: %s", err) } return NewTemplateInspector(out, tmpl), nil }
[ "func", "NewTemplateInspectorFromString", "(", "out", "io", ".", "Writer", ",", "tmplStr", "string", ")", "(", "Inspector", ",", "error", ")", "{", "if", "tmplStr", "==", "\"", "\"", "{", "return", "NewIndentedInspector", "(", "out", ")", ",", "nil", "\n", "}", "\n\n", "tmpl", ",", "err", ":=", "templates", ".", "Parse", "(", "tmplStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "NewTemplateInspector", "(", "out", ",", "tmpl", ")", ",", "nil", "\n", "}" ]
// NewTemplateInspectorFromString creates a new TemplateInspector from a string // which is compiled into a template.
[ "NewTemplateInspectorFromString", "creates", "a", "new", "TemplateInspector", "from", "a", "string", "which", "is", "compiled", "into", "a", "template", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/inspect/inspector.go#L40-L50
train
docker/cli
cli/command/inspect/inspector.go
Inspect
func Inspect(out io.Writer, references []string, tmplStr string, getRef GetRefFunc) error { inspector, err := NewTemplateInspectorFromString(out, tmplStr) if err != nil { return cli.StatusError{StatusCode: 64, Status: err.Error()} } var inspectErrs []string for _, ref := range references { element, raw, err := getRef(ref) if err != nil { inspectErrs = append(inspectErrs, err.Error()) continue } if err := inspector.Inspect(element, raw); err != nil { inspectErrs = append(inspectErrs, err.Error()) } } if err := inspector.Flush(); err != nil { logrus.Errorf("%s\n", err) } if len(inspectErrs) != 0 { return cli.StatusError{ StatusCode: 1, Status: strings.Join(inspectErrs, "\n"), } } return nil }
go
func Inspect(out io.Writer, references []string, tmplStr string, getRef GetRefFunc) error { inspector, err := NewTemplateInspectorFromString(out, tmplStr) if err != nil { return cli.StatusError{StatusCode: 64, Status: err.Error()} } var inspectErrs []string for _, ref := range references { element, raw, err := getRef(ref) if err != nil { inspectErrs = append(inspectErrs, err.Error()) continue } if err := inspector.Inspect(element, raw); err != nil { inspectErrs = append(inspectErrs, err.Error()) } } if err := inspector.Flush(); err != nil { logrus.Errorf("%s\n", err) } if len(inspectErrs) != 0 { return cli.StatusError{ StatusCode: 1, Status: strings.Join(inspectErrs, "\n"), } } return nil }
[ "func", "Inspect", "(", "out", "io", ".", "Writer", ",", "references", "[", "]", "string", ",", "tmplStr", "string", ",", "getRef", "GetRefFunc", ")", "error", "{", "inspector", ",", "err", ":=", "NewTemplateInspectorFromString", "(", "out", ",", "tmplStr", ")", "\n", "if", "err", "!=", "nil", "{", "return", "cli", ".", "StatusError", "{", "StatusCode", ":", "64", ",", "Status", ":", "err", ".", "Error", "(", ")", "}", "\n", "}", "\n\n", "var", "inspectErrs", "[", "]", "string", "\n", "for", "_", ",", "ref", ":=", "range", "references", "{", "element", ",", "raw", ",", "err", ":=", "getRef", "(", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "inspectErrs", "=", "append", "(", "inspectErrs", ",", "err", ".", "Error", "(", ")", ")", "\n", "continue", "\n", "}", "\n\n", "if", "err", ":=", "inspector", ".", "Inspect", "(", "element", ",", "raw", ")", ";", "err", "!=", "nil", "{", "inspectErrs", "=", "append", "(", "inspectErrs", ",", "err", ".", "Error", "(", ")", ")", "\n", "}", "\n", "}", "\n\n", "if", "err", ":=", "inspector", ".", "Flush", "(", ")", ";", "err", "!=", "nil", "{", "logrus", ".", "Errorf", "(", "\"", "\\n", "\"", ",", "err", ")", "\n", "}", "\n\n", "if", "len", "(", "inspectErrs", ")", "!=", "0", "{", "return", "cli", ".", "StatusError", "{", "StatusCode", ":", "1", ",", "Status", ":", "strings", ".", "Join", "(", "inspectErrs", ",", "\"", "\\n", "\"", ")", ",", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Inspect fetches objects by reference using GetRefFunc and writes the json // representation to the output writer.
[ "Inspect", "fetches", "objects", "by", "reference", "using", "GetRefFunc", "and", "writes", "the", "json", "representation", "to", "the", "output", "writer", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/inspect/inspector.go#L58-L88
train
docker/cli
cli/command/inspect/inspector.go
Inspect
func (i *TemplateInspector) Inspect(typedElement interface{}, rawElement []byte) error { buffer := new(bytes.Buffer) if err := i.tmpl.Execute(buffer, typedElement); err != nil { if rawElement == nil { return errors.Errorf("Template parsing error: %v", err) } return i.tryRawInspectFallback(rawElement) } i.buffer.Write(buffer.Bytes()) i.buffer.WriteByte('\n') return nil }
go
func (i *TemplateInspector) Inspect(typedElement interface{}, rawElement []byte) error { buffer := new(bytes.Buffer) if err := i.tmpl.Execute(buffer, typedElement); err != nil { if rawElement == nil { return errors.Errorf("Template parsing error: %v", err) } return i.tryRawInspectFallback(rawElement) } i.buffer.Write(buffer.Bytes()) i.buffer.WriteByte('\n') return nil }
[ "func", "(", "i", "*", "TemplateInspector", ")", "Inspect", "(", "typedElement", "interface", "{", "}", ",", "rawElement", "[", "]", "byte", ")", "error", "{", "buffer", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "if", "err", ":=", "i", ".", "tmpl", ".", "Execute", "(", "buffer", ",", "typedElement", ")", ";", "err", "!=", "nil", "{", "if", "rawElement", "==", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "return", "i", ".", "tryRawInspectFallback", "(", "rawElement", ")", "\n", "}", "\n", "i", ".", "buffer", ".", "Write", "(", "buffer", ".", "Bytes", "(", ")", ")", "\n", "i", ".", "buffer", ".", "WriteByte", "(", "'\\n'", ")", "\n", "return", "nil", "\n", "}" ]
// Inspect executes the inspect template. // It decodes the raw element into a map if the initial execution fails. // This allows docker cli to parse inspect structs injected with Swarm fields.
[ "Inspect", "executes", "the", "inspect", "template", ".", "It", "decodes", "the", "raw", "element", "into", "a", "map", "if", "the", "initial", "execution", "fails", ".", "This", "allows", "docker", "cli", "to", "parse", "inspect", "structs", "injected", "with", "Swarm", "fields", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/inspect/inspector.go#L93-L104
train
docker/cli
cli/command/inspect/inspector.go
tryRawInspectFallback
func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error { var raw interface{} buffer := new(bytes.Buffer) rdr := bytes.NewReader(rawElement) dec := json.NewDecoder(rdr) dec.UseNumber() if rawErr := dec.Decode(&raw); rawErr != nil { return errors.Errorf("unable to read inspect data: %v", rawErr) } tmplMissingKey := i.tmpl.Option("missingkey=error") if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil { return errors.Errorf("Template parsing error: %v", rawErr) } i.buffer.Write(buffer.Bytes()) i.buffer.WriteByte('\n') return nil }
go
func (i *TemplateInspector) tryRawInspectFallback(rawElement []byte) error { var raw interface{} buffer := new(bytes.Buffer) rdr := bytes.NewReader(rawElement) dec := json.NewDecoder(rdr) dec.UseNumber() if rawErr := dec.Decode(&raw); rawErr != nil { return errors.Errorf("unable to read inspect data: %v", rawErr) } tmplMissingKey := i.tmpl.Option("missingkey=error") if rawErr := tmplMissingKey.Execute(buffer, raw); rawErr != nil { return errors.Errorf("Template parsing error: %v", rawErr) } i.buffer.Write(buffer.Bytes()) i.buffer.WriteByte('\n') return nil }
[ "func", "(", "i", "*", "TemplateInspector", ")", "tryRawInspectFallback", "(", "rawElement", "[", "]", "byte", ")", "error", "{", "var", "raw", "interface", "{", "}", "\n", "buffer", ":=", "new", "(", "bytes", ".", "Buffer", ")", "\n", "rdr", ":=", "bytes", ".", "NewReader", "(", "rawElement", ")", "\n", "dec", ":=", "json", ".", "NewDecoder", "(", "rdr", ")", "\n", "dec", ".", "UseNumber", "(", ")", "\n\n", "if", "rawErr", ":=", "dec", ".", "Decode", "(", "&", "raw", ")", ";", "rawErr", "!=", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "rawErr", ")", "\n", "}", "\n\n", "tmplMissingKey", ":=", "i", ".", "tmpl", ".", "Option", "(", "\"", "\"", ")", "\n", "if", "rawErr", ":=", "tmplMissingKey", ".", "Execute", "(", "buffer", ",", "raw", ")", ";", "rawErr", "!=", "nil", "{", "return", "errors", ".", "Errorf", "(", "\"", "\"", ",", "rawErr", ")", "\n", "}", "\n\n", "i", ".", "buffer", ".", "Write", "(", "buffer", ".", "Bytes", "(", ")", ")", "\n", "i", ".", "buffer", ".", "WriteByte", "(", "'\\n'", ")", "\n", "return", "nil", "\n", "}" ]
// tryRawInspectFallback executes the inspect template with a raw interface. // This allows docker cli to parse inspect structs injected with Swarm fields.
[ "tryRawInspectFallback", "executes", "the", "inspect", "template", "with", "a", "raw", "interface", ".", "This", "allows", "docker", "cli", "to", "parse", "inspect", "structs", "injected", "with", "Swarm", "fields", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/inspect/inspector.go#L108-L127
train
docker/cli
cli/command/inspect/inspector.go
Inspect
func (i *IndentedInspector) Inspect(typedElement interface{}, rawElement []byte) error { if rawElement != nil { i.rawElements = append(i.rawElements, rawElement) } else { i.elements = append(i.elements, typedElement) } return nil }
go
func (i *IndentedInspector) Inspect(typedElement interface{}, rawElement []byte) error { if rawElement != nil { i.rawElements = append(i.rawElements, rawElement) } else { i.elements = append(i.elements, typedElement) } return nil }
[ "func", "(", "i", "*", "IndentedInspector", ")", "Inspect", "(", "typedElement", "interface", "{", "}", ",", "rawElement", "[", "]", "byte", ")", "error", "{", "if", "rawElement", "!=", "nil", "{", "i", ".", "rawElements", "=", "append", "(", "i", ".", "rawElements", ",", "rawElement", ")", "\n", "}", "else", "{", "i", ".", "elements", "=", "append", "(", "i", ".", "elements", ",", "typedElement", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Inspect writes the raw element with an indented json format.
[ "Inspect", "writes", "the", "raw", "element", "with", "an", "indented", "json", "format", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/inspect/inspector.go#L154-L161
train
docker/cli
cli/command/idresolver/idresolver.go
New
func New(client client.APIClient, noResolve bool) *IDResolver { return &IDResolver{ client: client, noResolve: noResolve, cache: make(map[string]string), } }
go
func New(client client.APIClient, noResolve bool) *IDResolver { return &IDResolver{ client: client, noResolve: noResolve, cache: make(map[string]string), } }
[ "func", "New", "(", "client", "client", ".", "APIClient", ",", "noResolve", "bool", ")", "*", "IDResolver", "{", "return", "&", "IDResolver", "{", "client", ":", "client", ",", "noResolve", ":", "noResolve", ",", "cache", ":", "make", "(", "map", "[", "string", "]", "string", ")", ",", "}", "\n", "}" ]
// New creates a new IDResolver.
[ "New", "creates", "a", "new", "IDResolver", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/idresolver/idresolver.go#L20-L26
train
docker/cli
cli/compose/loader/volume.go
ParseVolume
func ParseVolume(spec string) (types.ServiceVolumeConfig, error) { volume := types.ServiceVolumeConfig{} switch len(spec) { case 0: return volume, errors.New("invalid empty volume spec") case 1, 2: volume.Target = spec volume.Type = string(mount.TypeVolume) return volume, nil } buffer := []rune{} for _, char := range spec + string(endOfSpec) { switch { case isWindowsDrive(buffer, char): buffer = append(buffer, char) case char == ':' || char == endOfSpec: if err := populateFieldFromBuffer(char, buffer, &volume); err != nil { populateType(&volume) return volume, errors.Wrapf(err, "invalid spec: %s", spec) } buffer = []rune{} default: buffer = append(buffer, char) } } populateType(&volume) return volume, nil }
go
func ParseVolume(spec string) (types.ServiceVolumeConfig, error) { volume := types.ServiceVolumeConfig{} switch len(spec) { case 0: return volume, errors.New("invalid empty volume spec") case 1, 2: volume.Target = spec volume.Type = string(mount.TypeVolume) return volume, nil } buffer := []rune{} for _, char := range spec + string(endOfSpec) { switch { case isWindowsDrive(buffer, char): buffer = append(buffer, char) case char == ':' || char == endOfSpec: if err := populateFieldFromBuffer(char, buffer, &volume); err != nil { populateType(&volume) return volume, errors.Wrapf(err, "invalid spec: %s", spec) } buffer = []rune{} default: buffer = append(buffer, char) } } populateType(&volume) return volume, nil }
[ "func", "ParseVolume", "(", "spec", "string", ")", "(", "types", ".", "ServiceVolumeConfig", ",", "error", ")", "{", "volume", ":=", "types", ".", "ServiceVolumeConfig", "{", "}", "\n\n", "switch", "len", "(", "spec", ")", "{", "case", "0", ":", "return", "volume", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "case", "1", ",", "2", ":", "volume", ".", "Target", "=", "spec", "\n", "volume", ".", "Type", "=", "string", "(", "mount", ".", "TypeVolume", ")", "\n", "return", "volume", ",", "nil", "\n", "}", "\n\n", "buffer", ":=", "[", "]", "rune", "{", "}", "\n", "for", "_", ",", "char", ":=", "range", "spec", "+", "string", "(", "endOfSpec", ")", "{", "switch", "{", "case", "isWindowsDrive", "(", "buffer", ",", "char", ")", ":", "buffer", "=", "append", "(", "buffer", ",", "char", ")", "\n", "case", "char", "==", "':'", "||", "char", "==", "endOfSpec", ":", "if", "err", ":=", "populateFieldFromBuffer", "(", "char", ",", "buffer", ",", "&", "volume", ")", ";", "err", "!=", "nil", "{", "populateType", "(", "&", "volume", ")", "\n", "return", "volume", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "spec", ")", "\n", "}", "\n", "buffer", "=", "[", "]", "rune", "{", "}", "\n", "default", ":", "buffer", "=", "append", "(", "buffer", ",", "char", ")", "\n", "}", "\n", "}", "\n\n", "populateType", "(", "&", "volume", ")", "\n", "return", "volume", ",", "nil", "\n", "}" ]
// ParseVolume parses a volume spec without any knowledge of the target platform
[ "ParseVolume", "parses", "a", "volume", "spec", "without", "any", "knowledge", "of", "the", "target", "platform" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/loader/volume.go#L16-L46
train
docker/cli
cli/command/system/dial_stdio.go
newDialStdioCommand
func newDialStdioCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "dial-stdio", Short: "Proxy the stdio stream to the daemon connection. Should not be invoked manually.", Args: cli.NoArgs, Hidden: true, RunE: func(cmd *cobra.Command, args []string) error { return runDialStdio(dockerCli) }, } return cmd }
go
func newDialStdioCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "dial-stdio", Short: "Proxy the stdio stream to the daemon connection. Should not be invoked manually.", Args: cli.NoArgs, Hidden: true, RunE: func(cmd *cobra.Command, args []string) error { return runDialStdio(dockerCli) }, } return cmd }
[ "func", "newDialStdioCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "Hidden", ":", "true", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "return", "runDialStdio", "(", "dockerCli", ")", "\n", "}", ",", "}", "\n", "return", "cmd", "\n", "}" ]
// newDialStdioCommand creates a new cobra.Command for `docker system dial-stdio`
[ "newDialStdioCommand", "creates", "a", "new", "cobra", ".", "Command", "for", "docker", "system", "dial", "-", "stdio" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/dial_stdio.go#L16-L27
train
docker/cli
cli/command/container/unpause.go
NewUnpauseCommand
func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command { var opts unpauseOptions cmd := &cobra.Command{ Use: "unpause CONTAINER [CONTAINER...]", Short: "Unpause all processes within one or more containers", Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.containers = args return runUnpause(dockerCli, &opts) }, } return cmd }
go
func NewUnpauseCommand(dockerCli command.Cli) *cobra.Command { var opts unpauseOptions cmd := &cobra.Command{ Use: "unpause CONTAINER [CONTAINER...]", Short: "Unpause all processes within one or more containers", Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.containers = args return runUnpause(dockerCli, &opts) }, } return cmd }
[ "func", "NewUnpauseCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "opts", "unpauseOptions", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "RequiresMinArgs", "(", "1", ")", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "opts", ".", "containers", "=", "args", "\n", "return", "runUnpause", "(", "dockerCli", ",", "&", "opts", ")", "\n", "}", ",", "}", "\n", "return", "cmd", "\n", "}" ]
// NewUnpauseCommand creates a new cobra.Command for `docker unpause`
[ "NewUnpauseCommand", "creates", "a", "new", "cobra", ".", "Command", "for", "docker", "unpause" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/unpause.go#L19-L32
train
docker/cli
cli/command/config/cmd.go
NewConfigCommand
func NewConfigCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "config", Short: "Manage Docker configs", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{ "version": "1.30", "swarm": "", }, } cmd.AddCommand( newConfigListCommand(dockerCli), newConfigCreateCommand(dockerCli), newConfigInspectCommand(dockerCli), newConfigRemoveCommand(dockerCli), ) return cmd }
go
func NewConfigCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "config", Short: "Manage Docker configs", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{ "version": "1.30", "swarm": "", }, } cmd.AddCommand( newConfigListCommand(dockerCli), newConfigCreateCommand(dockerCli), newConfigInspectCommand(dockerCli), newConfigRemoveCommand(dockerCli), ) return cmd }
[ "func", "NewConfigCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "command", ".", "ShowHelp", "(", "dockerCli", ".", "Err", "(", ")", ")", ",", "Annotations", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "}", ",", "}", "\n", "cmd", ".", "AddCommand", "(", "newConfigListCommand", "(", "dockerCli", ")", ",", "newConfigCreateCommand", "(", "dockerCli", ")", ",", "newConfigInspectCommand", "(", "dockerCli", ")", ",", "newConfigRemoveCommand", "(", "dockerCli", ")", ",", ")", "\n", "return", "cmd", "\n", "}" ]
// NewConfigCommand returns a cobra command for `config` subcommands
[ "NewConfigCommand", "returns", "a", "cobra", "command", "for", "config", "subcommands" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/config/cmd.go#L11-L29
train
docker/cli
kubernetes/check.go
GetStackAPIVersion
func GetStackAPIVersion(serverGroups discovery.ServerGroupsInterface, experimental bool) (StackVersion, error) { groups, err := serverGroups.ServerGroups() if err != nil { return "", err } return getAPIVersion(groups, experimental) }
go
func GetStackAPIVersion(serverGroups discovery.ServerGroupsInterface, experimental bool) (StackVersion, error) { groups, err := serverGroups.ServerGroups() if err != nil { return "", err } return getAPIVersion(groups, experimental) }
[ "func", "GetStackAPIVersion", "(", "serverGroups", "discovery", ".", "ServerGroupsInterface", ",", "experimental", "bool", ")", "(", "StackVersion", ",", "error", ")", "{", "groups", ",", "err", ":=", "serverGroups", ".", "ServerGroups", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n\n", "return", "getAPIVersion", "(", "groups", ",", "experimental", ")", "\n", "}" ]
// GetStackAPIVersion returns the most appropriate stack API version installed.
[ "GetStackAPIVersion", "returns", "the", "most", "appropriate", "stack", "API", "version", "installed", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/kubernetes/check.go#L27-L34
train
docker/cli
cli/command/stack/swarm/services.go
RunServices
func RunServices(dockerCli command.Cli, opts options.Services) error { ctx := context.Background() client := dockerCli.Client() filter := getStackFilterFromOpt(opts.Namespace, opts.Filter) services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: filter}) if err != nil { return err } // if no services in this stack, print message and exit 0 if len(services) == 0 { fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", opts.Namespace) return nil } info := map[string]service.ListInfo{} if !opts.Quiet { taskFilter := filters.NewArgs() for _, service := range services { taskFilter.Add("service", service.ID) } tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: taskFilter}) if err != nil { return err } nodes, err := client.NodeList(ctx, types.NodeListOptions{}) if err != nil { return err } info = service.GetServicesStatus(services, nodes, tasks) } format := opts.Format if len(format) == 0 { if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !opts.Quiet { format = dockerCli.ConfigFile().ServicesFormat } else { format = formatter.TableFormatKey } } servicesCtx := formatter.Context{ Output: dockerCli.Out(), Format: service.NewListFormat(format, opts.Quiet), } return service.ListFormatWrite(servicesCtx, services, info) }
go
func RunServices(dockerCli command.Cli, opts options.Services) error { ctx := context.Background() client := dockerCli.Client() filter := getStackFilterFromOpt(opts.Namespace, opts.Filter) services, err := client.ServiceList(ctx, types.ServiceListOptions{Filters: filter}) if err != nil { return err } // if no services in this stack, print message and exit 0 if len(services) == 0 { fmt.Fprintf(dockerCli.Err(), "Nothing found in stack: %s\n", opts.Namespace) return nil } info := map[string]service.ListInfo{} if !opts.Quiet { taskFilter := filters.NewArgs() for _, service := range services { taskFilter.Add("service", service.ID) } tasks, err := client.TaskList(ctx, types.TaskListOptions{Filters: taskFilter}) if err != nil { return err } nodes, err := client.NodeList(ctx, types.NodeListOptions{}) if err != nil { return err } info = service.GetServicesStatus(services, nodes, tasks) } format := opts.Format if len(format) == 0 { if len(dockerCli.ConfigFile().ServicesFormat) > 0 && !opts.Quiet { format = dockerCli.ConfigFile().ServicesFormat } else { format = formatter.TableFormatKey } } servicesCtx := formatter.Context{ Output: dockerCli.Out(), Format: service.NewListFormat(format, opts.Quiet), } return service.ListFormatWrite(servicesCtx, services, info) }
[ "func", "RunServices", "(", "dockerCli", "command", ".", "Cli", ",", "opts", "options", ".", "Services", ")", "error", "{", "ctx", ":=", "context", ".", "Background", "(", ")", "\n", "client", ":=", "dockerCli", ".", "Client", "(", ")", "\n\n", "filter", ":=", "getStackFilterFromOpt", "(", "opts", ".", "Namespace", ",", "opts", ".", "Filter", ")", "\n", "services", ",", "err", ":=", "client", ".", "ServiceList", "(", "ctx", ",", "types", ".", "ServiceListOptions", "{", "Filters", ":", "filter", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// if no services in this stack, print message and exit 0", "if", "len", "(", "services", ")", "==", "0", "{", "fmt", ".", "Fprintf", "(", "dockerCli", ".", "Err", "(", ")", ",", "\"", "\\n", "\"", ",", "opts", ".", "Namespace", ")", "\n", "return", "nil", "\n", "}", "\n\n", "info", ":=", "map", "[", "string", "]", "service", ".", "ListInfo", "{", "}", "\n", "if", "!", "opts", ".", "Quiet", "{", "taskFilter", ":=", "filters", ".", "NewArgs", "(", ")", "\n", "for", "_", ",", "service", ":=", "range", "services", "{", "taskFilter", ".", "Add", "(", "\"", "\"", ",", "service", ".", "ID", ")", "\n", "}", "\n\n", "tasks", ",", "err", ":=", "client", ".", "TaskList", "(", "ctx", ",", "types", ".", "TaskListOptions", "{", "Filters", ":", "taskFilter", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "nodes", ",", "err", ":=", "client", ".", "NodeList", "(", "ctx", ",", "types", ".", "NodeListOptions", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "info", "=", "service", ".", "GetServicesStatus", "(", "services", ",", "nodes", ",", "tasks", ")", "\n", "}", "\n\n", "format", ":=", "opts", ".", "Format", "\n", "if", "len", "(", "format", ")", "==", "0", "{", "if", "len", "(", "dockerCli", ".", "ConfigFile", "(", ")", ".", "ServicesFormat", ")", ">", "0", "&&", "!", "opts", ".", "Quiet", "{", "format", "=", "dockerCli", ".", "ConfigFile", "(", ")", ".", "ServicesFormat", "\n", "}", "else", "{", "format", "=", "formatter", ".", "TableFormatKey", "\n", "}", "\n", "}", "\n\n", "servicesCtx", ":=", "formatter", ".", "Context", "{", "Output", ":", "dockerCli", ".", "Out", "(", ")", ",", "Format", ":", "service", ".", "NewListFormat", "(", "format", ",", "opts", ".", "Quiet", ")", ",", "}", "\n", "return", "service", ".", "ListFormatWrite", "(", "servicesCtx", ",", "services", ",", "info", ")", "\n", "}" ]
// RunServices is the swarm implementation of docker stack services
[ "RunServices", "is", "the", "swarm", "implementation", "of", "docker", "stack", "services" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/swarm/services.go#L16-L66
train
docker/cli
cli/command/context/export.go
RunExport
func RunExport(dockerCli command.Cli, opts *ExportOptions) error { if err := validateContextName(opts.ContextName); err != nil && opts.ContextName != command.DefaultContextName { return err } ctxMeta, err := dockerCli.ContextStore().GetMetadata(opts.ContextName) if err != nil { return err } if !opts.Kubeconfig { reader := store.Export(opts.ContextName, dockerCli.ContextStore()) defer reader.Close() return writeTo(dockerCli, reader, opts.Dest) } kubernetesEndpointMeta := kubernetes.EndpointFromContext(ctxMeta) if kubernetesEndpointMeta == nil { return fmt.Errorf("context %q has no kubernetes endpoint", opts.ContextName) } kubernetesEndpoint, err := kubernetesEndpointMeta.WithTLSData(dockerCli.ContextStore(), opts.ContextName) if err != nil { return err } kubeConfig := kubernetesEndpoint.KubernetesConfig() rawCfg, err := kubeConfig.RawConfig() if err != nil { return err } data, err := clientcmd.Write(rawCfg) if err != nil { return err } return writeTo(dockerCli, bytes.NewBuffer(data), opts.Dest) }
go
func RunExport(dockerCli command.Cli, opts *ExportOptions) error { if err := validateContextName(opts.ContextName); err != nil && opts.ContextName != command.DefaultContextName { return err } ctxMeta, err := dockerCli.ContextStore().GetMetadata(opts.ContextName) if err != nil { return err } if !opts.Kubeconfig { reader := store.Export(opts.ContextName, dockerCli.ContextStore()) defer reader.Close() return writeTo(dockerCli, reader, opts.Dest) } kubernetesEndpointMeta := kubernetes.EndpointFromContext(ctxMeta) if kubernetesEndpointMeta == nil { return fmt.Errorf("context %q has no kubernetes endpoint", opts.ContextName) } kubernetesEndpoint, err := kubernetesEndpointMeta.WithTLSData(dockerCli.ContextStore(), opts.ContextName) if err != nil { return err } kubeConfig := kubernetesEndpoint.KubernetesConfig() rawCfg, err := kubeConfig.RawConfig() if err != nil { return err } data, err := clientcmd.Write(rawCfg) if err != nil { return err } return writeTo(dockerCli, bytes.NewBuffer(data), opts.Dest) }
[ "func", "RunExport", "(", "dockerCli", "command", ".", "Cli", ",", "opts", "*", "ExportOptions", ")", "error", "{", "if", "err", ":=", "validateContextName", "(", "opts", ".", "ContextName", ")", ";", "err", "!=", "nil", "&&", "opts", ".", "ContextName", "!=", "command", ".", "DefaultContextName", "{", "return", "err", "\n", "}", "\n", "ctxMeta", ",", "err", ":=", "dockerCli", ".", "ContextStore", "(", ")", ".", "GetMetadata", "(", "opts", ".", "ContextName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "if", "!", "opts", ".", "Kubeconfig", "{", "reader", ":=", "store", ".", "Export", "(", "opts", ".", "ContextName", ",", "dockerCli", ".", "ContextStore", "(", ")", ")", "\n", "defer", "reader", ".", "Close", "(", ")", "\n", "return", "writeTo", "(", "dockerCli", ",", "reader", ",", "opts", ".", "Dest", ")", "\n", "}", "\n", "kubernetesEndpointMeta", ":=", "kubernetes", ".", "EndpointFromContext", "(", "ctxMeta", ")", "\n", "if", "kubernetesEndpointMeta", "==", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "opts", ".", "ContextName", ")", "\n", "}", "\n", "kubernetesEndpoint", ",", "err", ":=", "kubernetesEndpointMeta", ".", "WithTLSData", "(", "dockerCli", ".", "ContextStore", "(", ")", ",", "opts", ".", "ContextName", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "kubeConfig", ":=", "kubernetesEndpoint", ".", "KubernetesConfig", "(", ")", "\n", "rawCfg", ",", "err", ":=", "kubeConfig", ".", "RawConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "data", ",", "err", ":=", "clientcmd", ".", "Write", "(", "rawCfg", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "writeTo", "(", "dockerCli", ",", "bytes", ".", "NewBuffer", "(", "data", ")", ",", "opts", ".", "Dest", ")", "\n", "}" ]
// RunExport exports a Docker context
[ "RunExport", "exports", "a", "Docker", "context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/context/export.go#L79-L110
train
docker/cli
cli/command/service/helpers.go
waitOnService
func waitOnService(ctx context.Context, dockerCli command.Cli, serviceID string, quiet bool) error { errChan := make(chan error, 1) pipeReader, pipeWriter := io.Pipe() go func() { errChan <- progress.ServiceProgress(ctx, dockerCli.Client(), serviceID, pipeWriter) }() if quiet { go io.Copy(ioutil.Discard, pipeReader) return <-errChan } err := jsonmessage.DisplayJSONMessagesToStream(pipeReader, dockerCli.Out(), nil) if err == nil { err = <-errChan } return err }
go
func waitOnService(ctx context.Context, dockerCli command.Cli, serviceID string, quiet bool) error { errChan := make(chan error, 1) pipeReader, pipeWriter := io.Pipe() go func() { errChan <- progress.ServiceProgress(ctx, dockerCli.Client(), serviceID, pipeWriter) }() if quiet { go io.Copy(ioutil.Discard, pipeReader) return <-errChan } err := jsonmessage.DisplayJSONMessagesToStream(pipeReader, dockerCli.Out(), nil) if err == nil { err = <-errChan } return err }
[ "func", "waitOnService", "(", "ctx", "context", ".", "Context", ",", "dockerCli", "command", ".", "Cli", ",", "serviceID", "string", ",", "quiet", "bool", ")", "error", "{", "errChan", ":=", "make", "(", "chan", "error", ",", "1", ")", "\n", "pipeReader", ",", "pipeWriter", ":=", "io", ".", "Pipe", "(", ")", "\n\n", "go", "func", "(", ")", "{", "errChan", "<-", "progress", ".", "ServiceProgress", "(", "ctx", ",", "dockerCli", ".", "Client", "(", ")", ",", "serviceID", ",", "pipeWriter", ")", "\n", "}", "(", ")", "\n\n", "if", "quiet", "{", "go", "io", ".", "Copy", "(", "ioutil", ".", "Discard", ",", "pipeReader", ")", "\n", "return", "<-", "errChan", "\n", "}", "\n\n", "err", ":=", "jsonmessage", ".", "DisplayJSONMessagesToStream", "(", "pipeReader", ",", "dockerCli", ".", "Out", "(", ")", ",", "nil", ")", "\n", "if", "err", "==", "nil", "{", "err", "=", "<-", "errChan", "\n", "}", "\n", "return", "err", "\n", "}" ]
// waitOnService waits for the service to converge. It outputs a progress bar, // if appropriate based on the CLI flags.
[ "waitOnService", "waits", "for", "the", "service", "to", "converge", ".", "It", "outputs", "a", "progress", "bar", "if", "appropriate", "based", "on", "the", "CLI", "flags", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/service/helpers.go#L15-L33
train
docker/cli
cli/command/image/import.go
NewImportCommand
func NewImportCommand(dockerCli command.Cli) *cobra.Command { var options importOptions cmd := &cobra.Command{ Use: "import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]", Short: "Import the contents from a tarball to create a filesystem image", Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { options.source = args[0] if len(args) > 1 { options.reference = args[1] } return runImport(dockerCli, options) }, } flags := cmd.Flags() options.changes = dockeropts.NewListOpts(nil) flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image") flags.StringVarP(&options.message, "message", "m", "", "Set commit message for imported image") command.AddPlatformFlag(flags, &options.platform) return cmd }
go
func NewImportCommand(dockerCli command.Cli) *cobra.Command { var options importOptions cmd := &cobra.Command{ Use: "import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]", Short: "Import the contents from a tarball to create a filesystem image", Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { options.source = args[0] if len(args) > 1 { options.reference = args[1] } return runImport(dockerCli, options) }, } flags := cmd.Flags() options.changes = dockeropts.NewListOpts(nil) flags.VarP(&options.changes, "change", "c", "Apply Dockerfile instruction to the created image") flags.StringVarP(&options.message, "message", "m", "", "Set commit message for imported image") command.AddPlatformFlag(flags, &options.platform) return cmd }
[ "func", "NewImportCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "options", "importOptions", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "RequiresMinArgs", "(", "1", ")", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "options", ".", "source", "=", "args", "[", "0", "]", "\n", "if", "len", "(", "args", ")", ">", "1", "{", "options", ".", "reference", "=", "args", "[", "1", "]", "\n", "}", "\n", "return", "runImport", "(", "dockerCli", ",", "options", ")", "\n", "}", ",", "}", "\n\n", "flags", ":=", "cmd", ".", "Flags", "(", ")", "\n\n", "options", ".", "changes", "=", "dockeropts", ".", "NewListOpts", "(", "nil", ")", "\n", "flags", ".", "VarP", "(", "&", "options", ".", "changes", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVarP", "(", "&", "options", ".", "message", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "command", ".", "AddPlatformFlag", "(", "flags", ",", "&", "options", ".", "platform", ")", "\n\n", "return", "cmd", "\n", "}" ]
// NewImportCommand creates a new `docker import` command
[ "NewImportCommand", "creates", "a", "new", "docker", "import", "command" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/import.go#L26-L50
train
docker/cli
cli/command/image/push.go
NewPushCommand
func NewPushCommand(dockerCli command.Cli) *cobra.Command { var opts pushOptions cmd := &cobra.Command{ Use: "push [OPTIONS] NAME[:TAG]", Short: "Push an image or a repository to a registry", Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.remote = args[0] return RunPush(dockerCli, opts) }, } flags := cmd.Flags() command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled()) return cmd }
go
func NewPushCommand(dockerCli command.Cli) *cobra.Command { var opts pushOptions cmd := &cobra.Command{ Use: "push [OPTIONS] NAME[:TAG]", Short: "Push an image or a repository to a registry", Args: cli.ExactArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.remote = args[0] return RunPush(dockerCli, opts) }, } flags := cmd.Flags() command.AddTrustSigningFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled()) return cmd }
[ "func", "NewPushCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "opts", "pushOptions", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "ExactArgs", "(", "1", ")", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "opts", ".", "remote", "=", "args", "[", "0", "]", "\n", "return", "RunPush", "(", "dockerCli", ",", "opts", ")", "\n", "}", ",", "}", "\n\n", "flags", ":=", "cmd", ".", "Flags", "(", ")", "\n\n", "command", ".", "AddTrustSigningFlags", "(", "flags", ",", "&", "opts", ".", "untrusted", ",", "dockerCli", ".", "ContentTrustEnabled", "(", ")", ")", "\n\n", "return", "cmd", "\n", "}" ]
// NewPushCommand creates a new `docker push` command
[ "NewPushCommand", "creates", "a", "new", "docker", "push", "command" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/push.go#L20-L38
train
docker/cli
cli/command/image/push.go
RunPush
func RunPush(dockerCli command.Cli, opts pushOptions) error { ref, err := reference.ParseNormalizedNamed(opts.remote) if err != nil { return err } // Resolve the Repository name from fqn to RepositoryInfo repoInfo, err := registry.ParseRepositoryInfo(ref) if err != nil { return err } ctx := context.Background() // Resolve the Auth config relevant for this server authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index) requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "push") if !opts.untrusted { return TrustedPush(ctx, dockerCli, repoInfo, ref, authConfig, requestPrivilege) } responseBody, err := imagePushPrivileged(ctx, dockerCli, authConfig, ref, requestPrivilege) if err != nil { return err } defer responseBody.Close() return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) }
go
func RunPush(dockerCli command.Cli, opts pushOptions) error { ref, err := reference.ParseNormalizedNamed(opts.remote) if err != nil { return err } // Resolve the Repository name from fqn to RepositoryInfo repoInfo, err := registry.ParseRepositoryInfo(ref) if err != nil { return err } ctx := context.Background() // Resolve the Auth config relevant for this server authConfig := command.ResolveAuthConfig(ctx, dockerCli, repoInfo.Index) requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(dockerCli, repoInfo.Index, "push") if !opts.untrusted { return TrustedPush(ctx, dockerCli, repoInfo, ref, authConfig, requestPrivilege) } responseBody, err := imagePushPrivileged(ctx, dockerCli, authConfig, ref, requestPrivilege) if err != nil { return err } defer responseBody.Close() return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) }
[ "func", "RunPush", "(", "dockerCli", "command", ".", "Cli", ",", "opts", "pushOptions", ")", "error", "{", "ref", ",", "err", ":=", "reference", ".", "ParseNormalizedNamed", "(", "opts", ".", "remote", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "// Resolve the Repository name from fqn to RepositoryInfo", "repoInfo", ",", "err", ":=", "registry", ".", "ParseRepositoryInfo", "(", "ref", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "ctx", ":=", "context", ".", "Background", "(", ")", "\n\n", "// Resolve the Auth config relevant for this server", "authConfig", ":=", "command", ".", "ResolveAuthConfig", "(", "ctx", ",", "dockerCli", ",", "repoInfo", ".", "Index", ")", "\n", "requestPrivilege", ":=", "command", ".", "RegistryAuthenticationPrivilegedFunc", "(", "dockerCli", ",", "repoInfo", ".", "Index", ",", "\"", "\"", ")", "\n\n", "if", "!", "opts", ".", "untrusted", "{", "return", "TrustedPush", "(", "ctx", ",", "dockerCli", ",", "repoInfo", ",", "ref", ",", "authConfig", ",", "requestPrivilege", ")", "\n", "}", "\n\n", "responseBody", ",", "err", ":=", "imagePushPrivileged", "(", "ctx", ",", "dockerCli", ",", "authConfig", ",", "ref", ",", "requestPrivilege", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "defer", "responseBody", ".", "Close", "(", ")", "\n", "return", "jsonmessage", ".", "DisplayJSONMessagesToStream", "(", "responseBody", ",", "dockerCli", ".", "Out", "(", ")", ",", "nil", ")", "\n", "}" ]
// RunPush performs a push against the engine based on the specified options
[ "RunPush", "performs", "a", "push", "against", "the", "engine", "based", "on", "the", "specified", "options" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/push.go#L41-L70
train
docker/cli
opts/parse.go
ReadKVStrings
func ReadKVStrings(files []string, override []string) ([]string, error) { return readKVStrings(files, override, nil) }
go
func ReadKVStrings(files []string, override []string) ([]string, error) { return readKVStrings(files, override, nil) }
[ "func", "ReadKVStrings", "(", "files", "[", "]", "string", ",", "override", "[", "]", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "readKVStrings", "(", "files", ",", "override", ",", "nil", ")", "\n", "}" ]
// ReadKVStrings reads a file of line terminated key=value pairs, and overrides any keys // present in the file with additional pairs specified in the override parameter
[ "ReadKVStrings", "reads", "a", "file", "of", "line", "terminated", "key", "=", "value", "pairs", "and", "overrides", "any", "keys", "present", "in", "the", "file", "with", "additional", "pairs", "specified", "in", "the", "override", "parameter" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/parse.go#L14-L16
train
docker/cli
opts/parse.go
ReadKVEnvStrings
func ReadKVEnvStrings(files []string, override []string) ([]string, error) { return readKVStrings(files, override, os.LookupEnv) }
go
func ReadKVEnvStrings(files []string, override []string) ([]string, error) { return readKVStrings(files, override, os.LookupEnv) }
[ "func", "ReadKVEnvStrings", "(", "files", "[", "]", "string", ",", "override", "[", "]", "string", ")", "(", "[", "]", "string", ",", "error", ")", "{", "return", "readKVStrings", "(", "files", ",", "override", ",", "os", ".", "LookupEnv", ")", "\n", "}" ]
// ReadKVEnvStrings reads a file of line terminated key=value pairs, and overrides any keys // present in the file with additional pairs specified in the override parameter. // If a key has no value, it will get the value from the environment.
[ "ReadKVEnvStrings", "reads", "a", "file", "of", "line", "terminated", "key", "=", "value", "pairs", "and", "overrides", "any", "keys", "present", "in", "the", "file", "with", "additional", "pairs", "specified", "in", "the", "override", "parameter", ".", "If", "a", "key", "has", "no", "value", "it", "will", "get", "the", "value", "from", "the", "environment", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/parse.go#L21-L23
train
docker/cli
opts/parse.go
ParseRestartPolicy
func ParseRestartPolicy(policy string) (container.RestartPolicy, error) { p := container.RestartPolicy{} if policy == "" { return p, nil } parts := strings.Split(policy, ":") if len(parts) > 2 { return p, fmt.Errorf("invalid restart policy format") } if len(parts) == 2 { count, err := strconv.Atoi(parts[1]) if err != nil { return p, fmt.Errorf("maximum retry count must be an integer") } p.MaximumRetryCount = count } p.Name = parts[0] return p, nil }
go
func ParseRestartPolicy(policy string) (container.RestartPolicy, error) { p := container.RestartPolicy{} if policy == "" { return p, nil } parts := strings.Split(policy, ":") if len(parts) > 2 { return p, fmt.Errorf("invalid restart policy format") } if len(parts) == 2 { count, err := strconv.Atoi(parts[1]) if err != nil { return p, fmt.Errorf("maximum retry count must be an integer") } p.MaximumRetryCount = count } p.Name = parts[0] return p, nil }
[ "func", "ParseRestartPolicy", "(", "policy", "string", ")", "(", "container", ".", "RestartPolicy", ",", "error", ")", "{", "p", ":=", "container", ".", "RestartPolicy", "{", "}", "\n\n", "if", "policy", "==", "\"", "\"", "{", "return", "p", ",", "nil", "\n", "}", "\n\n", "parts", ":=", "strings", ".", "Split", "(", "policy", ",", "\"", "\"", ")", "\n\n", "if", "len", "(", "parts", ")", ">", "2", "{", "return", "p", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "len", "(", "parts", ")", "==", "2", "{", "count", ",", "err", ":=", "strconv", ".", "Atoi", "(", "parts", "[", "1", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "p", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "p", ".", "MaximumRetryCount", "=", "count", "\n", "}", "\n\n", "p", ".", "Name", "=", "parts", "[", "0", "]", "\n\n", "return", "p", ",", "nil", "\n", "}" ]
// ParseRestartPolicy returns the parsed policy or an error indicating what is incorrect
[ "ParseRestartPolicy", "returns", "the", "parsed", "policy", "or", "an", "error", "indicating", "what", "is", "incorrect" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/parse.go#L75-L99
train
docker/cli
cli/command/system/info.go
NewInfoCommand
func NewInfoCommand(dockerCli command.Cli) *cobra.Command { var opts infoOptions cmd := &cobra.Command{ Use: "info [OPTIONS]", Short: "Display system-wide information", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return runInfo(cmd, dockerCli, &opts) }, } flags := cmd.Flags() flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") return cmd }
go
func NewInfoCommand(dockerCli command.Cli) *cobra.Command { var opts infoOptions cmd := &cobra.Command{ Use: "info [OPTIONS]", Short: "Display system-wide information", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return runInfo(cmd, dockerCli, &opts) }, } flags := cmd.Flags() flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template") return cmd }
[ "func", "NewInfoCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "opts", "infoOptions", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "return", "runInfo", "(", "cmd", ",", "dockerCli", ",", "&", "opts", ")", "\n", "}", ",", "}", "\n\n", "flags", ":=", "cmd", ".", "Flags", "(", ")", "\n\n", "flags", ".", "StringVarP", "(", "&", "opts", ".", "format", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "return", "cmd", "\n", "}" ]
// NewInfoCommand creates a new cobra.Command for `docker info`
[ "NewInfoCommand", "creates", "a", "new", "cobra", ".", "Command", "for", "docker", "info" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/info.go#L44-L61
train
docker/cli
cli/command/config/inspect.go
RunConfigInspect
func RunConfigInspect(dockerCli command.Cli, opts InspectOptions) error { client := dockerCli.Client() ctx := context.Background() if opts.Pretty { opts.Format = "pretty" } getRef := func(id string) (interface{}, []byte, error) { return client.ConfigInspectWithRaw(ctx, id) } f := opts.Format // check if the user is trying to apply a template to the pretty format, which // is not supported if strings.HasPrefix(f, "pretty") && f != "pretty" { return fmt.Errorf("Cannot supply extra formatting options to the pretty template") } configCtx := formatter.Context{ Output: dockerCli.Out(), Format: NewFormat(f, false), } if err := InspectFormatWrite(configCtx, opts.Names, getRef); err != nil { return cli.StatusError{StatusCode: 1, Status: err.Error()} } return nil }
go
func RunConfigInspect(dockerCli command.Cli, opts InspectOptions) error { client := dockerCli.Client() ctx := context.Background() if opts.Pretty { opts.Format = "pretty" } getRef := func(id string) (interface{}, []byte, error) { return client.ConfigInspectWithRaw(ctx, id) } f := opts.Format // check if the user is trying to apply a template to the pretty format, which // is not supported if strings.HasPrefix(f, "pretty") && f != "pretty" { return fmt.Errorf("Cannot supply extra formatting options to the pretty template") } configCtx := formatter.Context{ Output: dockerCli.Out(), Format: NewFormat(f, false), } if err := InspectFormatWrite(configCtx, opts.Names, getRef); err != nil { return cli.StatusError{StatusCode: 1, Status: err.Error()} } return nil }
[ "func", "RunConfigInspect", "(", "dockerCli", "command", ".", "Cli", ",", "opts", "InspectOptions", ")", "error", "{", "client", ":=", "dockerCli", ".", "Client", "(", ")", "\n", "ctx", ":=", "context", ".", "Background", "(", ")", "\n\n", "if", "opts", ".", "Pretty", "{", "opts", ".", "Format", "=", "\"", "\"", "\n", "}", "\n\n", "getRef", ":=", "func", "(", "id", "string", ")", "(", "interface", "{", "}", ",", "[", "]", "byte", ",", "error", ")", "{", "return", "client", ".", "ConfigInspectWithRaw", "(", "ctx", ",", "id", ")", "\n", "}", "\n", "f", ":=", "opts", ".", "Format", "\n\n", "// check if the user is trying to apply a template to the pretty format, which", "// is not supported", "if", "strings", ".", "HasPrefix", "(", "f", ",", "\"", "\"", ")", "&&", "f", "!=", "\"", "\"", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "}", "\n\n", "configCtx", ":=", "formatter", ".", "Context", "{", "Output", ":", "dockerCli", ".", "Out", "(", ")", ",", "Format", ":", "NewFormat", "(", "f", ",", "false", ")", ",", "}", "\n\n", "if", "err", ":=", "InspectFormatWrite", "(", "configCtx", ",", "opts", ".", "Names", ",", "getRef", ")", ";", "err", "!=", "nil", "{", "return", "cli", ".", "StatusError", "{", "StatusCode", ":", "1", ",", "Status", ":", "err", ".", "Error", "(", ")", "}", "\n", "}", "\n", "return", "nil", "\n\n", "}" ]
// RunConfigInspect inspects the given Swarm config.
[ "RunConfigInspect", "inspects", "the", "given", "Swarm", "config", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/config/inspect.go#L39-L68
train
docker/cli
cli/command/formatter/context.go
NewClientContextFormat
func NewClientContextFormat(source string, quiet bool) Format { if quiet { return Format(quietContextFormat) } if source == TableFormatKey { return Format(ClientContextTableFormat) } return Format(source) }
go
func NewClientContextFormat(source string, quiet bool) Format { if quiet { return Format(quietContextFormat) } if source == TableFormatKey { return Format(ClientContextTableFormat) } return Format(source) }
[ "func", "NewClientContextFormat", "(", "source", "string", ",", "quiet", "bool", ")", "Format", "{", "if", "quiet", "{", "return", "Format", "(", "quietContextFormat", ")", "\n", "}", "\n", "if", "source", "==", "TableFormatKey", "{", "return", "Format", "(", "ClientContextTableFormat", ")", "\n", "}", "\n", "return", "Format", "(", "source", ")", "\n", "}" ]
// NewClientContextFormat returns a Format for rendering using a Context
[ "NewClientContextFormat", "returns", "a", "Format", "for", "rendering", "using", "a", "Context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/formatter/context.go#L14-L22
train
docker/cli
cli/command/formatter/context.go
ClientContextWrite
func ClientContextWrite(ctx Context, contexts []*ClientContext) error { render := func(format func(subContext SubContext) error) error { for _, context := range contexts { if err := format(&clientContextContext{c: context}); err != nil { return err } } return nil } return ctx.Write(newClientContextContext(), render) }
go
func ClientContextWrite(ctx Context, contexts []*ClientContext) error { render := func(format func(subContext SubContext) error) error { for _, context := range contexts { if err := format(&clientContextContext{c: context}); err != nil { return err } } return nil } return ctx.Write(newClientContextContext(), render) }
[ "func", "ClientContextWrite", "(", "ctx", "Context", ",", "contexts", "[", "]", "*", "ClientContext", ")", "error", "{", "render", ":=", "func", "(", "format", "func", "(", "subContext", "SubContext", ")", "error", ")", "error", "{", "for", "_", ",", "context", ":=", "range", "contexts", "{", "if", "err", ":=", "format", "(", "&", "clientContextContext", "{", "c", ":", "context", "}", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "return", "ctx", ".", "Write", "(", "newClientContextContext", "(", ")", ",", "render", ")", "\n", "}" ]
// ClientContextWrite writes formatted contexts using the Context
[ "ClientContextWrite", "writes", "formatted", "contexts", "using", "the", "Context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/formatter/context.go#L35-L45
train
docker/cli
cli/compose/schema/schema.go
Version
func Version(config map[string]interface{}) string { version, ok := config[versionField] if !ok { return defaultVersion } return normalizeVersion(fmt.Sprintf("%v", version)) }
go
func Version(config map[string]interface{}) string { version, ok := config[versionField] if !ok { return defaultVersion } return normalizeVersion(fmt.Sprintf("%v", version)) }
[ "func", "Version", "(", "config", "map", "[", "string", "]", "interface", "{", "}", ")", "string", "{", "version", ",", "ok", ":=", "config", "[", "versionField", "]", "\n", "if", "!", "ok", "{", "return", "defaultVersion", "\n", "}", "\n", "return", "normalizeVersion", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "version", ")", ")", "\n", "}" ]
// Version returns the version of the config, defaulting to version 1.0
[ "Version", "returns", "the", "version", "of", "the", "config", "defaulting", "to", "version", "1", ".", "0" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/schema/schema.go#L40-L46
train
docker/cli
cli/command/task/formatter.go
NewTaskFormat
func NewTaskFormat(source string, quiet bool) formatter.Format { switch source { case formatter.TableFormatKey: if quiet { return formatter.DefaultQuietFormat } return defaultTaskTableFormat case formatter.RawFormatKey: if quiet { return `id: {{.ID}}` } return `id: {{.ID}}\nname: {{.Name}}\nimage: {{.Image}}\nnode: {{.Node}}\ndesired_state: {{.DesiredState}}\ncurrent_state: {{.CurrentState}}\nerror: {{.Error}}\nports: {{.Ports}}\n` } return formatter.Format(source) }
go
func NewTaskFormat(source string, quiet bool) formatter.Format { switch source { case formatter.TableFormatKey: if quiet { return formatter.DefaultQuietFormat } return defaultTaskTableFormat case formatter.RawFormatKey: if quiet { return `id: {{.ID}}` } return `id: {{.ID}}\nname: {{.Name}}\nimage: {{.Image}}\nnode: {{.Node}}\ndesired_state: {{.DesiredState}}\ncurrent_state: {{.CurrentState}}\nerror: {{.Error}}\nports: {{.Ports}}\n` } return formatter.Format(source) }
[ "func", "NewTaskFormat", "(", "source", "string", ",", "quiet", "bool", ")", "formatter", ".", "Format", "{", "switch", "source", "{", "case", "formatter", ".", "TableFormatKey", ":", "if", "quiet", "{", "return", "formatter", ".", "DefaultQuietFormat", "\n", "}", "\n", "return", "defaultTaskTableFormat", "\n", "case", "formatter", ".", "RawFormatKey", ":", "if", "quiet", "{", "return", "`id: {{.ID}}`", "\n", "}", "\n", "return", "`id: {{.ID}}\\nname: {{.Name}}\\nimage: {{.Image}}\\nnode: {{.Node}}\\ndesired_state: {{.DesiredState}}\\ncurrent_state: {{.CurrentState}}\\nerror: {{.Error}}\\nports: {{.Ports}}\\n`", "\n", "}", "\n", "return", "formatter", ".", "Format", "(", "source", ")", "\n", "}" ]
// NewTaskFormat returns a Format for rendering using a task Context
[ "NewTaskFormat", "returns", "a", "Format", "for", "rendering", "using", "a", "task", "Context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/task/formatter.go#L29-L43
train
docker/cli
cli/command/image/formatter_history.go
NewHistoryFormat
func NewHistoryFormat(source string, quiet bool, human bool) formatter.Format { switch source { case formatter.TableFormatKey: switch { case quiet: return formatter.DefaultQuietFormat case !human: return nonHumanHistoryTableFormat default: return defaultHistoryTableFormat } } return formatter.Format(source) }
go
func NewHistoryFormat(source string, quiet bool, human bool) formatter.Format { switch source { case formatter.TableFormatKey: switch { case quiet: return formatter.DefaultQuietFormat case !human: return nonHumanHistoryTableFormat default: return defaultHistoryTableFormat } } return formatter.Format(source) }
[ "func", "NewHistoryFormat", "(", "source", "string", ",", "quiet", "bool", ",", "human", "bool", ")", "formatter", ".", "Format", "{", "switch", "source", "{", "case", "formatter", ".", "TableFormatKey", ":", "switch", "{", "case", "quiet", ":", "return", "formatter", ".", "DefaultQuietFormat", "\n", "case", "!", "human", ":", "return", "nonHumanHistoryTableFormat", "\n", "default", ":", "return", "defaultHistoryTableFormat", "\n", "}", "\n", "}", "\n\n", "return", "formatter", ".", "Format", "(", "source", ")", "\n", "}" ]
// NewHistoryFormat returns a format for rendering an HistoryContext
[ "NewHistoryFormat", "returns", "a", "format", "for", "rendering", "an", "HistoryContext" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/formatter_history.go#L24-L38
train
docker/cli
cli/command/image/formatter_history.go
HistoryWrite
func HistoryWrite(ctx formatter.Context, human bool, histories []image.HistoryResponseItem) error { render := func(format func(subContext formatter.SubContext) error) error { for _, history := range histories { historyCtx := &historyContext{trunc: ctx.Trunc, h: history, human: human} if err := format(historyCtx); err != nil { return err } } return nil } historyCtx := &historyContext{} historyCtx.Header = formatter.SubHeaderContext{ "ID": historyIDHeader, "CreatedSince": formatter.CreatedSinceHeader, "CreatedAt": formatter.CreatedAtHeader, "CreatedBy": createdByHeader, "Size": formatter.SizeHeader, "Comment": commentHeader, } return ctx.Write(historyCtx, render) }
go
func HistoryWrite(ctx formatter.Context, human bool, histories []image.HistoryResponseItem) error { render := func(format func(subContext formatter.SubContext) error) error { for _, history := range histories { historyCtx := &historyContext{trunc: ctx.Trunc, h: history, human: human} if err := format(historyCtx); err != nil { return err } } return nil } historyCtx := &historyContext{} historyCtx.Header = formatter.SubHeaderContext{ "ID": historyIDHeader, "CreatedSince": formatter.CreatedSinceHeader, "CreatedAt": formatter.CreatedAtHeader, "CreatedBy": createdByHeader, "Size": formatter.SizeHeader, "Comment": commentHeader, } return ctx.Write(historyCtx, render) }
[ "func", "HistoryWrite", "(", "ctx", "formatter", ".", "Context", ",", "human", "bool", ",", "histories", "[", "]", "image", ".", "HistoryResponseItem", ")", "error", "{", "render", ":=", "func", "(", "format", "func", "(", "subContext", "formatter", ".", "SubContext", ")", "error", ")", "error", "{", "for", "_", ",", "history", ":=", "range", "histories", "{", "historyCtx", ":=", "&", "historyContext", "{", "trunc", ":", "ctx", ".", "Trunc", ",", "h", ":", "history", ",", "human", ":", "human", "}", "\n", "if", "err", ":=", "format", "(", "historyCtx", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}", "\n", "historyCtx", ":=", "&", "historyContext", "{", "}", "\n", "historyCtx", ".", "Header", "=", "formatter", ".", "SubHeaderContext", "{", "\"", "\"", ":", "historyIDHeader", ",", "\"", "\"", ":", "formatter", ".", "CreatedSinceHeader", ",", "\"", "\"", ":", "formatter", ".", "CreatedAtHeader", ",", "\"", "\"", ":", "createdByHeader", ",", "\"", "\"", ":", "formatter", ".", "SizeHeader", ",", "\"", "\"", ":", "commentHeader", ",", "}", "\n", "return", "ctx", ".", "Write", "(", "historyCtx", ",", "render", ")", "\n", "}" ]
// HistoryWrite writes the context
[ "HistoryWrite", "writes", "the", "context" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/formatter_history.go#L41-L61
train
docker/cli
cli/command/engine/activate.go
newActivateCommand
func newActivateCommand(dockerCli command.Cli) *cobra.Command { var options activateOptions options.licenseLoginFunc = licenseutils.Login cmd := &cobra.Command{ Use: "activate [OPTIONS]", Short: "Activate Enterprise Edition", Long: `Activate Enterprise Edition. With this command you may apply an existing Docker enterprise license, or interactively download one from Docker. In the interactive exchange, you can sign up for a new trial, or download an existing license. If you are currently running a Community Edition engine, the daemon will be updated to the Enterprise Edition Docker engine with additional capabilities and long term support. For more information about different Docker Enterprise license types visit https://www.docker.com/licenses For non-interactive scriptable deployments, download your license from https://hub.docker.com/ then specify the file with the '--license' flag. `, RunE: func(cmd *cobra.Command, args []string) error { return runActivate(dockerCli, options) }, } flags := cmd.Flags() flags.StringVar(&options.licenseFile, "license", "", "License File") flags.StringVar(&options.version, "version", "", "Specify engine version (default is to use currently running version)") flags.StringVar(&options.registryPrefix, "registry-prefix", clitypes.RegistryPrefix, "Override the default location where engine images are pulled") flags.StringVar(&options.image, "engine-image", "", "Specify engine image") flags.StringVar(&options.format, "format", "", "Pretty-print licenses using a Go template") flags.BoolVar(&options.displayOnly, "display-only", false, "only display license information and exit") flags.BoolVar(&options.quiet, "quiet", false, "Only display available licenses by ID") flags.StringVar(&options.sockPath, "containerd", "", "override default location of containerd endpoint") return cmd }
go
func newActivateCommand(dockerCli command.Cli) *cobra.Command { var options activateOptions options.licenseLoginFunc = licenseutils.Login cmd := &cobra.Command{ Use: "activate [OPTIONS]", Short: "Activate Enterprise Edition", Long: `Activate Enterprise Edition. With this command you may apply an existing Docker enterprise license, or interactively download one from Docker. In the interactive exchange, you can sign up for a new trial, or download an existing license. If you are currently running a Community Edition engine, the daemon will be updated to the Enterprise Edition Docker engine with additional capabilities and long term support. For more information about different Docker Enterprise license types visit https://www.docker.com/licenses For non-interactive scriptable deployments, download your license from https://hub.docker.com/ then specify the file with the '--license' flag. `, RunE: func(cmd *cobra.Command, args []string) error { return runActivate(dockerCli, options) }, } flags := cmd.Flags() flags.StringVar(&options.licenseFile, "license", "", "License File") flags.StringVar(&options.version, "version", "", "Specify engine version (default is to use currently running version)") flags.StringVar(&options.registryPrefix, "registry-prefix", clitypes.RegistryPrefix, "Override the default location where engine images are pulled") flags.StringVar(&options.image, "engine-image", "", "Specify engine image") flags.StringVar(&options.format, "format", "", "Pretty-print licenses using a Go template") flags.BoolVar(&options.displayOnly, "display-only", false, "only display license information and exit") flags.BoolVar(&options.quiet, "quiet", false, "Only display available licenses by ID") flags.StringVar(&options.sockPath, "containerd", "", "override default location of containerd endpoint") return cmd }
[ "func", "newActivateCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "options", "activateOptions", "\n", "options", ".", "licenseLoginFunc", "=", "licenseutils", ".", "Login", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Long", ":", "`Activate Enterprise Edition.\n\nWith this command you may apply an existing Docker enterprise license, or\ninteractively download one from Docker. In the interactive exchange, you can\nsign up for a new trial, or download an existing license. If you are\ncurrently running a Community Edition engine, the daemon will be updated to\nthe Enterprise Edition Docker engine with additional capabilities and long\nterm support.\n\nFor more information about different Docker Enterprise license types visit\nhttps://www.docker.com/licenses\n\nFor non-interactive scriptable deployments, download your license from\nhttps://hub.docker.com/ then specify the file with the '--license' flag.\n`", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "return", "runActivate", "(", "dockerCli", ",", "options", ")", "\n", "}", ",", "}", "\n\n", "flags", ":=", "cmd", ".", "Flags", "(", ")", "\n\n", "flags", ".", "StringVar", "(", "&", "options", ".", "licenseFile", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVar", "(", "&", "options", ".", "version", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVar", "(", "&", "options", ".", "registryPrefix", ",", "\"", "\"", ",", "clitypes", ".", "RegistryPrefix", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVar", "(", "&", "options", ".", "image", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVar", "(", "&", "options", ".", "format", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVar", "(", "&", "options", ".", "displayOnly", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVar", "(", "&", "options", ".", "quiet", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVar", "(", "&", "options", ".", "sockPath", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n\n", "return", "cmd", "\n", "}" ]
// newActivateCommand creates a new `docker engine activate` command
[ "newActivateCommand", "creates", "a", "new", "docker", "engine", "activate", "command" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/engine/activate.go#L31-L70
train
docker/cli
cli-plugins/manager/plugin.go
newPlugin
func newPlugin(c Candidate, rootcmd *cobra.Command) (Plugin, error) { path := c.Path() if path == "" { return Plugin{}, errors.New("plugin candidate path cannot be empty") } // The candidate listing process should have skipped anything // which would fail here, so there are all real errors. fullname := filepath.Base(path) if fullname == "." { return Plugin{}, errors.Errorf("unable to determine basename of plugin candidate %q", path) } var err error if fullname, err = trimExeSuffix(fullname); err != nil { return Plugin{}, errors.Wrapf(err, "plugin candidate %q", path) } if !strings.HasPrefix(fullname, NamePrefix) { return Plugin{}, errors.Errorf("plugin candidate %q: does not have %q prefix", path, NamePrefix) } p := Plugin{ Name: strings.TrimPrefix(fullname, NamePrefix), Path: path, } // Now apply the candidate tests, so these update p.Err. if !pluginNameRe.MatchString(p.Name) { p.Err = NewPluginError("plugin candidate %q did not match %q", p.Name, pluginNameRe.String()) return p, nil } if rootcmd != nil { for _, cmd := range rootcmd.Commands() { // Ignore conflicts with commands which are // just plugin stubs (i.e. from a previous // call to AddPluginCommandStubs). if p := cmd.Annotations[CommandAnnotationPlugin]; p == "true" { continue } if cmd.Name() == p.Name { p.Err = NewPluginError("plugin %q duplicates builtin command", p.Name) return p, nil } if cmd.HasAlias(p.Name) { p.Err = NewPluginError("plugin %q duplicates an alias of builtin command %q", p.Name, cmd.Name()) return p, nil } } } // We are supposed to check for relevant execute permissions here. Instead we rely on an attempt to execute. meta, err := c.Metadata() if err != nil { p.Err = wrapAsPluginError(err, "failed to fetch metadata") return p, nil } if err := json.Unmarshal(meta, &p.Metadata); err != nil { p.Err = wrapAsPluginError(err, "invalid metadata") return p, nil } if p.Metadata.SchemaVersion != "0.1.0" { p.Err = NewPluginError("plugin SchemaVersion %q is not valid, must be 0.1.0", p.Metadata.SchemaVersion) return p, nil } if p.Metadata.Vendor == "" { p.Err = NewPluginError("plugin metadata does not define a vendor") return p, nil } return p, nil }
go
func newPlugin(c Candidate, rootcmd *cobra.Command) (Plugin, error) { path := c.Path() if path == "" { return Plugin{}, errors.New("plugin candidate path cannot be empty") } // The candidate listing process should have skipped anything // which would fail here, so there are all real errors. fullname := filepath.Base(path) if fullname == "." { return Plugin{}, errors.Errorf("unable to determine basename of plugin candidate %q", path) } var err error if fullname, err = trimExeSuffix(fullname); err != nil { return Plugin{}, errors.Wrapf(err, "plugin candidate %q", path) } if !strings.HasPrefix(fullname, NamePrefix) { return Plugin{}, errors.Errorf("plugin candidate %q: does not have %q prefix", path, NamePrefix) } p := Plugin{ Name: strings.TrimPrefix(fullname, NamePrefix), Path: path, } // Now apply the candidate tests, so these update p.Err. if !pluginNameRe.MatchString(p.Name) { p.Err = NewPluginError("plugin candidate %q did not match %q", p.Name, pluginNameRe.String()) return p, nil } if rootcmd != nil { for _, cmd := range rootcmd.Commands() { // Ignore conflicts with commands which are // just plugin stubs (i.e. from a previous // call to AddPluginCommandStubs). if p := cmd.Annotations[CommandAnnotationPlugin]; p == "true" { continue } if cmd.Name() == p.Name { p.Err = NewPluginError("plugin %q duplicates builtin command", p.Name) return p, nil } if cmd.HasAlias(p.Name) { p.Err = NewPluginError("plugin %q duplicates an alias of builtin command %q", p.Name, cmd.Name()) return p, nil } } } // We are supposed to check for relevant execute permissions here. Instead we rely on an attempt to execute. meta, err := c.Metadata() if err != nil { p.Err = wrapAsPluginError(err, "failed to fetch metadata") return p, nil } if err := json.Unmarshal(meta, &p.Metadata); err != nil { p.Err = wrapAsPluginError(err, "invalid metadata") return p, nil } if p.Metadata.SchemaVersion != "0.1.0" { p.Err = NewPluginError("plugin SchemaVersion %q is not valid, must be 0.1.0", p.Metadata.SchemaVersion) return p, nil } if p.Metadata.Vendor == "" { p.Err = NewPluginError("plugin metadata does not define a vendor") return p, nil } return p, nil }
[ "func", "newPlugin", "(", "c", "Candidate", ",", "rootcmd", "*", "cobra", ".", "Command", ")", "(", "Plugin", ",", "error", ")", "{", "path", ":=", "c", ".", "Path", "(", ")", "\n", "if", "path", "==", "\"", "\"", "{", "return", "Plugin", "{", "}", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n\n", "// The candidate listing process should have skipped anything", "// which would fail here, so there are all real errors.", "fullname", ":=", "filepath", ".", "Base", "(", "path", ")", "\n", "if", "fullname", "==", "\"", "\"", "{", "return", "Plugin", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "path", ")", "\n", "}", "\n", "var", "err", "error", "\n", "if", "fullname", ",", "err", "=", "trimExeSuffix", "(", "fullname", ")", ";", "err", "!=", "nil", "{", "return", "Plugin", "{", "}", ",", "errors", ".", "Wrapf", "(", "err", ",", "\"", "\"", ",", "path", ")", "\n", "}", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "fullname", ",", "NamePrefix", ")", "{", "return", "Plugin", "{", "}", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "path", ",", "NamePrefix", ")", "\n", "}", "\n\n", "p", ":=", "Plugin", "{", "Name", ":", "strings", ".", "TrimPrefix", "(", "fullname", ",", "NamePrefix", ")", ",", "Path", ":", "path", ",", "}", "\n\n", "// Now apply the candidate tests, so these update p.Err.", "if", "!", "pluginNameRe", ".", "MatchString", "(", "p", ".", "Name", ")", "{", "p", ".", "Err", "=", "NewPluginError", "(", "\"", "\"", ",", "p", ".", "Name", ",", "pluginNameRe", ".", "String", "(", ")", ")", "\n", "return", "p", ",", "nil", "\n", "}", "\n\n", "if", "rootcmd", "!=", "nil", "{", "for", "_", ",", "cmd", ":=", "range", "rootcmd", ".", "Commands", "(", ")", "{", "// Ignore conflicts with commands which are", "// just plugin stubs (i.e. from a previous", "// call to AddPluginCommandStubs).", "if", "p", ":=", "cmd", ".", "Annotations", "[", "CommandAnnotationPlugin", "]", ";", "p", "==", "\"", "\"", "{", "continue", "\n", "}", "\n", "if", "cmd", ".", "Name", "(", ")", "==", "p", ".", "Name", "{", "p", ".", "Err", "=", "NewPluginError", "(", "\"", "\"", ",", "p", ".", "Name", ")", "\n", "return", "p", ",", "nil", "\n", "}", "\n", "if", "cmd", ".", "HasAlias", "(", "p", ".", "Name", ")", "{", "p", ".", "Err", "=", "NewPluginError", "(", "\"", "\"", ",", "p", ".", "Name", ",", "cmd", ".", "Name", "(", ")", ")", "\n", "return", "p", ",", "nil", "\n", "}", "\n", "}", "\n", "}", "\n\n", "// We are supposed to check for relevant execute permissions here. Instead we rely on an attempt to execute.", "meta", ",", "err", ":=", "c", ".", "Metadata", "(", ")", "\n", "if", "err", "!=", "nil", "{", "p", ".", "Err", "=", "wrapAsPluginError", "(", "err", ",", "\"", "\"", ")", "\n", "return", "p", ",", "nil", "\n", "}", "\n\n", "if", "err", ":=", "json", ".", "Unmarshal", "(", "meta", ",", "&", "p", ".", "Metadata", ")", ";", "err", "!=", "nil", "{", "p", ".", "Err", "=", "wrapAsPluginError", "(", "err", ",", "\"", "\"", ")", "\n", "return", "p", ",", "nil", "\n", "}", "\n\n", "if", "p", ".", "Metadata", ".", "SchemaVersion", "!=", "\"", "\"", "{", "p", ".", "Err", "=", "NewPluginError", "(", "\"", "\"", ",", "p", ".", "Metadata", ".", "SchemaVersion", ")", "\n", "return", "p", ",", "nil", "\n", "}", "\n", "if", "p", ".", "Metadata", ".", "Vendor", "==", "\"", "\"", "{", "p", ".", "Err", "=", "NewPluginError", "(", "\"", "\"", ")", "\n", "return", "p", ",", "nil", "\n", "}", "\n", "return", "p", ",", "nil", "\n", "}" ]
// newPlugin determines if the given candidate is valid and returns a // Plugin. If the candidate fails one of the tests then `Plugin.Err` // is set, and is always a `pluginError`, but the `Plugin` is still // returned with no error. An error is only returned due to a // non-recoverable error.
[ "newPlugin", "determines", "if", "the", "given", "candidate", "is", "valid", "and", "returns", "a", "Plugin", ".", "If", "the", "candidate", "fails", "one", "of", "the", "tests", "then", "Plugin", ".", "Err", "is", "set", "and", "is", "always", "a", "pluginError", "but", "the", "Plugin", "is", "still", "returned", "with", "no", "error", ".", "An", "error", "is", "only", "returned", "due", "to", "a", "non", "-", "recoverable", "error", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli-plugins/manager/plugin.go#L36-L107
train
docker/cli
cli/command/stack/cmd.go
NewStackCommand
func NewStackCommand(dockerCli command.Cli) *cobra.Command { var opts commonOptions cmd := &cobra.Command{ Use: "stack [OPTIONS]", Short: "Manage Docker stacks", Args: cli.NoArgs, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { orchestrator, err := getOrchestrator(dockerCli, cmd) if err != nil { return err } opts.orchestrator = orchestrator hideOrchestrationFlags(cmd, orchestrator) return checkSupportedFlag(cmd, orchestrator) }, RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{ "version": "1.25", }, } defaultHelpFunc := cmd.HelpFunc() cmd.SetHelpFunc(func(c *cobra.Command, args []string) { if err := cmd.Root().PersistentPreRunE(c, args); err != nil { fmt.Fprintln(dockerCli.Err(), err) return } if err := cmd.PersistentPreRunE(c, args); err != nil { fmt.Fprintln(dockerCli.Err(), err) return } hideOrchestrationFlags(c, opts.orchestrator) defaultHelpFunc(c, args) }) cmd.AddCommand( newDeployCommand(dockerCli, &opts), newListCommand(dockerCli, &opts), newPsCommand(dockerCli, &opts), newRemoveCommand(dockerCli, &opts), newServicesCommand(dockerCli, &opts), ) flags := cmd.PersistentFlags() flags.String("kubeconfig", "", "Kubernetes config file") flags.SetAnnotation("kubeconfig", "kubernetes", nil) flags.String("orchestrator", "", "Orchestrator to use (swarm|kubernetes|all)") return cmd }
go
func NewStackCommand(dockerCli command.Cli) *cobra.Command { var opts commonOptions cmd := &cobra.Command{ Use: "stack [OPTIONS]", Short: "Manage Docker stacks", Args: cli.NoArgs, PersistentPreRunE: func(cmd *cobra.Command, args []string) error { orchestrator, err := getOrchestrator(dockerCli, cmd) if err != nil { return err } opts.orchestrator = orchestrator hideOrchestrationFlags(cmd, orchestrator) return checkSupportedFlag(cmd, orchestrator) }, RunE: command.ShowHelp(dockerCli.Err()), Annotations: map[string]string{ "version": "1.25", }, } defaultHelpFunc := cmd.HelpFunc() cmd.SetHelpFunc(func(c *cobra.Command, args []string) { if err := cmd.Root().PersistentPreRunE(c, args); err != nil { fmt.Fprintln(dockerCli.Err(), err) return } if err := cmd.PersistentPreRunE(c, args); err != nil { fmt.Fprintln(dockerCli.Err(), err) return } hideOrchestrationFlags(c, opts.orchestrator) defaultHelpFunc(c, args) }) cmd.AddCommand( newDeployCommand(dockerCli, &opts), newListCommand(dockerCli, &opts), newPsCommand(dockerCli, &opts), newRemoveCommand(dockerCli, &opts), newServicesCommand(dockerCli, &opts), ) flags := cmd.PersistentFlags() flags.String("kubeconfig", "", "Kubernetes config file") flags.SetAnnotation("kubeconfig", "kubernetes", nil) flags.String("orchestrator", "", "Orchestrator to use (swarm|kubernetes|all)") return cmd }
[ "func", "NewStackCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "opts", "commonOptions", "\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "PersistentPreRunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "orchestrator", ",", "err", ":=", "getOrchestrator", "(", "dockerCli", ",", "cmd", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "opts", ".", "orchestrator", "=", "orchestrator", "\n", "hideOrchestrationFlags", "(", "cmd", ",", "orchestrator", ")", "\n", "return", "checkSupportedFlag", "(", "cmd", ",", "orchestrator", ")", "\n", "}", ",", "RunE", ":", "command", ".", "ShowHelp", "(", "dockerCli", ".", "Err", "(", ")", ")", ",", "Annotations", ":", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "}", ",", "}", "\n", "defaultHelpFunc", ":=", "cmd", ".", "HelpFunc", "(", ")", "\n", "cmd", ".", "SetHelpFunc", "(", "func", "(", "c", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "{", "if", "err", ":=", "cmd", ".", "Root", "(", ")", ".", "PersistentPreRunE", "(", "c", ",", "args", ")", ";", "err", "!=", "nil", "{", "fmt", ".", "Fprintln", "(", "dockerCli", ".", "Err", "(", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n", "if", "err", ":=", "cmd", ".", "PersistentPreRunE", "(", "c", ",", "args", ")", ";", "err", "!=", "nil", "{", "fmt", ".", "Fprintln", "(", "dockerCli", ".", "Err", "(", ")", ",", "err", ")", "\n", "return", "\n", "}", "\n", "hideOrchestrationFlags", "(", "c", ",", "opts", ".", "orchestrator", ")", "\n", "defaultHelpFunc", "(", "c", ",", "args", ")", "\n", "}", ")", "\n", "cmd", ".", "AddCommand", "(", "newDeployCommand", "(", "dockerCli", ",", "&", "opts", ")", ",", "newListCommand", "(", "dockerCli", ",", "&", "opts", ")", ",", "newPsCommand", "(", "dockerCli", ",", "&", "opts", ")", ",", "newRemoveCommand", "(", "dockerCli", ",", "&", "opts", ")", ",", "newServicesCommand", "(", "dockerCli", ",", "&", "opts", ")", ",", ")", "\n", "flags", ":=", "cmd", ".", "PersistentFlags", "(", ")", "\n", "flags", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "SetAnnotation", "(", "\"", "\"", ",", "\"", "\"", ",", "nil", ")", "\n", "flags", ".", "String", "(", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "return", "cmd", "\n", "}" ]
// NewStackCommand returns a cobra command for `stack` subcommands
[ "NewStackCommand", "returns", "a", "cobra", "command", "for", "stack", "subcommands" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/cmd.go#L28-L74
train
docker/cli
cli/command/stack/cmd.go
NewTopLevelDeployCommand
func NewTopLevelDeployCommand(dockerCli command.Cli) *cobra.Command { cmd := newDeployCommand(dockerCli, nil) // Remove the aliases at the top level cmd.Aliases = []string{} cmd.Annotations = map[string]string{ "experimental": "", "version": "1.25", } return cmd }
go
func NewTopLevelDeployCommand(dockerCli command.Cli) *cobra.Command { cmd := newDeployCommand(dockerCli, nil) // Remove the aliases at the top level cmd.Aliases = []string{} cmd.Annotations = map[string]string{ "experimental": "", "version": "1.25", } return cmd }
[ "func", "NewTopLevelDeployCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "newDeployCommand", "(", "dockerCli", ",", "nil", ")", "\n", "// Remove the aliases at the top level", "cmd", ".", "Aliases", "=", "[", "]", "string", "{", "}", "\n", "cmd", ".", "Annotations", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "\"", "\"", ",", "\"", "\"", ":", "\"", "\"", ",", "}", "\n", "return", "cmd", "\n", "}" ]
// NewTopLevelDeployCommand returns a command for `docker deploy`
[ "NewTopLevelDeployCommand", "returns", "a", "command", "for", "docker", "deploy" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/cmd.go#L77-L86
train
docker/cli
cli/command/image/load.go
NewLoadCommand
func NewLoadCommand(dockerCli command.Cli) *cobra.Command { var opts loadOptions cmd := &cobra.Command{ Use: "load [OPTIONS]", Short: "Load an image from a tar archive or STDIN", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return runLoad(dockerCli, opts) }, } flags := cmd.Flags() flags.StringVarP(&opts.input, "input", "i", "", "Read from tar archive file, instead of STDIN") flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress the load output") return cmd }
go
func NewLoadCommand(dockerCli command.Cli) *cobra.Command { var opts loadOptions cmd := &cobra.Command{ Use: "load [OPTIONS]", Short: "Load an image from a tar archive or STDIN", Args: cli.NoArgs, RunE: func(cmd *cobra.Command, args []string) error { return runLoad(dockerCli, opts) }, } flags := cmd.Flags() flags.StringVarP(&opts.input, "input", "i", "", "Read from tar archive file, instead of STDIN") flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress the load output") return cmd }
[ "func", "NewLoadCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "var", "opts", "loadOptions", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "return", "runLoad", "(", "dockerCli", ",", "opts", ")", "\n", "}", ",", "}", "\n\n", "flags", ":=", "cmd", ".", "Flags", "(", ")", "\n\n", "flags", ".", "StringVarP", "(", "&", "opts", ".", "input", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVarP", "(", "&", "opts", ".", "quiet", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n\n", "return", "cmd", "\n", "}" ]
// NewLoadCommand creates a new `docker load` command
[ "NewLoadCommand", "creates", "a", "new", "docker", "load", "command" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/load.go#L21-L39
train
docker/cli
cli/command/engine/cmd.go
NewEngineCommand
func NewEngineCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "engine COMMAND", Short: "Manage the docker engine", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), } cmd.AddCommand( newActivateCommand(dockerCli), newCheckForUpdatesCommand(dockerCli), newUpdateCommand(dockerCli), ) return cmd }
go
func NewEngineCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "engine COMMAND", Short: "Manage the docker engine", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), } cmd.AddCommand( newActivateCommand(dockerCli), newCheckForUpdatesCommand(dockerCli), newUpdateCommand(dockerCli), ) return cmd }
[ "func", "NewEngineCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "command", ".", "ShowHelp", "(", "dockerCli", ".", "Err", "(", ")", ")", ",", "}", "\n", "cmd", ".", "AddCommand", "(", "newActivateCommand", "(", "dockerCli", ")", ",", "newCheckForUpdatesCommand", "(", "dockerCli", ")", ",", "newUpdateCommand", "(", "dockerCli", ")", ",", ")", "\n", "return", "cmd", "\n", "}" ]
// NewEngineCommand returns a cobra command for `engine` subcommands
[ "NewEngineCommand", "returns", "a", "cobra", "command", "for", "engine", "subcommands" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/engine/cmd.go#L10-L23
train
docker/cli
cli/command/container/exec.go
NewExecCommand
func NewExecCommand(dockerCli command.Cli) *cobra.Command { options := newExecOptions() cmd := &cobra.Command{ Use: "exec [OPTIONS] CONTAINER COMMAND [ARG...]", Short: "Run a command in a running container", Args: cli.RequiresMinArgs(2), RunE: func(cmd *cobra.Command, args []string) error { options.container = args[0] options.command = args[1:] return runExec(dockerCli, options) }, } flags := cmd.Flags() flags.SetInterspersed(false) flags.StringVarP(&options.detachKeys, "detach-keys", "", "", "Override the key sequence for detaching a container") flags.BoolVarP(&options.interactive, "interactive", "i", false, "Keep STDIN open even if not attached") flags.BoolVarP(&options.tty, "tty", "t", false, "Allocate a pseudo-TTY") flags.BoolVarP(&options.detach, "detach", "d", false, "Detached mode: run command in the background") flags.StringVarP(&options.user, "user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])") flags.BoolVarP(&options.privileged, "privileged", "", false, "Give extended privileges to the command") flags.VarP(&options.env, "env", "e", "Set environment variables") flags.SetAnnotation("env", "version", []string{"1.25"}) flags.StringVarP(&options.workdir, "workdir", "w", "", "Working directory inside the container") flags.SetAnnotation("workdir", "version", []string{"1.35"}) return cmd }
go
func NewExecCommand(dockerCli command.Cli) *cobra.Command { options := newExecOptions() cmd := &cobra.Command{ Use: "exec [OPTIONS] CONTAINER COMMAND [ARG...]", Short: "Run a command in a running container", Args: cli.RequiresMinArgs(2), RunE: func(cmd *cobra.Command, args []string) error { options.container = args[0] options.command = args[1:] return runExec(dockerCli, options) }, } flags := cmd.Flags() flags.SetInterspersed(false) flags.StringVarP(&options.detachKeys, "detach-keys", "", "", "Override the key sequence for detaching a container") flags.BoolVarP(&options.interactive, "interactive", "i", false, "Keep STDIN open even if not attached") flags.BoolVarP(&options.tty, "tty", "t", false, "Allocate a pseudo-TTY") flags.BoolVarP(&options.detach, "detach", "d", false, "Detached mode: run command in the background") flags.StringVarP(&options.user, "user", "u", "", "Username or UID (format: <name|uid>[:<group|gid>])") flags.BoolVarP(&options.privileged, "privileged", "", false, "Give extended privileges to the command") flags.VarP(&options.env, "env", "e", "Set environment variables") flags.SetAnnotation("env", "version", []string{"1.25"}) flags.StringVarP(&options.workdir, "workdir", "w", "", "Working directory inside the container") flags.SetAnnotation("workdir", "version", []string{"1.35"}) return cmd }
[ "func", "NewExecCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "options", ":=", "newExecOptions", "(", ")", "\n\n", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "RequiresMinArgs", "(", "2", ")", ",", "RunE", ":", "func", "(", "cmd", "*", "cobra", ".", "Command", ",", "args", "[", "]", "string", ")", "error", "{", "options", ".", "container", "=", "args", "[", "0", "]", "\n", "options", ".", "command", "=", "args", "[", "1", ":", "]", "\n", "return", "runExec", "(", "dockerCli", ",", "options", ")", "\n", "}", ",", "}", "\n\n", "flags", ":=", "cmd", ".", "Flags", "(", ")", "\n", "flags", ".", "SetInterspersed", "(", "false", ")", "\n\n", "flags", ".", "StringVarP", "(", "&", "options", ".", "detachKeys", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVarP", "(", "&", "options", ".", "interactive", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVarP", "(", "&", "options", ".", "tty", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVarP", "(", "&", "options", ".", "detach", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "StringVarP", "(", "&", "options", ".", "user", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "BoolVarP", "(", "&", "options", ".", "privileged", ",", "\"", "\"", ",", "\"", "\"", ",", "false", ",", "\"", "\"", ")", "\n", "flags", ".", "VarP", "(", "&", "options", ".", "env", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "SetAnnotation", "(", "\"", "\"", ",", "\"", "\"", ",", "[", "]", "string", "{", "\"", "\"", "}", ")", "\n", "flags", ".", "StringVarP", "(", "&", "options", ".", "workdir", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ",", "\"", "\"", ")", "\n", "flags", ".", "SetAnnotation", "(", "\"", "\"", ",", "\"", "\"", ",", "[", "]", "string", "{", "\"", "\"", "}", ")", "\n\n", "return", "cmd", "\n", "}" ]
// NewExecCommand creates a new cobra.Command for `docker exec`
[ "NewExecCommand", "creates", "a", "new", "cobra", ".", "Command", "for", "docker", "exec" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/exec.go#L37-L66
train
docker/cli
cli/command/container/exec.go
parseExec
func parseExec(opts execOptions, configFile *configfile.ConfigFile) *types.ExecConfig { execConfig := &types.ExecConfig{ User: opts.user, Privileged: opts.privileged, Tty: opts.tty, Cmd: opts.command, Detach: opts.detach, Env: opts.env.GetAll(), WorkingDir: opts.workdir, } // If -d is not set, attach to everything by default if !opts.detach { execConfig.AttachStdout = true execConfig.AttachStderr = true if opts.interactive { execConfig.AttachStdin = true } } if opts.detachKeys != "" { execConfig.DetachKeys = opts.detachKeys } else { execConfig.DetachKeys = configFile.DetachKeys } return execConfig }
go
func parseExec(opts execOptions, configFile *configfile.ConfigFile) *types.ExecConfig { execConfig := &types.ExecConfig{ User: opts.user, Privileged: opts.privileged, Tty: opts.tty, Cmd: opts.command, Detach: opts.detach, Env: opts.env.GetAll(), WorkingDir: opts.workdir, } // If -d is not set, attach to everything by default if !opts.detach { execConfig.AttachStdout = true execConfig.AttachStderr = true if opts.interactive { execConfig.AttachStdin = true } } if opts.detachKeys != "" { execConfig.DetachKeys = opts.detachKeys } else { execConfig.DetachKeys = configFile.DetachKeys } return execConfig }
[ "func", "parseExec", "(", "opts", "execOptions", ",", "configFile", "*", "configfile", ".", "ConfigFile", ")", "*", "types", ".", "ExecConfig", "{", "execConfig", ":=", "&", "types", ".", "ExecConfig", "{", "User", ":", "opts", ".", "user", ",", "Privileged", ":", "opts", ".", "privileged", ",", "Tty", ":", "opts", ".", "tty", ",", "Cmd", ":", "opts", ".", "command", ",", "Detach", ":", "opts", ".", "detach", ",", "Env", ":", "opts", ".", "env", ".", "GetAll", "(", ")", ",", "WorkingDir", ":", "opts", ".", "workdir", ",", "}", "\n\n", "// If -d is not set, attach to everything by default", "if", "!", "opts", ".", "detach", "{", "execConfig", ".", "AttachStdout", "=", "true", "\n", "execConfig", ".", "AttachStderr", "=", "true", "\n", "if", "opts", ".", "interactive", "{", "execConfig", ".", "AttachStdin", "=", "true", "\n", "}", "\n", "}", "\n\n", "if", "opts", ".", "detachKeys", "!=", "\"", "\"", "{", "execConfig", ".", "DetachKeys", "=", "opts", ".", "detachKeys", "\n", "}", "else", "{", "execConfig", ".", "DetachKeys", "=", "configFile", ".", "DetachKeys", "\n", "}", "\n", "return", "execConfig", "\n", "}" ]
// parseExec parses the specified args for the specified command and generates // an ExecConfig from it.
[ "parseExec", "parses", "the", "specified", "args", "for", "the", "specified", "command", "and", "generates", "an", "ExecConfig", "from", "it", "." ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/exec.go#L188-L214
train
docker/cli
cli/streams/stream.go
RestoreTerminal
func (s *commonStream) RestoreTerminal() { if s.state != nil { term.RestoreTerminal(s.fd, s.state) } }
go
func (s *commonStream) RestoreTerminal() { if s.state != nil { term.RestoreTerminal(s.fd, s.state) } }
[ "func", "(", "s", "*", "commonStream", ")", "RestoreTerminal", "(", ")", "{", "if", "s", ".", "state", "!=", "nil", "{", "term", ".", "RestoreTerminal", "(", "s", ".", "fd", ",", "s", ".", "state", ")", "\n", "}", "\n", "}" ]
// RestoreTerminal restores normal mode to the terminal
[ "RestoreTerminal", "restores", "normal", "mode", "to", "the", "terminal" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/streams/stream.go#L25-L29
train
docker/cli
cli/command/system/cmd.go
NewSystemCommand
func NewSystemCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "system", Short: "Manage Docker", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), } cmd.AddCommand( NewEventsCommand(dockerCli), NewInfoCommand(dockerCli), newDiskUsageCommand(dockerCli), newPruneCommand(dockerCli), newDialStdioCommand(dockerCli), ) return cmd }
go
func NewSystemCommand(dockerCli command.Cli) *cobra.Command { cmd := &cobra.Command{ Use: "system", Short: "Manage Docker", Args: cli.NoArgs, RunE: command.ShowHelp(dockerCli.Err()), } cmd.AddCommand( NewEventsCommand(dockerCli), NewInfoCommand(dockerCli), newDiskUsageCommand(dockerCli), newPruneCommand(dockerCli), newDialStdioCommand(dockerCli), ) return cmd }
[ "func", "NewSystemCommand", "(", "dockerCli", "command", ".", "Cli", ")", "*", "cobra", ".", "Command", "{", "cmd", ":=", "&", "cobra", ".", "Command", "{", "Use", ":", "\"", "\"", ",", "Short", ":", "\"", "\"", ",", "Args", ":", "cli", ".", "NoArgs", ",", "RunE", ":", "command", ".", "ShowHelp", "(", "dockerCli", ".", "Err", "(", ")", ")", ",", "}", "\n", "cmd", ".", "AddCommand", "(", "NewEventsCommand", "(", "dockerCli", ")", ",", "NewInfoCommand", "(", "dockerCli", ")", ",", "newDiskUsageCommand", "(", "dockerCli", ")", ",", "newPruneCommand", "(", "dockerCli", ")", ",", "newDialStdioCommand", "(", "dockerCli", ")", ",", ")", "\n\n", "return", "cmd", "\n", "}" ]
// NewSystemCommand returns a cobra command for `system` subcommands
[ "NewSystemCommand", "returns", "a", "cobra", "command", "for", "system", "subcommands" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/cmd.go#L10-L26
train
docker/cli
cli/config/config.go
Path
func Path(p ...string) (string, error) { path := filepath.Join(append([]string{Dir()}, p...)...) if !strings.HasPrefix(path, Dir()+string(filepath.Separator)) { return "", errors.Errorf("path %q is outside of root config directory %q", path, Dir()) } return path, nil }
go
func Path(p ...string) (string, error) { path := filepath.Join(append([]string{Dir()}, p...)...) if !strings.HasPrefix(path, Dir()+string(filepath.Separator)) { return "", errors.Errorf("path %q is outside of root config directory %q", path, Dir()) } return path, nil }
[ "func", "Path", "(", "p", "...", "string", ")", "(", "string", ",", "error", ")", "{", "path", ":=", "filepath", ".", "Join", "(", "append", "(", "[", "]", "string", "{", "Dir", "(", ")", "}", ",", "p", "...", ")", "...", ")", "\n", "if", "!", "strings", ".", "HasPrefix", "(", "path", ",", "Dir", "(", ")", "+", "string", "(", "filepath", ".", "Separator", ")", ")", "{", "return", "\"", "\"", ",", "errors", ".", "Errorf", "(", "\"", "\"", ",", "path", ",", "Dir", "(", ")", ")", "\n", "}", "\n", "return", "path", ",", "nil", "\n", "}" ]
// Path returns the path to a file relative to the config dir
[ "Path", "returns", "the", "path", "to", "a", "file", "relative", "to", "the", "config", "dir" ]
3273c2e23546dddd0ff8bb499f4aba02fe60bf30
https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/config.go#L51-L57
train