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/utils.go | CopyToFile | func CopyToFile(outfile string, r io.Reader) error {
// We use sequential file access here to avoid depleting the standby list
// on Windows. On Linux, this is a call directly to ioutil.TempFile
tmpFile, err := system.TempFileSequential(filepath.Dir(outfile), ".docker_temp_")
if err != nil {
return err
}
tmpPath := tmpFile.Name()
_, err = io.Copy(tmpFile, r)
tmpFile.Close()
if err != nil {
os.Remove(tmpPath)
return err
}
if err = os.Rename(tmpPath, outfile); err != nil {
os.Remove(tmpPath)
return err
}
return nil
} | go | func CopyToFile(outfile string, r io.Reader) error {
// We use sequential file access here to avoid depleting the standby list
// on Windows. On Linux, this is a call directly to ioutil.TempFile
tmpFile, err := system.TempFileSequential(filepath.Dir(outfile), ".docker_temp_")
if err != nil {
return err
}
tmpPath := tmpFile.Name()
_, err = io.Copy(tmpFile, r)
tmpFile.Close()
if err != nil {
os.Remove(tmpPath)
return err
}
if err = os.Rename(tmpPath, outfile); err != nil {
os.Remove(tmpPath)
return err
}
return nil
} | [
"func",
"CopyToFile",
"(",
"outfile",
"string",
",",
"r",
"io",
".",
"Reader",
")",
"error",
"{",
"// We use sequential file access here to avoid depleting the standby list",
"// on Windows. On Linux, this is a call directly to ioutil.TempFile",
"tmpFile",
",",
"err",
":=",
"system",
".",
"TempFileSequential",
"(",
"filepath",
".",
"Dir",
"(",
"outfile",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"tmpPath",
":=",
"tmpFile",
".",
"Name",
"(",
")",
"\n\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"tmpFile",
",",
"r",
")",
"\n",
"tmpFile",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"os",
".",
"Remove",
"(",
"tmpPath",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"os",
".",
"Rename",
"(",
"tmpPath",
",",
"outfile",
")",
";",
"err",
"!=",
"nil",
"{",
"os",
".",
"Remove",
"(",
"tmpPath",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // CopyToFile writes the content of the reader to the specified file | [
"CopyToFile",
"writes",
"the",
"content",
"of",
"the",
"reader",
"to",
"the",
"specified",
"file"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/utils.go#L20-L44 | train |
docker/cli | cli/command/utils.go | capitalizeFirst | func capitalizeFirst(s string) string {
switch l := len(s); l {
case 0:
return s
case 1:
return strings.ToLower(s)
default:
return strings.ToUpper(string(s[0])) + strings.ToLower(s[1:])
}
} | go | func capitalizeFirst(s string) string {
switch l := len(s); l {
case 0:
return s
case 1:
return strings.ToLower(s)
default:
return strings.ToUpper(string(s[0])) + strings.ToLower(s[1:])
}
} | [
"func",
"capitalizeFirst",
"(",
"s",
"string",
")",
"string",
"{",
"switch",
"l",
":=",
"len",
"(",
"s",
")",
";",
"l",
"{",
"case",
"0",
":",
"return",
"s",
"\n",
"case",
"1",
":",
"return",
"strings",
".",
"ToLower",
"(",
"s",
")",
"\n",
"default",
":",
"return",
"strings",
".",
"ToUpper",
"(",
"string",
"(",
"s",
"[",
"0",
"]",
")",
")",
"+",
"strings",
".",
"ToLower",
"(",
"s",
"[",
"1",
":",
"]",
")",
"\n",
"}",
"\n",
"}"
] | // capitalizeFirst capitalizes the first character of string | [
"capitalizeFirst",
"capitalizes",
"the",
"first",
"character",
"of",
"string"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/utils.go#L47-L56 | train |
docker/cli | cli/command/utils.go | PrettyPrint | func PrettyPrint(i interface{}) string {
switch t := i.(type) {
case nil:
return "None"
case string:
return capitalizeFirst(t)
default:
return capitalizeFirst(fmt.Sprintf("%s", t))
}
} | go | func PrettyPrint(i interface{}) string {
switch t := i.(type) {
case nil:
return "None"
case string:
return capitalizeFirst(t)
default:
return capitalizeFirst(fmt.Sprintf("%s", t))
}
} | [
"func",
"PrettyPrint",
"(",
"i",
"interface",
"{",
"}",
")",
"string",
"{",
"switch",
"t",
":=",
"i",
".",
"(",
"type",
")",
"{",
"case",
"nil",
":",
"return",
"\"",
"\"",
"\n",
"case",
"string",
":",
"return",
"capitalizeFirst",
"(",
"t",
")",
"\n",
"default",
":",
"return",
"capitalizeFirst",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"t",
")",
")",
"\n",
"}",
"\n",
"}"
] | // PrettyPrint outputs arbitrary data for human formatted output by uppercasing the first letter. | [
"PrettyPrint",
"outputs",
"arbitrary",
"data",
"for",
"human",
"formatted",
"output",
"by",
"uppercasing",
"the",
"first",
"letter",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/utils.go#L59-L68 | train |
docker/cli | cli/command/utils.go | PruneFilters | func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args {
if dockerCli.ConfigFile() == nil {
return pruneFilters
}
for _, f := range dockerCli.ConfigFile().PruneFilters {
parts := strings.SplitN(f, "=", 2)
if len(parts) != 2 {
continue
}
if parts[0] == "label" {
// CLI label filter supersede config.json.
// If CLI label filter conflict with config.json,
// skip adding label! filter in config.json.
if pruneFilters.Contains("label!") && pruneFilters.ExactMatch("label!", parts[1]) {
continue
}
} else if parts[0] == "label!" {
// CLI label! filter supersede config.json.
// If CLI label! filter conflict with config.json,
// skip adding label filter in config.json.
if pruneFilters.Contains("label") && pruneFilters.ExactMatch("label", parts[1]) {
continue
}
}
pruneFilters.Add(parts[0], parts[1])
}
return pruneFilters
} | go | func PruneFilters(dockerCli Cli, pruneFilters filters.Args) filters.Args {
if dockerCli.ConfigFile() == nil {
return pruneFilters
}
for _, f := range dockerCli.ConfigFile().PruneFilters {
parts := strings.SplitN(f, "=", 2)
if len(parts) != 2 {
continue
}
if parts[0] == "label" {
// CLI label filter supersede config.json.
// If CLI label filter conflict with config.json,
// skip adding label! filter in config.json.
if pruneFilters.Contains("label!") && pruneFilters.ExactMatch("label!", parts[1]) {
continue
}
} else if parts[0] == "label!" {
// CLI label! filter supersede config.json.
// If CLI label! filter conflict with config.json,
// skip adding label filter in config.json.
if pruneFilters.Contains("label") && pruneFilters.ExactMatch("label", parts[1]) {
continue
}
}
pruneFilters.Add(parts[0], parts[1])
}
return pruneFilters
} | [
"func",
"PruneFilters",
"(",
"dockerCli",
"Cli",
",",
"pruneFilters",
"filters",
".",
"Args",
")",
"filters",
".",
"Args",
"{",
"if",
"dockerCli",
".",
"ConfigFile",
"(",
")",
"==",
"nil",
"{",
"return",
"pruneFilters",
"\n",
"}",
"\n",
"for",
"_",
",",
"f",
":=",
"range",
"dockerCli",
".",
"ConfigFile",
"(",
")",
".",
"PruneFilters",
"{",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"f",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"2",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"parts",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"// CLI label filter supersede config.json.",
"// If CLI label filter conflict with config.json,",
"// skip adding label! filter in config.json.",
"if",
"pruneFilters",
".",
"Contains",
"(",
"\"",
"\"",
")",
"&&",
"pruneFilters",
".",
"ExactMatch",
"(",
"\"",
"\"",
",",
"parts",
"[",
"1",
"]",
")",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"else",
"if",
"parts",
"[",
"0",
"]",
"==",
"\"",
"\"",
"{",
"// CLI label! filter supersede config.json.",
"// If CLI label! filter conflict with config.json,",
"// skip adding label filter in config.json.",
"if",
"pruneFilters",
".",
"Contains",
"(",
"\"",
"\"",
")",
"&&",
"pruneFilters",
".",
"ExactMatch",
"(",
"\"",
"\"",
",",
"parts",
"[",
"1",
"]",
")",
"{",
"continue",
"\n",
"}",
"\n",
"}",
"\n",
"pruneFilters",
".",
"Add",
"(",
"parts",
"[",
"0",
"]",
",",
"parts",
"[",
"1",
"]",
")",
"\n",
"}",
"\n\n",
"return",
"pruneFilters",
"\n",
"}"
] | // PruneFilters returns consolidated prune filters obtained from config.json and cli | [
"PruneFilters",
"returns",
"consolidated",
"prune",
"filters",
"obtained",
"from",
"config",
".",
"json",
"and",
"cli"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/utils.go#L94-L122 | train |
docker/cli | cli/command/utils.go | AddPlatformFlag | func AddPlatformFlag(flags *pflag.FlagSet, target *string) {
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
flags.SetAnnotation("platform", "version", []string{"1.32"})
flags.SetAnnotation("platform", "experimental", nil)
} | go | func AddPlatformFlag(flags *pflag.FlagSet, target *string) {
flags.StringVar(target, "platform", os.Getenv("DOCKER_DEFAULT_PLATFORM"), "Set platform if server is multi-platform capable")
flags.SetAnnotation("platform", "version", []string{"1.32"})
flags.SetAnnotation("platform", "experimental", nil)
} | [
"func",
"AddPlatformFlag",
"(",
"flags",
"*",
"pflag",
".",
"FlagSet",
",",
"target",
"*",
"string",
")",
"{",
"flags",
".",
"StringVar",
"(",
"target",
",",
"\"",
"\"",
",",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"SetAnnotation",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
")",
"\n",
"flags",
".",
"SetAnnotation",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n",
"}"
] | // AddPlatformFlag adds `platform` to a set of flags for API version 1.32 and later. | [
"AddPlatformFlag",
"adds",
"platform",
"to",
"a",
"set",
"of",
"flags",
"for",
"API",
"version",
"1",
".",
"32",
"and",
"later",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/utils.go#L125-L129 | train |
docker/cli | cli/command/utils.go | ValidateOutputPath | func ValidateOutputPath(path string) error {
dir := filepath.Dir(path)
if dir != "" && dir != "." {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return errors.Errorf("invalid output path: directory %q does not exist", dir)
}
}
// check whether `path` points to a regular file
// (if the path exists and doesn't point to a directory)
if fileInfo, err := os.Stat(path); !os.IsNotExist(err) {
if fileInfo.Mode().IsDir() || fileInfo.Mode().IsRegular() {
return nil
}
if err := ValidateOutputPathFileMode(fileInfo.Mode()); err != nil {
return errors.Wrapf(err, fmt.Sprintf("invalid output path: %q must be a directory or a regular file", path))
}
}
return nil
} | go | func ValidateOutputPath(path string) error {
dir := filepath.Dir(path)
if dir != "" && dir != "." {
if _, err := os.Stat(dir); os.IsNotExist(err) {
return errors.Errorf("invalid output path: directory %q does not exist", dir)
}
}
// check whether `path` points to a regular file
// (if the path exists and doesn't point to a directory)
if fileInfo, err := os.Stat(path); !os.IsNotExist(err) {
if fileInfo.Mode().IsDir() || fileInfo.Mode().IsRegular() {
return nil
}
if err := ValidateOutputPathFileMode(fileInfo.Mode()); err != nil {
return errors.Wrapf(err, fmt.Sprintf("invalid output path: %q must be a directory or a regular file", path))
}
}
return nil
} | [
"func",
"ValidateOutputPath",
"(",
"path",
"string",
")",
"error",
"{",
"dir",
":=",
"filepath",
".",
"Dir",
"(",
"path",
")",
"\n",
"if",
"dir",
"!=",
"\"",
"\"",
"&&",
"dir",
"!=",
"\"",
"\"",
"{",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"dir",
")",
";",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"dir",
")",
"\n",
"}",
"\n",
"}",
"\n",
"// check whether `path` points to a regular file",
"// (if the path exists and doesn't point to a directory)",
"if",
"fileInfo",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"path",
")",
";",
"!",
"os",
".",
"IsNotExist",
"(",
"err",
")",
"{",
"if",
"fileInfo",
".",
"Mode",
"(",
")",
".",
"IsDir",
"(",
")",
"||",
"fileInfo",
".",
"Mode",
"(",
")",
".",
"IsRegular",
"(",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"ValidateOutputPathFileMode",
"(",
"fileInfo",
".",
"Mode",
"(",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"path",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ValidateOutputPath validates the output paths of the `export` and `save` commands. | [
"ValidateOutputPath",
"validates",
"the",
"output",
"paths",
"of",
"the",
"export",
"and",
"save",
"commands",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/utils.go#L132-L151 | train |
docker/cli | cli/command/utils.go | ValidateOutputPathFileMode | func ValidateOutputPathFileMode(fileMode os.FileMode) error {
switch {
case fileMode&os.ModeDevice != 0:
return errors.New("got a device")
case fileMode&os.ModeIrregular != 0:
return errors.New("got an irregular file")
}
return nil
} | go | func ValidateOutputPathFileMode(fileMode os.FileMode) error {
switch {
case fileMode&os.ModeDevice != 0:
return errors.New("got a device")
case fileMode&os.ModeIrregular != 0:
return errors.New("got an irregular file")
}
return nil
} | [
"func",
"ValidateOutputPathFileMode",
"(",
"fileMode",
"os",
".",
"FileMode",
")",
"error",
"{",
"switch",
"{",
"case",
"fileMode",
"&",
"os",
".",
"ModeDevice",
"!=",
"0",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"fileMode",
"&",
"os",
".",
"ModeIrregular",
"!=",
"0",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // ValidateOutputPathFileMode validates the output paths of the `cp` command and serves as a
// helper to `ValidateOutputPath` | [
"ValidateOutputPathFileMode",
"validates",
"the",
"output",
"paths",
"of",
"the",
"cp",
"command",
"and",
"serves",
"as",
"a",
"helper",
"to",
"ValidateOutputPath"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/utils.go#L155-L163 | train |
docker/cli | cli/command/system/df.go | newDiskUsageCommand | func newDiskUsageCommand(dockerCli command.Cli) *cobra.Command {
var opts diskUsageOptions
cmd := &cobra.Command{
Use: "df [OPTIONS]",
Short: "Show docker disk usage",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runDiskUsage(dockerCli, opts)
},
Annotations: map[string]string{"version": "1.25"},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.verbose, "verbose", "v", false, "Show detailed information on space usage")
flags.StringVar(&opts.format, "format", "", "Pretty-print images using a Go template")
return cmd
} | go | func newDiskUsageCommand(dockerCli command.Cli) *cobra.Command {
var opts diskUsageOptions
cmd := &cobra.Command{
Use: "df [OPTIONS]",
Short: "Show docker disk usage",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runDiskUsage(dockerCli, opts)
},
Annotations: map[string]string{"version": "1.25"},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.verbose, "verbose", "v", false, "Show detailed information on space usage")
flags.StringVar(&opts.format, "format", "", "Pretty-print images using a Go template")
return cmd
} | [
"func",
"newDiskUsageCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"diskUsageOptions",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"NoArgs",
",",
"RunE",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"return",
"runDiskUsage",
"(",
"dockerCli",
",",
"opts",
")",
"\n",
"}",
",",
"Annotations",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"\"",
"\"",
"}",
",",
"}",
"\n\n",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n\n",
"flags",
".",
"BoolVarP",
"(",
"&",
"opts",
".",
"verbose",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"StringVar",
"(",
"&",
"opts",
".",
"format",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"cmd",
"\n",
"}"
] | // newDiskUsageCommand creates a new cobra.Command for `docker df` | [
"newDiskUsageCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"df"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/df.go#L18-L37 | train |
docker/cli | cli/streams/in.go | CheckTty | func (i *In) CheckTty(attachStdin, ttyMode bool) error {
// In order to attach to a container tty, input stream for the client must
// be a tty itself: redirecting or piping the client standard input is
// incompatible with `docker run -t`, `docker exec -t` or `docker attach`.
if ttyMode && attachStdin && !i.isTerminal {
eText := "the input device is not a TTY"
if runtime.GOOS == "windows" {
return errors.New(eText + ". If you are using mintty, try prefixing the command with 'winpty'")
}
return errors.New(eText)
}
return nil
} | go | func (i *In) CheckTty(attachStdin, ttyMode bool) error {
// In order to attach to a container tty, input stream for the client must
// be a tty itself: redirecting or piping the client standard input is
// incompatible with `docker run -t`, `docker exec -t` or `docker attach`.
if ttyMode && attachStdin && !i.isTerminal {
eText := "the input device is not a TTY"
if runtime.GOOS == "windows" {
return errors.New(eText + ". If you are using mintty, try prefixing the command with 'winpty'")
}
return errors.New(eText)
}
return nil
} | [
"func",
"(",
"i",
"*",
"In",
")",
"CheckTty",
"(",
"attachStdin",
",",
"ttyMode",
"bool",
")",
"error",
"{",
"// In order to attach to a container tty, input stream for the client must",
"// be a tty itself: redirecting or piping the client standard input is",
"// incompatible with `docker run -t`, `docker exec -t` or `docker attach`.",
"if",
"ttyMode",
"&&",
"attachStdin",
"&&",
"!",
"i",
".",
"isTerminal",
"{",
"eText",
":=",
"\"",
"\"",
"\n",
"if",
"runtime",
".",
"GOOS",
"==",
"\"",
"\"",
"{",
"return",
"errors",
".",
"New",
"(",
"eText",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"errors",
".",
"New",
"(",
"eText",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // CheckTty checks if we are trying to attach to a container tty
// from a non-tty client input stream, and if so, returns an error. | [
"CheckTty",
"checks",
"if",
"we",
"are",
"trying",
"to",
"attach",
"to",
"a",
"container",
"tty",
"from",
"a",
"non",
"-",
"tty",
"client",
"input",
"stream",
"and",
"if",
"so",
"returns",
"an",
"error",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/streams/in.go#L38-L50 | train |
docker/cli | cli/streams/in.go | NewIn | func NewIn(in io.ReadCloser) *In {
fd, isTerminal := term.GetFdInfo(in)
return &In{commonStream: commonStream{fd: fd, isTerminal: isTerminal}, in: in}
} | go | func NewIn(in io.ReadCloser) *In {
fd, isTerminal := term.GetFdInfo(in)
return &In{commonStream: commonStream{fd: fd, isTerminal: isTerminal}, in: in}
} | [
"func",
"NewIn",
"(",
"in",
"io",
".",
"ReadCloser",
")",
"*",
"In",
"{",
"fd",
",",
"isTerminal",
":=",
"term",
".",
"GetFdInfo",
"(",
"in",
")",
"\n",
"return",
"&",
"In",
"{",
"commonStream",
":",
"commonStream",
"{",
"fd",
":",
"fd",
",",
"isTerminal",
":",
"isTerminal",
"}",
",",
"in",
":",
"in",
"}",
"\n",
"}"
] | // NewIn returns a new In object from a ReadCloser | [
"NewIn",
"returns",
"a",
"new",
"In",
"object",
"from",
"a",
"ReadCloser"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/streams/in.go#L53-L56 | train |
docker/cli | templates/templates.go | New | func New(tag string) *template.Template {
return template.New(tag).Funcs(basicFunctions)
} | go | func New(tag string) *template.Template {
return template.New(tag).Funcs(basicFunctions)
} | [
"func",
"New",
"(",
"tag",
"string",
")",
"*",
"template",
".",
"Template",
"{",
"return",
"template",
".",
"New",
"(",
"tag",
")",
".",
"Funcs",
"(",
"basicFunctions",
")",
"\n",
"}"
] | // New creates a new empty template with the provided tag and built-in
// template functions. | [
"New",
"creates",
"a",
"new",
"empty",
"template",
"with",
"the",
"provided",
"tag",
"and",
"built",
"-",
"in",
"template",
"functions",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/templates/templates.go#L60-L62 | train |
docker/cli | cli/command/service/logs.go | parseContext | func (lw *logWriter) parseContext(details map[string]string) (logContext, error) {
nodeID, ok := details["com.docker.swarm.node.id"]
if !ok {
return logContext{}, errors.Errorf("missing node id in details: %v", details)
}
delete(details, "com.docker.swarm.node.id")
serviceID, ok := details["com.docker.swarm.service.id"]
if !ok {
return logContext{}, errors.Errorf("missing service id in details: %v", details)
}
delete(details, "com.docker.swarm.service.id")
taskID, ok := details["com.docker.swarm.task.id"]
if !ok {
return logContext{}, errors.Errorf("missing task id in details: %s", details)
}
delete(details, "com.docker.swarm.task.id")
return logContext{
nodeID: nodeID,
serviceID: serviceID,
taskID: taskID,
}, nil
} | go | func (lw *logWriter) parseContext(details map[string]string) (logContext, error) {
nodeID, ok := details["com.docker.swarm.node.id"]
if !ok {
return logContext{}, errors.Errorf("missing node id in details: %v", details)
}
delete(details, "com.docker.swarm.node.id")
serviceID, ok := details["com.docker.swarm.service.id"]
if !ok {
return logContext{}, errors.Errorf("missing service id in details: %v", details)
}
delete(details, "com.docker.swarm.service.id")
taskID, ok := details["com.docker.swarm.task.id"]
if !ok {
return logContext{}, errors.Errorf("missing task id in details: %s", details)
}
delete(details, "com.docker.swarm.task.id")
return logContext{
nodeID: nodeID,
serviceID: serviceID,
taskID: taskID,
}, nil
} | [
"func",
"(",
"lw",
"*",
"logWriter",
")",
"parseContext",
"(",
"details",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"logContext",
",",
"error",
")",
"{",
"nodeID",
",",
"ok",
":=",
"details",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"logContext",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"details",
")",
"\n",
"}",
"\n",
"delete",
"(",
"details",
",",
"\"",
"\"",
")",
"\n\n",
"serviceID",
",",
"ok",
":=",
"details",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"logContext",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"details",
")",
"\n",
"}",
"\n",
"delete",
"(",
"details",
",",
"\"",
"\"",
")",
"\n\n",
"taskID",
",",
"ok",
":=",
"details",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"logContext",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"details",
")",
"\n",
"}",
"\n",
"delete",
"(",
"details",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"logContext",
"{",
"nodeID",
":",
"nodeID",
",",
"serviceID",
":",
"serviceID",
",",
"taskID",
":",
"taskID",
",",
"}",
",",
"nil",
"\n",
"}"
] | // parseContext returns a log context and REMOVES the context from the details map | [
"parseContext",
"returns",
"a",
"log",
"context",
"and",
"REMOVES",
"the",
"context",
"from",
"the",
"details",
"map"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/service/logs.go#L319-L343 | train |
docker/cli | cli/context/store/store.go | New | func New(dir string, cfg Config) Store {
metaRoot := filepath.Join(dir, metadataDir)
tlsRoot := filepath.Join(dir, tlsDir)
return &store{
meta: &metadataStore{
root: metaRoot,
config: cfg,
},
tls: &tlsStore{
root: tlsRoot,
},
}
} | go | func New(dir string, cfg Config) Store {
metaRoot := filepath.Join(dir, metadataDir)
tlsRoot := filepath.Join(dir, tlsDir)
return &store{
meta: &metadataStore{
root: metaRoot,
config: cfg,
},
tls: &tlsStore{
root: tlsRoot,
},
}
} | [
"func",
"New",
"(",
"dir",
"string",
",",
"cfg",
"Config",
")",
"Store",
"{",
"metaRoot",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"metadataDir",
")",
"\n",
"tlsRoot",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"tlsDir",
")",
"\n\n",
"return",
"&",
"store",
"{",
"meta",
":",
"&",
"metadataStore",
"{",
"root",
":",
"metaRoot",
",",
"config",
":",
"cfg",
",",
"}",
",",
"tls",
":",
"&",
"tlsStore",
"{",
"root",
":",
"tlsRoot",
",",
"}",
",",
"}",
"\n",
"}"
] | // New creates a store from a given directory.
// If the directory does not exist or is empty, initialize it | [
"New",
"creates",
"a",
"store",
"from",
"a",
"given",
"directory",
".",
"If",
"the",
"directory",
"does",
"not",
"exist",
"or",
"is",
"empty",
"initialize",
"it"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/context/store/store.go#L89-L102 | train |
docker/cli | cli/context/store/store.go | Import | func Import(name string, s Writer, reader io.Reader) error {
tr := tar.NewReader(reader)
tlsData := ContextTLSData{
Endpoints: map[string]EndpointTLSData{},
}
for {
hdr, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
if hdr.Typeflag == tar.TypeDir {
// skip this entry, only taking files into account
continue
}
if hdr.Name == metaFile {
data, err := ioutil.ReadAll(tr)
if err != nil {
return err
}
var meta Metadata
if err := json.Unmarshal(data, &meta); err != nil {
return err
}
meta.Name = name
if err := s.CreateOrUpdate(meta); err != nil {
return err
}
} else if strings.HasPrefix(hdr.Name, "tls/") {
relative := strings.TrimPrefix(hdr.Name, "tls/")
parts := strings.SplitN(relative, "/", 2)
if len(parts) != 2 {
return errors.New("archive format is invalid")
}
endpointName := parts[0]
fileName := parts[1]
data, err := ioutil.ReadAll(tr)
if err != nil {
return err
}
if _, ok := tlsData.Endpoints[endpointName]; !ok {
tlsData.Endpoints[endpointName] = EndpointTLSData{
Files: map[string][]byte{},
}
}
tlsData.Endpoints[endpointName].Files[fileName] = data
}
}
return s.ResetTLSMaterial(name, &tlsData)
} | go | func Import(name string, s Writer, reader io.Reader) error {
tr := tar.NewReader(reader)
tlsData := ContextTLSData{
Endpoints: map[string]EndpointTLSData{},
}
for {
hdr, err := tr.Next()
if err == io.EOF {
break
}
if err != nil {
return err
}
if hdr.Typeflag == tar.TypeDir {
// skip this entry, only taking files into account
continue
}
if hdr.Name == metaFile {
data, err := ioutil.ReadAll(tr)
if err != nil {
return err
}
var meta Metadata
if err := json.Unmarshal(data, &meta); err != nil {
return err
}
meta.Name = name
if err := s.CreateOrUpdate(meta); err != nil {
return err
}
} else if strings.HasPrefix(hdr.Name, "tls/") {
relative := strings.TrimPrefix(hdr.Name, "tls/")
parts := strings.SplitN(relative, "/", 2)
if len(parts) != 2 {
return errors.New("archive format is invalid")
}
endpointName := parts[0]
fileName := parts[1]
data, err := ioutil.ReadAll(tr)
if err != nil {
return err
}
if _, ok := tlsData.Endpoints[endpointName]; !ok {
tlsData.Endpoints[endpointName] = EndpointTLSData{
Files: map[string][]byte{},
}
}
tlsData.Endpoints[endpointName].Files[fileName] = data
}
}
return s.ResetTLSMaterial(name, &tlsData)
} | [
"func",
"Import",
"(",
"name",
"string",
",",
"s",
"Writer",
",",
"reader",
"io",
".",
"Reader",
")",
"error",
"{",
"tr",
":=",
"tar",
".",
"NewReader",
"(",
"reader",
")",
"\n",
"tlsData",
":=",
"ContextTLSData",
"{",
"Endpoints",
":",
"map",
"[",
"string",
"]",
"EndpointTLSData",
"{",
"}",
",",
"}",
"\n",
"for",
"{",
"hdr",
",",
"err",
":=",
"tr",
".",
"Next",
"(",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"break",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"hdr",
".",
"Typeflag",
"==",
"tar",
".",
"TypeDir",
"{",
"// skip this entry, only taking files into account",
"continue",
"\n",
"}",
"\n",
"if",
"hdr",
".",
"Name",
"==",
"metaFile",
"{",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"tr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"meta",
"Metadata",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"meta",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"meta",
".",
"Name",
"=",
"name",
"\n",
"if",
"err",
":=",
"s",
".",
"CreateOrUpdate",
"(",
"meta",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"else",
"if",
"strings",
".",
"HasPrefix",
"(",
"hdr",
".",
"Name",
",",
"\"",
"\"",
")",
"{",
"relative",
":=",
"strings",
".",
"TrimPrefix",
"(",
"hdr",
".",
"Name",
",",
"\"",
"\"",
")",
"\n",
"parts",
":=",
"strings",
".",
"SplitN",
"(",
"relative",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"2",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"endpointName",
":=",
"parts",
"[",
"0",
"]",
"\n",
"fileName",
":=",
"parts",
"[",
"1",
"]",
"\n",
"data",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"tr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"_",
",",
"ok",
":=",
"tlsData",
".",
"Endpoints",
"[",
"endpointName",
"]",
";",
"!",
"ok",
"{",
"tlsData",
".",
"Endpoints",
"[",
"endpointName",
"]",
"=",
"EndpointTLSData",
"{",
"Files",
":",
"map",
"[",
"string",
"]",
"[",
"]",
"byte",
"{",
"}",
",",
"}",
"\n",
"}",
"\n",
"tlsData",
".",
"Endpoints",
"[",
"endpointName",
"]",
".",
"Files",
"[",
"fileName",
"]",
"=",
"data",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"s",
".",
"ResetTLSMaterial",
"(",
"name",
",",
"&",
"tlsData",
")",
"\n",
"}"
] | // Import imports an exported context into a store | [
"Import",
"imports",
"an",
"exported",
"context",
"into",
"a",
"store"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/context/store/store.go#L263-L314 | train |
docker/cli | cli/command/trust/formatter.go | TagWrite | func TagWrite(ctx formatter.Context, signedTagInfoList []SignedTagInfo) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, signedTag := range signedTagInfoList {
if err := format(&trustTagContext{s: signedTag}); err != nil {
return err
}
}
return nil
}
trustTagCtx := trustTagContext{}
trustTagCtx.Header = formatter.SubHeaderContext{
"SignedTag": signedTagNameHeader,
"Digest": trustedDigestHeader,
"Signers": signersHeader,
}
return ctx.Write(&trustTagCtx, render)
} | go | func TagWrite(ctx formatter.Context, signedTagInfoList []SignedTagInfo) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, signedTag := range signedTagInfoList {
if err := format(&trustTagContext{s: signedTag}); err != nil {
return err
}
}
return nil
}
trustTagCtx := trustTagContext{}
trustTagCtx.Header = formatter.SubHeaderContext{
"SignedTag": signedTagNameHeader,
"Digest": trustedDigestHeader,
"Signers": signersHeader,
}
return ctx.Write(&trustTagCtx, render)
} | [
"func",
"TagWrite",
"(",
"ctx",
"formatter",
".",
"Context",
",",
"signedTagInfoList",
"[",
"]",
"SignedTagInfo",
")",
"error",
"{",
"render",
":=",
"func",
"(",
"format",
"func",
"(",
"subContext",
"formatter",
".",
"SubContext",
")",
"error",
")",
"error",
"{",
"for",
"_",
",",
"signedTag",
":=",
"range",
"signedTagInfoList",
"{",
"if",
"err",
":=",
"format",
"(",
"&",
"trustTagContext",
"{",
"s",
":",
"signedTag",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"trustTagCtx",
":=",
"trustTagContext",
"{",
"}",
"\n",
"trustTagCtx",
".",
"Header",
"=",
"formatter",
".",
"SubHeaderContext",
"{",
"\"",
"\"",
":",
"signedTagNameHeader",
",",
"\"",
"\"",
":",
"trustedDigestHeader",
",",
"\"",
"\"",
":",
"signersHeader",
",",
"}",
"\n",
"return",
"ctx",
".",
"Write",
"(",
"&",
"trustTagCtx",
",",
"render",
")",
"\n",
"}"
] | // TagWrite writes the context | [
"TagWrite",
"writes",
"the",
"context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust/formatter.go#L50-L66 | train |
docker/cli | cli/command/trust/formatter.go | Signers | func (c *trustTagContext) Signers() string {
sort.Strings(c.s.Signers)
return strings.Join(c.s.Signers, ", ")
} | go | func (c *trustTagContext) Signers() string {
sort.Strings(c.s.Signers)
return strings.Join(c.s.Signers, ", ")
} | [
"func",
"(",
"c",
"*",
"trustTagContext",
")",
"Signers",
"(",
")",
"string",
"{",
"sort",
".",
"Strings",
"(",
"c",
".",
"s",
".",
"Signers",
")",
"\n",
"return",
"strings",
".",
"Join",
"(",
"c",
".",
"s",
".",
"Signers",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Signers returns the sorted list of entities who signed this tag | [
"Signers",
"returns",
"the",
"sorted",
"list",
"of",
"entities",
"who",
"signed",
"this",
"tag"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust/formatter.go#L84-L87 | train |
docker/cli | cli/command/trust/formatter.go | SignerInfoWrite | func SignerInfoWrite(ctx formatter.Context, signerInfoList []SignerInfo) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, signerInfo := range signerInfoList {
if err := format(&signerInfoContext{
trunc: ctx.Trunc,
s: signerInfo,
}); err != nil {
return err
}
}
return nil
}
signerInfoCtx := signerInfoContext{}
signerInfoCtx.Header = formatter.SubHeaderContext{
"Signer": signerNameHeader,
"Keys": keysHeader,
}
return ctx.Write(&signerInfoCtx, render)
} | go | func SignerInfoWrite(ctx formatter.Context, signerInfoList []SignerInfo) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, signerInfo := range signerInfoList {
if err := format(&signerInfoContext{
trunc: ctx.Trunc,
s: signerInfo,
}); err != nil {
return err
}
}
return nil
}
signerInfoCtx := signerInfoContext{}
signerInfoCtx.Header = formatter.SubHeaderContext{
"Signer": signerNameHeader,
"Keys": keysHeader,
}
return ctx.Write(&signerInfoCtx, render)
} | [
"func",
"SignerInfoWrite",
"(",
"ctx",
"formatter",
".",
"Context",
",",
"signerInfoList",
"[",
"]",
"SignerInfo",
")",
"error",
"{",
"render",
":=",
"func",
"(",
"format",
"func",
"(",
"subContext",
"formatter",
".",
"SubContext",
")",
"error",
")",
"error",
"{",
"for",
"_",
",",
"signerInfo",
":=",
"range",
"signerInfoList",
"{",
"if",
"err",
":=",
"format",
"(",
"&",
"signerInfoContext",
"{",
"trunc",
":",
"ctx",
".",
"Trunc",
",",
"s",
":",
"signerInfo",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"signerInfoCtx",
":=",
"signerInfoContext",
"{",
"}",
"\n",
"signerInfoCtx",
".",
"Header",
"=",
"formatter",
".",
"SubHeaderContext",
"{",
"\"",
"\"",
":",
"signerNameHeader",
",",
"\"",
"\"",
":",
"keysHeader",
",",
"}",
"\n",
"return",
"ctx",
".",
"Write",
"(",
"&",
"signerInfoCtx",
",",
"render",
")",
"\n",
"}"
] | // SignerInfoWrite writes the context | [
"SignerInfoWrite",
"writes",
"the",
"context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust/formatter.go#L90-L108 | train |
docker/cli | cli/command/trust/formatter.go | Keys | func (c *signerInfoContext) Keys() string {
sort.Strings(c.s.Keys)
truncatedKeys := []string{}
if c.trunc {
for _, keyID := range c.s.Keys {
truncatedKeys = append(truncatedKeys, stringid.TruncateID(keyID))
}
return strings.Join(truncatedKeys, ", ")
}
return strings.Join(c.s.Keys, ", ")
} | go | func (c *signerInfoContext) Keys() string {
sort.Strings(c.s.Keys)
truncatedKeys := []string{}
if c.trunc {
for _, keyID := range c.s.Keys {
truncatedKeys = append(truncatedKeys, stringid.TruncateID(keyID))
}
return strings.Join(truncatedKeys, ", ")
}
return strings.Join(c.s.Keys, ", ")
} | [
"func",
"(",
"c",
"*",
"signerInfoContext",
")",
"Keys",
"(",
")",
"string",
"{",
"sort",
".",
"Strings",
"(",
"c",
".",
"s",
".",
"Keys",
")",
"\n",
"truncatedKeys",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"if",
"c",
".",
"trunc",
"{",
"for",
"_",
",",
"keyID",
":=",
"range",
"c",
".",
"s",
".",
"Keys",
"{",
"truncatedKeys",
"=",
"append",
"(",
"truncatedKeys",
",",
"stringid",
".",
"TruncateID",
"(",
"keyID",
")",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"truncatedKeys",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"Join",
"(",
"c",
".",
"s",
".",
"Keys",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Keys returns the sorted list of keys associated with the signer | [
"Keys",
"returns",
"the",
"sorted",
"list",
"of",
"keys",
"associated",
"with",
"the",
"signer"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust/formatter.go#L117-L127 | train |
docker/cli | cli/command/container/cmd.go | NewContainerCommand | func NewContainerCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "container",
Short: "Manage containers",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
NewAttachCommand(dockerCli),
NewCommitCommand(dockerCli),
NewCopyCommand(dockerCli),
NewCreateCommand(dockerCli),
NewDiffCommand(dockerCli),
NewExecCommand(dockerCli),
NewExportCommand(dockerCli),
NewKillCommand(dockerCli),
NewLogsCommand(dockerCli),
NewPauseCommand(dockerCli),
NewPortCommand(dockerCli),
NewRenameCommand(dockerCli),
NewRestartCommand(dockerCli),
NewRmCommand(dockerCli),
NewRunCommand(dockerCli),
NewStartCommand(dockerCli),
NewStatsCommand(dockerCli),
NewStopCommand(dockerCli),
NewTopCommand(dockerCli),
NewUnpauseCommand(dockerCli),
NewUpdateCommand(dockerCli),
NewWaitCommand(dockerCli),
newListCommand(dockerCli),
newInspectCommand(dockerCli),
NewPruneCommand(dockerCli),
)
return cmd
} | go | func NewContainerCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "container",
Short: "Manage containers",
Args: cli.NoArgs,
RunE: command.ShowHelp(dockerCli.Err()),
}
cmd.AddCommand(
NewAttachCommand(dockerCli),
NewCommitCommand(dockerCli),
NewCopyCommand(dockerCli),
NewCreateCommand(dockerCli),
NewDiffCommand(dockerCli),
NewExecCommand(dockerCli),
NewExportCommand(dockerCli),
NewKillCommand(dockerCli),
NewLogsCommand(dockerCli),
NewPauseCommand(dockerCli),
NewPortCommand(dockerCli),
NewRenameCommand(dockerCli),
NewRestartCommand(dockerCli),
NewRmCommand(dockerCli),
NewRunCommand(dockerCli),
NewStartCommand(dockerCli),
NewStatsCommand(dockerCli),
NewStopCommand(dockerCli),
NewTopCommand(dockerCli),
NewUnpauseCommand(dockerCli),
NewUpdateCommand(dockerCli),
NewWaitCommand(dockerCli),
newListCommand(dockerCli),
newInspectCommand(dockerCli),
NewPruneCommand(dockerCli),
)
return cmd
} | [
"func",
"NewContainerCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"NoArgs",
",",
"RunE",
":",
"command",
".",
"ShowHelp",
"(",
"dockerCli",
".",
"Err",
"(",
")",
")",
",",
"}",
"\n",
"cmd",
".",
"AddCommand",
"(",
"NewAttachCommand",
"(",
"dockerCli",
")",
",",
"NewCommitCommand",
"(",
"dockerCli",
")",
",",
"NewCopyCommand",
"(",
"dockerCli",
")",
",",
"NewCreateCommand",
"(",
"dockerCli",
")",
",",
"NewDiffCommand",
"(",
"dockerCli",
")",
",",
"NewExecCommand",
"(",
"dockerCli",
")",
",",
"NewExportCommand",
"(",
"dockerCli",
")",
",",
"NewKillCommand",
"(",
"dockerCli",
")",
",",
"NewLogsCommand",
"(",
"dockerCli",
")",
",",
"NewPauseCommand",
"(",
"dockerCli",
")",
",",
"NewPortCommand",
"(",
"dockerCli",
")",
",",
"NewRenameCommand",
"(",
"dockerCli",
")",
",",
"NewRestartCommand",
"(",
"dockerCli",
")",
",",
"NewRmCommand",
"(",
"dockerCli",
")",
",",
"NewRunCommand",
"(",
"dockerCli",
")",
",",
"NewStartCommand",
"(",
"dockerCli",
")",
",",
"NewStatsCommand",
"(",
"dockerCli",
")",
",",
"NewStopCommand",
"(",
"dockerCli",
")",
",",
"NewTopCommand",
"(",
"dockerCli",
")",
",",
"NewUnpauseCommand",
"(",
"dockerCli",
")",
",",
"NewUpdateCommand",
"(",
"dockerCli",
")",
",",
"NewWaitCommand",
"(",
"dockerCli",
")",
",",
"newListCommand",
"(",
"dockerCli",
")",
",",
"newInspectCommand",
"(",
"dockerCli",
")",
",",
"NewPruneCommand",
"(",
"dockerCli",
")",
",",
")",
"\n",
"return",
"cmd",
"\n",
"}"
] | // NewContainerCommand returns a cobra command for `container` subcommands | [
"NewContainerCommand",
"returns",
"a",
"cobra",
"command",
"for",
"container",
"subcommands"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/cmd.go#L10-L45 | train |
docker/cli | cli/command/config/ls.go | RunConfigList | func RunConfigList(dockerCli command.Cli, options ListOptions) error {
client := dockerCli.Client()
ctx := context.Background()
configs, err := client.ConfigList(ctx, types.ConfigListOptions{Filters: options.Filter.Value()})
if err != nil {
return err
}
format := options.Format
if len(format) == 0 {
if len(dockerCli.ConfigFile().ConfigFormat) > 0 && !options.Quiet {
format = dockerCli.ConfigFile().ConfigFormat
} else {
format = formatter.TableFormatKey
}
}
sort.Slice(configs, func(i, j int) bool {
return sortorder.NaturalLess(configs[i].Spec.Name, configs[j].Spec.Name)
})
configCtx := formatter.Context{
Output: dockerCli.Out(),
Format: NewFormat(format, options.Quiet),
}
return FormatWrite(configCtx, configs)
} | go | func RunConfigList(dockerCli command.Cli, options ListOptions) error {
client := dockerCli.Client()
ctx := context.Background()
configs, err := client.ConfigList(ctx, types.ConfigListOptions{Filters: options.Filter.Value()})
if err != nil {
return err
}
format := options.Format
if len(format) == 0 {
if len(dockerCli.ConfigFile().ConfigFormat) > 0 && !options.Quiet {
format = dockerCli.ConfigFile().ConfigFormat
} else {
format = formatter.TableFormatKey
}
}
sort.Slice(configs, func(i, j int) bool {
return sortorder.NaturalLess(configs[i].Spec.Name, configs[j].Spec.Name)
})
configCtx := formatter.Context{
Output: dockerCli.Out(),
Format: NewFormat(format, options.Quiet),
}
return FormatWrite(configCtx, configs)
} | [
"func",
"RunConfigList",
"(",
"dockerCli",
"command",
".",
"Cli",
",",
"options",
"ListOptions",
")",
"error",
"{",
"client",
":=",
"dockerCli",
".",
"Client",
"(",
")",
"\n",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n\n",
"configs",
",",
"err",
":=",
"client",
".",
"ConfigList",
"(",
"ctx",
",",
"types",
".",
"ConfigListOptions",
"{",
"Filters",
":",
"options",
".",
"Filter",
".",
"Value",
"(",
")",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"format",
":=",
"options",
".",
"Format",
"\n",
"if",
"len",
"(",
"format",
")",
"==",
"0",
"{",
"if",
"len",
"(",
"dockerCli",
".",
"ConfigFile",
"(",
")",
".",
"ConfigFormat",
")",
">",
"0",
"&&",
"!",
"options",
".",
"Quiet",
"{",
"format",
"=",
"dockerCli",
".",
"ConfigFile",
"(",
")",
".",
"ConfigFormat",
"\n",
"}",
"else",
"{",
"format",
"=",
"formatter",
".",
"TableFormatKey",
"\n",
"}",
"\n",
"}",
"\n\n",
"sort",
".",
"Slice",
"(",
"configs",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"sortorder",
".",
"NaturalLess",
"(",
"configs",
"[",
"i",
"]",
".",
"Spec",
".",
"Name",
",",
"configs",
"[",
"j",
"]",
".",
"Spec",
".",
"Name",
")",
"\n",
"}",
")",
"\n\n",
"configCtx",
":=",
"formatter",
".",
"Context",
"{",
"Output",
":",
"dockerCli",
".",
"Out",
"(",
")",
",",
"Format",
":",
"NewFormat",
"(",
"format",
",",
"options",
".",
"Quiet",
")",
",",
"}",
"\n",
"return",
"FormatWrite",
"(",
"configCtx",
",",
"configs",
")",
"\n",
"}"
] | // RunConfigList lists Swarm configs. | [
"RunConfigList",
"lists",
"Swarm",
"configs",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/config/ls.go#L45-L72 | train |
docker/cli | cli/config/credentials/default_store.go | DetectDefaultStore | func DetectDefaultStore(store string) string {
platformDefault := defaultCredentialsStore()
// user defined or no default for platform
if store != "" || platformDefault == "" {
return store
}
if _, err := exec.LookPath(remoteCredentialsPrefix + platformDefault); err == nil {
return platformDefault
}
return ""
} | go | func DetectDefaultStore(store string) string {
platformDefault := defaultCredentialsStore()
// user defined or no default for platform
if store != "" || platformDefault == "" {
return store
}
if _, err := exec.LookPath(remoteCredentialsPrefix + platformDefault); err == nil {
return platformDefault
}
return ""
} | [
"func",
"DetectDefaultStore",
"(",
"store",
"string",
")",
"string",
"{",
"platformDefault",
":=",
"defaultCredentialsStore",
"(",
")",
"\n\n",
"// user defined or no default for platform",
"if",
"store",
"!=",
"\"",
"\"",
"||",
"platformDefault",
"==",
"\"",
"\"",
"{",
"return",
"store",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"exec",
".",
"LookPath",
"(",
"remoteCredentialsPrefix",
"+",
"platformDefault",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"platformDefault",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
"\n",
"}"
] | // DetectDefaultStore return the default credentials store for the platform if
// the store executable is available. | [
"DetectDefaultStore",
"return",
"the",
"default",
"credentials",
"store",
"for",
"the",
"platform",
"if",
"the",
"store",
"executable",
"is",
"available",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/config/credentials/default_store.go#L9-L21 | train |
docker/cli | cli/command/image/pull.go | NewPullCommand | func NewPullCommand(dockerCli command.Cli) *cobra.Command {
var opts PullOptions
cmd := &cobra.Command{
Use: "pull [OPTIONS] NAME[:TAG|@DIGEST]",
Short: "Pull an image or a repository from a registry",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.remote = args[0]
return RunPull(dockerCli, opts)
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository")
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
command.AddPlatformFlag(flags, &opts.platform)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
return cmd
} | go | func NewPullCommand(dockerCli command.Cli) *cobra.Command {
var opts PullOptions
cmd := &cobra.Command{
Use: "pull [OPTIONS] NAME[:TAG|@DIGEST]",
Short: "Pull an image or a repository from a registry",
Args: cli.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.remote = args[0]
return RunPull(dockerCli, opts)
},
}
flags := cmd.Flags()
flags.BoolVarP(&opts.all, "all-tags", "a", false, "Download all tagged images in the repository")
flags.BoolVarP(&opts.quiet, "quiet", "q", false, "Suppress verbose output")
command.AddPlatformFlag(flags, &opts.platform)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
return cmd
} | [
"func",
"NewPullCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"PullOptions",
"\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",
"RunPull",
"(",
"dockerCli",
",",
"opts",
")",
"\n",
"}",
",",
"}",
"\n\n",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n\n",
"flags",
".",
"BoolVarP",
"(",
"&",
"opts",
".",
"all",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"BoolVarP",
"(",
"&",
"opts",
".",
"quiet",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
",",
"\"",
"\"",
")",
"\n\n",
"command",
".",
"AddPlatformFlag",
"(",
"flags",
",",
"&",
"opts",
".",
"platform",
")",
"\n",
"command",
".",
"AddTrustVerificationFlags",
"(",
"flags",
",",
"&",
"opts",
".",
"untrusted",
",",
"dockerCli",
".",
"ContentTrustEnabled",
"(",
")",
")",
"\n\n",
"return",
"cmd",
"\n",
"}"
] | // NewPullCommand creates a new `docker pull` command | [
"NewPullCommand",
"creates",
"a",
"new",
"docker",
"pull",
"command"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/pull.go#L26-L48 | train |
docker/cli | cli/command/image/pull.go | RunPull | func RunPull(cli command.Cli, opts PullOptions) error {
distributionRef, err := reference.ParseNormalizedNamed(opts.remote)
switch {
case err != nil:
return err
case opts.all && !reference.IsNameOnly(distributionRef):
return errors.New("tag can't be used with --all-tags/-a")
case !opts.all && reference.IsNameOnly(distributionRef):
distributionRef = reference.TagNameOnly(distributionRef)
if tagged, ok := distributionRef.(reference.Tagged); ok && !opts.quiet {
fmt.Fprintf(cli.Out(), "Using default tag: %s\n", tagged.Tag())
}
}
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, AuthResolver(cli), distributionRef.String())
if err != nil {
return err
}
// Check if reference has a digest
_, isCanonical := distributionRef.(reference.Canonical)
if !opts.untrusted && !isCanonical {
err = trustedPull(ctx, cli, imgRefAndAuth, opts)
} else {
err = imagePullPrivileged(ctx, cli, imgRefAndAuth, opts)
}
if err != nil {
if strings.Contains(err.Error(), "when fetching 'plugin'") {
return errors.New(err.Error() + " - Use `docker plugin install`")
}
return err
}
fmt.Fprintln(cli.Out(), imgRefAndAuth.Reference().String())
return nil
} | go | func RunPull(cli command.Cli, opts PullOptions) error {
distributionRef, err := reference.ParseNormalizedNamed(opts.remote)
switch {
case err != nil:
return err
case opts.all && !reference.IsNameOnly(distributionRef):
return errors.New("tag can't be used with --all-tags/-a")
case !opts.all && reference.IsNameOnly(distributionRef):
distributionRef = reference.TagNameOnly(distributionRef)
if tagged, ok := distributionRef.(reference.Tagged); ok && !opts.quiet {
fmt.Fprintf(cli.Out(), "Using default tag: %s\n", tagged.Tag())
}
}
ctx := context.Background()
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, AuthResolver(cli), distributionRef.String())
if err != nil {
return err
}
// Check if reference has a digest
_, isCanonical := distributionRef.(reference.Canonical)
if !opts.untrusted && !isCanonical {
err = trustedPull(ctx, cli, imgRefAndAuth, opts)
} else {
err = imagePullPrivileged(ctx, cli, imgRefAndAuth, opts)
}
if err != nil {
if strings.Contains(err.Error(), "when fetching 'plugin'") {
return errors.New(err.Error() + " - Use `docker plugin install`")
}
return err
}
fmt.Fprintln(cli.Out(), imgRefAndAuth.Reference().String())
return nil
} | [
"func",
"RunPull",
"(",
"cli",
"command",
".",
"Cli",
",",
"opts",
"PullOptions",
")",
"error",
"{",
"distributionRef",
",",
"err",
":=",
"reference",
".",
"ParseNormalizedNamed",
"(",
"opts",
".",
"remote",
")",
"\n",
"switch",
"{",
"case",
"err",
"!=",
"nil",
":",
"return",
"err",
"\n",
"case",
"opts",
".",
"all",
"&&",
"!",
"reference",
".",
"IsNameOnly",
"(",
"distributionRef",
")",
":",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"case",
"!",
"opts",
".",
"all",
"&&",
"reference",
".",
"IsNameOnly",
"(",
"distributionRef",
")",
":",
"distributionRef",
"=",
"reference",
".",
"TagNameOnly",
"(",
"distributionRef",
")",
"\n",
"if",
"tagged",
",",
"ok",
":=",
"distributionRef",
".",
"(",
"reference",
".",
"Tagged",
")",
";",
"ok",
"&&",
"!",
"opts",
".",
"quiet",
"{",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"Out",
"(",
")",
",",
"\"",
"\\n",
"\"",
",",
"tagged",
".",
"Tag",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"ctx",
":=",
"context",
".",
"Background",
"(",
")",
"\n",
"imgRefAndAuth",
",",
"err",
":=",
"trust",
".",
"GetImageReferencesAndAuth",
"(",
"ctx",
",",
"nil",
",",
"AuthResolver",
"(",
"cli",
")",
",",
"distributionRef",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check if reference has a digest",
"_",
",",
"isCanonical",
":=",
"distributionRef",
".",
"(",
"reference",
".",
"Canonical",
")",
"\n",
"if",
"!",
"opts",
".",
"untrusted",
"&&",
"!",
"isCanonical",
"{",
"err",
"=",
"trustedPull",
"(",
"ctx",
",",
"cli",
",",
"imgRefAndAuth",
",",
"opts",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"imagePullPrivileged",
"(",
"ctx",
",",
"cli",
",",
"imgRefAndAuth",
",",
"opts",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"strings",
".",
"Contains",
"(",
"err",
".",
"Error",
"(",
")",
",",
"\"",
"\"",
")",
"{",
"return",
"errors",
".",
"New",
"(",
"err",
".",
"Error",
"(",
")",
"+",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"cli",
".",
"Out",
"(",
")",
",",
"imgRefAndAuth",
".",
"Reference",
"(",
")",
".",
"String",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // RunPull performs a pull against the engine based on the specified options | [
"RunPull",
"performs",
"a",
"pull",
"against",
"the",
"engine",
"based",
"on",
"the",
"specified",
"options"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/pull.go#L51-L86 | train |
docker/cli | cli/command/registry/logout.go | NewLogoutCommand | func NewLogoutCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "logout [SERVER]",
Short: "Log out from a Docker registry",
Long: "Log out from a Docker registry.\nIf no server is specified, the default is defined by the daemon.",
Args: cli.RequiresMaxArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var serverAddress string
if len(args) > 0 {
serverAddress = args[0]
}
return runLogout(dockerCli, serverAddress)
},
}
return cmd
} | go | func NewLogoutCommand(dockerCli command.Cli) *cobra.Command {
cmd := &cobra.Command{
Use: "logout [SERVER]",
Short: "Log out from a Docker registry",
Long: "Log out from a Docker registry.\nIf no server is specified, the default is defined by the daemon.",
Args: cli.RequiresMaxArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var serverAddress string
if len(args) > 0 {
serverAddress = args[0]
}
return runLogout(dockerCli, serverAddress)
},
}
return cmd
} | [
"func",
"NewLogoutCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Long",
":",
"\"",
"\\n",
"\"",
",",
"Args",
":",
"cli",
".",
"RequiresMaxArgs",
"(",
"1",
")",
",",
"RunE",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"var",
"serverAddress",
"string",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"0",
"{",
"serverAddress",
"=",
"args",
"[",
"0",
"]",
"\n",
"}",
"\n",
"return",
"runLogout",
"(",
"dockerCli",
",",
"serverAddress",
")",
"\n",
"}",
",",
"}",
"\n\n",
"return",
"cmd",
"\n",
"}"
] | // NewLogoutCommand creates a new `docker logout` command | [
"NewLogoutCommand",
"creates",
"a",
"new",
"docker",
"logout",
"command"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/registry/logout.go#L14-L30 | train |
docker/cli | cli/command/cli_options.go | WithStandardStreams | func WithStandardStreams() DockerCliOption {
return func(cli *DockerCli) error {
// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()
cli.in = streams.NewIn(stdin)
cli.out = streams.NewOut(stdout)
cli.err = stderr
return nil
}
} | go | func WithStandardStreams() DockerCliOption {
return func(cli *DockerCli) error {
// Set terminal emulation based on platform as required.
stdin, stdout, stderr := term.StdStreams()
cli.in = streams.NewIn(stdin)
cli.out = streams.NewOut(stdout)
cli.err = stderr
return nil
}
} | [
"func",
"WithStandardStreams",
"(",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"// Set terminal emulation based on platform as required.",
"stdin",
",",
"stdout",
",",
"stderr",
":=",
"term",
".",
"StdStreams",
"(",
")",
"\n",
"cli",
".",
"in",
"=",
"streams",
".",
"NewIn",
"(",
"stdin",
")",
"\n",
"cli",
".",
"out",
"=",
"streams",
".",
"NewOut",
"(",
"stdout",
")",
"\n",
"cli",
".",
"err",
"=",
"stderr",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithStandardStreams sets a cli in, out and err streams with the standard streams. | [
"WithStandardStreams",
"sets",
"a",
"cli",
"in",
"out",
"and",
"err",
"streams",
"with",
"the",
"standard",
"streams",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L21-L30 | train |
docker/cli | cli/command/cli_options.go | WithCombinedStreams | func WithCombinedStreams(combined io.Writer) DockerCliOption {
return func(cli *DockerCli) error {
cli.out = streams.NewOut(combined)
cli.err = combined
return nil
}
} | go | func WithCombinedStreams(combined io.Writer) DockerCliOption {
return func(cli *DockerCli) error {
cli.out = streams.NewOut(combined)
cli.err = combined
return nil
}
} | [
"func",
"WithCombinedStreams",
"(",
"combined",
"io",
".",
"Writer",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"cli",
".",
"out",
"=",
"streams",
".",
"NewOut",
"(",
"combined",
")",
"\n",
"cli",
".",
"err",
"=",
"combined",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithCombinedStreams uses the same stream for the output and error streams. | [
"WithCombinedStreams",
"uses",
"the",
"same",
"stream",
"for",
"the",
"output",
"and",
"error",
"streams",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L33-L39 | train |
docker/cli | cli/command/cli_options.go | WithInputStream | func WithInputStream(in io.ReadCloser) DockerCliOption {
return func(cli *DockerCli) error {
cli.in = streams.NewIn(in)
return nil
}
} | go | func WithInputStream(in io.ReadCloser) DockerCliOption {
return func(cli *DockerCli) error {
cli.in = streams.NewIn(in)
return nil
}
} | [
"func",
"WithInputStream",
"(",
"in",
"io",
".",
"ReadCloser",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"cli",
".",
"in",
"=",
"streams",
".",
"NewIn",
"(",
"in",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithInputStream sets a cli input stream. | [
"WithInputStream",
"sets",
"a",
"cli",
"input",
"stream",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L42-L47 | train |
docker/cli | cli/command/cli_options.go | WithOutputStream | func WithOutputStream(out io.Writer) DockerCliOption {
return func(cli *DockerCli) error {
cli.out = streams.NewOut(out)
return nil
}
} | go | func WithOutputStream(out io.Writer) DockerCliOption {
return func(cli *DockerCli) error {
cli.out = streams.NewOut(out)
return nil
}
} | [
"func",
"WithOutputStream",
"(",
"out",
"io",
".",
"Writer",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"cli",
".",
"out",
"=",
"streams",
".",
"NewOut",
"(",
"out",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithOutputStream sets a cli output stream. | [
"WithOutputStream",
"sets",
"a",
"cli",
"output",
"stream",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L50-L55 | train |
docker/cli | cli/command/cli_options.go | WithErrorStream | func WithErrorStream(err io.Writer) DockerCliOption {
return func(cli *DockerCli) error {
cli.err = err
return nil
}
} | go | func WithErrorStream(err io.Writer) DockerCliOption {
return func(cli *DockerCli) error {
cli.err = err
return nil
}
} | [
"func",
"WithErrorStream",
"(",
"err",
"io",
".",
"Writer",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"cli",
".",
"err",
"=",
"err",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithErrorStream sets a cli error stream. | [
"WithErrorStream",
"sets",
"a",
"cli",
"error",
"stream",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L58-L63 | train |
docker/cli | cli/command/cli_options.go | WithContentTrustFromEnv | func WithContentTrustFromEnv() DockerCliOption {
return func(cli *DockerCli) error {
cli.contentTrust = false
if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" {
if t, err := strconv.ParseBool(e); t || err != nil {
// treat any other value as true
cli.contentTrust = true
}
}
return nil
}
} | go | func WithContentTrustFromEnv() DockerCliOption {
return func(cli *DockerCli) error {
cli.contentTrust = false
if e := os.Getenv("DOCKER_CONTENT_TRUST"); e != "" {
if t, err := strconv.ParseBool(e); t || err != nil {
// treat any other value as true
cli.contentTrust = true
}
}
return nil
}
} | [
"func",
"WithContentTrustFromEnv",
"(",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"cli",
".",
"contentTrust",
"=",
"false",
"\n",
"if",
"e",
":=",
"os",
".",
"Getenv",
"(",
"\"",
"\"",
")",
";",
"e",
"!=",
"\"",
"\"",
"{",
"if",
"t",
",",
"err",
":=",
"strconv",
".",
"ParseBool",
"(",
"e",
")",
";",
"t",
"||",
"err",
"!=",
"nil",
"{",
"// treat any other value as true",
"cli",
".",
"contentTrust",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithContentTrustFromEnv enables content trust on a cli from environment variable DOCKER_CONTENT_TRUST value. | [
"WithContentTrustFromEnv",
"enables",
"content",
"trust",
"on",
"a",
"cli",
"from",
"environment",
"variable",
"DOCKER_CONTENT_TRUST",
"value",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L66-L77 | train |
docker/cli | cli/command/cli_options.go | WithContentTrust | func WithContentTrust(enabled bool) DockerCliOption {
return func(cli *DockerCli) error {
cli.contentTrust = enabled
return nil
}
} | go | func WithContentTrust(enabled bool) DockerCliOption {
return func(cli *DockerCli) error {
cli.contentTrust = enabled
return nil
}
} | [
"func",
"WithContentTrust",
"(",
"enabled",
"bool",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"cli",
".",
"contentTrust",
"=",
"enabled",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithContentTrust enables content trust on a cli. | [
"WithContentTrust",
"enables",
"content",
"trust",
"on",
"a",
"cli",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L80-L85 | train |
docker/cli | cli/command/cli_options.go | WithContainerizedClient | func WithContainerizedClient(containerizedFn func(string) (clitypes.ContainerizedClient, error)) DockerCliOption {
return func(cli *DockerCli) error {
cli.newContainerizeClient = containerizedFn
return nil
}
} | go | func WithContainerizedClient(containerizedFn func(string) (clitypes.ContainerizedClient, error)) DockerCliOption {
return func(cli *DockerCli) error {
cli.newContainerizeClient = containerizedFn
return nil
}
} | [
"func",
"WithContainerizedClient",
"(",
"containerizedFn",
"func",
"(",
"string",
")",
"(",
"clitypes",
".",
"ContainerizedClient",
",",
"error",
")",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"cli",
".",
"newContainerizeClient",
"=",
"containerizedFn",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithContainerizedClient sets the containerized client constructor on a cli. | [
"WithContainerizedClient",
"sets",
"the",
"containerized",
"client",
"constructor",
"on",
"a",
"cli",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L88-L93 | train |
docker/cli | cli/command/cli_options.go | WithContextEndpointType | func WithContextEndpointType(endpointName string, endpointType store.TypeGetter) DockerCliOption {
return func(cli *DockerCli) error {
switch endpointName {
case docker.DockerEndpoint, kubernetes.KubernetesEndpoint:
return fmt.Errorf("cannot change %q endpoint type", endpointName)
}
cli.contextStoreConfig.SetEndpoint(endpointName, endpointType)
return nil
}
} | go | func WithContextEndpointType(endpointName string, endpointType store.TypeGetter) DockerCliOption {
return func(cli *DockerCli) error {
switch endpointName {
case docker.DockerEndpoint, kubernetes.KubernetesEndpoint:
return fmt.Errorf("cannot change %q endpoint type", endpointName)
}
cli.contextStoreConfig.SetEndpoint(endpointName, endpointType)
return nil
}
} | [
"func",
"WithContextEndpointType",
"(",
"endpointName",
"string",
",",
"endpointType",
"store",
".",
"TypeGetter",
")",
"DockerCliOption",
"{",
"return",
"func",
"(",
"cli",
"*",
"DockerCli",
")",
"error",
"{",
"switch",
"endpointName",
"{",
"case",
"docker",
".",
"DockerEndpoint",
",",
"kubernetes",
".",
"KubernetesEndpoint",
":",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"endpointName",
")",
"\n",
"}",
"\n",
"cli",
".",
"contextStoreConfig",
".",
"SetEndpoint",
"(",
"endpointName",
",",
"endpointType",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}"
] | // WithContextEndpointType add support for an additional typed endpoint in the context store
// Plugins should use this to store additional endpoints configuration in the context store | [
"WithContextEndpointType",
"add",
"support",
"for",
"an",
"additional",
"typed",
"endpoint",
"in",
"the",
"context",
"store",
"Plugins",
"should",
"use",
"this",
"to",
"store",
"additional",
"endpoints",
"configuration",
"in",
"the",
"context",
"store"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/cli_options.go#L97-L106 | train |
docker/cli | cli/command/system/version.go | NewVersionCommand | func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
var opts versionOptions
cmd := &cobra.Command{
Use: "version [OPTIONS]",
Short: "Show the Docker version information",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runVersion(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
flags.StringVar(&opts.kubeConfig, "kubeconfig", "", "Kubernetes config file")
flags.SetAnnotation("kubeconfig", "kubernetes", nil)
return cmd
} | go | func NewVersionCommand(dockerCli command.Cli) *cobra.Command {
var opts versionOptions
cmd := &cobra.Command{
Use: "version [OPTIONS]",
Short: "Show the Docker version information",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runVersion(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.StringVarP(&opts.format, "format", "f", "", "Format the output using the given Go template")
flags.StringVar(&opts.kubeConfig, "kubeconfig", "", "Kubernetes config file")
flags.SetAnnotation("kubeconfig", "kubernetes", nil)
return cmd
} | [
"func",
"NewVersionCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"versionOptions",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"NoArgs",
",",
"RunE",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"return",
"runVersion",
"(",
"dockerCli",
",",
"&",
"opts",
")",
"\n",
"}",
",",
"}",
"\n\n",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n",
"flags",
".",
"StringVarP",
"(",
"&",
"opts",
".",
"format",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"StringVar",
"(",
"&",
"opts",
".",
"kubeConfig",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"SetAnnotation",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"nil",
")",
"\n\n",
"return",
"cmd",
"\n",
"}"
] | // NewVersionCommand creates a new cobra.Command for `docker version` | [
"NewVersionCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"version"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/version.go#L97-L115 | train |
docker/cli | cli/command/swarm/progress/root_rotation.go | RootRotationProgress | func RootRotationProgress(ctx context.Context, dclient client.APIClient, progressWriter io.WriteCloser) error {
defer progressWriter.Close()
progressOut := streamformatter.NewJSONProgressOutput(progressWriter, false)
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt)
defer signal.Stop(sigint)
// draw 2 progress bars, 1 for nodes with the correct cert, 1 for nodes with the correct trust root
progress.Update(progressOut, "desired root digest", "")
progress.Update(progressOut, certsRotatedStr, certsAction)
progress.Update(progressOut, rootsRotatedStr, rootsAction)
var done bool
for {
info, err := dclient.SwarmInspect(ctx)
if err != nil {
return err
}
if done {
return nil
}
nodes, err := dclient.NodeList(ctx, types.NodeListOptions{})
if err != nil {
return err
}
done = updateProgress(progressOut, info.ClusterInfo.TLSInfo, nodes, info.ClusterInfo.RootRotationInProgress)
select {
case <-time.After(200 * time.Millisecond):
case <-sigint:
if !done {
progress.Message(progressOut, "", "Operation continuing in background.")
progress.Message(progressOut, "", "Use `swarmctl cluster inspect default` to check progress.")
}
return nil
}
}
} | go | func RootRotationProgress(ctx context.Context, dclient client.APIClient, progressWriter io.WriteCloser) error {
defer progressWriter.Close()
progressOut := streamformatter.NewJSONProgressOutput(progressWriter, false)
sigint := make(chan os.Signal, 1)
signal.Notify(sigint, os.Interrupt)
defer signal.Stop(sigint)
// draw 2 progress bars, 1 for nodes with the correct cert, 1 for nodes with the correct trust root
progress.Update(progressOut, "desired root digest", "")
progress.Update(progressOut, certsRotatedStr, certsAction)
progress.Update(progressOut, rootsRotatedStr, rootsAction)
var done bool
for {
info, err := dclient.SwarmInspect(ctx)
if err != nil {
return err
}
if done {
return nil
}
nodes, err := dclient.NodeList(ctx, types.NodeListOptions{})
if err != nil {
return err
}
done = updateProgress(progressOut, info.ClusterInfo.TLSInfo, nodes, info.ClusterInfo.RootRotationInProgress)
select {
case <-time.After(200 * time.Millisecond):
case <-sigint:
if !done {
progress.Message(progressOut, "", "Operation continuing in background.")
progress.Message(progressOut, "", "Use `swarmctl cluster inspect default` to check progress.")
}
return nil
}
}
} | [
"func",
"RootRotationProgress",
"(",
"ctx",
"context",
".",
"Context",
",",
"dclient",
"client",
".",
"APIClient",
",",
"progressWriter",
"io",
".",
"WriteCloser",
")",
"error",
"{",
"defer",
"progressWriter",
".",
"Close",
"(",
")",
"\n\n",
"progressOut",
":=",
"streamformatter",
".",
"NewJSONProgressOutput",
"(",
"progressWriter",
",",
"false",
")",
"\n\n",
"sigint",
":=",
"make",
"(",
"chan",
"os",
".",
"Signal",
",",
"1",
")",
"\n",
"signal",
".",
"Notify",
"(",
"sigint",
",",
"os",
".",
"Interrupt",
")",
"\n",
"defer",
"signal",
".",
"Stop",
"(",
"sigint",
")",
"\n\n",
"// draw 2 progress bars, 1 for nodes with the correct cert, 1 for nodes with the correct trust root",
"progress",
".",
"Update",
"(",
"progressOut",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"progress",
".",
"Update",
"(",
"progressOut",
",",
"certsRotatedStr",
",",
"certsAction",
")",
"\n",
"progress",
".",
"Update",
"(",
"progressOut",
",",
"rootsRotatedStr",
",",
"rootsAction",
")",
"\n\n",
"var",
"done",
"bool",
"\n\n",
"for",
"{",
"info",
",",
"err",
":=",
"dclient",
".",
"SwarmInspect",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"done",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"nodes",
",",
"err",
":=",
"dclient",
".",
"NodeList",
"(",
"ctx",
",",
"types",
".",
"NodeListOptions",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"done",
"=",
"updateProgress",
"(",
"progressOut",
",",
"info",
".",
"ClusterInfo",
".",
"TLSInfo",
",",
"nodes",
",",
"info",
".",
"ClusterInfo",
".",
"RootRotationInProgress",
")",
"\n\n",
"select",
"{",
"case",
"<-",
"time",
".",
"After",
"(",
"200",
"*",
"time",
".",
"Millisecond",
")",
":",
"case",
"<-",
"sigint",
":",
"if",
"!",
"done",
"{",
"progress",
".",
"Message",
"(",
"progressOut",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"progress",
".",
"Message",
"(",
"progressOut",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // RootRotationProgress outputs progress information for convergence of a root rotation. | [
"RootRotationProgress",
"outputs",
"progress",
"information",
"for",
"convergence",
"of",
"a",
"root",
"rotation",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/swarm/progress/root_rotation.go#L29-L72 | train |
docker/cli | internal/containerizedengine/update.go | ActivateEngine | func (c *baseClient) ActivateEngine(ctx context.Context, opts clitypes.EngineInitOptions, out clitypes.OutStream,
authConfig *types.AuthConfig) error {
// If the user didn't specify an image, determine the correct enterprise image to use
if opts.EngineImage == "" {
localMetadata, err := versions.GetCurrentRuntimeMetadata(opts.RuntimeMetadataDir)
if err != nil {
return errors.Wrap(err, "unable to determine the installed engine version. Specify which engine image to update with --engine-image")
}
engineImage := localMetadata.EngineImage
if engineImage == clitypes.EnterpriseEngineImage || engineImage == clitypes.CommunityEngineImage {
opts.EngineImage = clitypes.EnterpriseEngineImage
} else {
// Chop off the standard prefix and retain any trailing OS specific image details
// e.g., engine-community-dm -> engine-enterprise-dm
engineImage = strings.TrimPrefix(engineImage, clitypes.EnterpriseEngineImage)
engineImage = strings.TrimPrefix(engineImage, clitypes.CommunityEngineImage)
opts.EngineImage = clitypes.EnterpriseEngineImage + engineImage
}
}
ctx = namespaces.WithNamespace(ctx, engineNamespace)
return c.DoUpdate(ctx, opts, out, authConfig)
} | go | func (c *baseClient) ActivateEngine(ctx context.Context, opts clitypes.EngineInitOptions, out clitypes.OutStream,
authConfig *types.AuthConfig) error {
// If the user didn't specify an image, determine the correct enterprise image to use
if opts.EngineImage == "" {
localMetadata, err := versions.GetCurrentRuntimeMetadata(opts.RuntimeMetadataDir)
if err != nil {
return errors.Wrap(err, "unable to determine the installed engine version. Specify which engine image to update with --engine-image")
}
engineImage := localMetadata.EngineImage
if engineImage == clitypes.EnterpriseEngineImage || engineImage == clitypes.CommunityEngineImage {
opts.EngineImage = clitypes.EnterpriseEngineImage
} else {
// Chop off the standard prefix and retain any trailing OS specific image details
// e.g., engine-community-dm -> engine-enterprise-dm
engineImage = strings.TrimPrefix(engineImage, clitypes.EnterpriseEngineImage)
engineImage = strings.TrimPrefix(engineImage, clitypes.CommunityEngineImage)
opts.EngineImage = clitypes.EnterpriseEngineImage + engineImage
}
}
ctx = namespaces.WithNamespace(ctx, engineNamespace)
return c.DoUpdate(ctx, opts, out, authConfig)
} | [
"func",
"(",
"c",
"*",
"baseClient",
")",
"ActivateEngine",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"clitypes",
".",
"EngineInitOptions",
",",
"out",
"clitypes",
".",
"OutStream",
",",
"authConfig",
"*",
"types",
".",
"AuthConfig",
")",
"error",
"{",
"// If the user didn't specify an image, determine the correct enterprise image to use",
"if",
"opts",
".",
"EngineImage",
"==",
"\"",
"\"",
"{",
"localMetadata",
",",
"err",
":=",
"versions",
".",
"GetCurrentRuntimeMetadata",
"(",
"opts",
".",
"RuntimeMetadataDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"engineImage",
":=",
"localMetadata",
".",
"EngineImage",
"\n",
"if",
"engineImage",
"==",
"clitypes",
".",
"EnterpriseEngineImage",
"||",
"engineImage",
"==",
"clitypes",
".",
"CommunityEngineImage",
"{",
"opts",
".",
"EngineImage",
"=",
"clitypes",
".",
"EnterpriseEngineImage",
"\n",
"}",
"else",
"{",
"// Chop off the standard prefix and retain any trailing OS specific image details",
"// e.g., engine-community-dm -> engine-enterprise-dm",
"engineImage",
"=",
"strings",
".",
"TrimPrefix",
"(",
"engineImage",
",",
"clitypes",
".",
"EnterpriseEngineImage",
")",
"\n",
"engineImage",
"=",
"strings",
".",
"TrimPrefix",
"(",
"engineImage",
",",
"clitypes",
".",
"CommunityEngineImage",
")",
"\n",
"opts",
".",
"EngineImage",
"=",
"clitypes",
".",
"EnterpriseEngineImage",
"+",
"engineImage",
"\n",
"}",
"\n",
"}",
"\n\n",
"ctx",
"=",
"namespaces",
".",
"WithNamespace",
"(",
"ctx",
",",
"engineNamespace",
")",
"\n",
"return",
"c",
".",
"DoUpdate",
"(",
"ctx",
",",
"opts",
",",
"out",
",",
"authConfig",
")",
"\n",
"}"
] | // ActivateEngine will switch the image from the CE to EE image | [
"ActivateEngine",
"will",
"switch",
"the",
"image",
"from",
"the",
"CE",
"to",
"EE",
"image"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/containerizedengine/update.go#L24-L48 | train |
docker/cli | internal/containerizedengine/update.go | DoUpdate | func (c *baseClient) DoUpdate(ctx context.Context, opts clitypes.EngineInitOptions, out clitypes.OutStream,
authConfig *types.AuthConfig) error {
ctx = namespaces.WithNamespace(ctx, engineNamespace)
if opts.EngineVersion == "" {
// TODO - Future enhancement: This could be improved to be
// smart about figuring out the latest patch rev for the
// current engine version and automatically apply it so users
// could stay in sync by simply having a scheduled
// `docker engine update`
return fmt.Errorf("pick the version you want to update to with --version")
}
var localMetadata *clitypes.RuntimeMetadata
if opts.EngineImage == "" {
var err error
localMetadata, err = versions.GetCurrentRuntimeMetadata(opts.RuntimeMetadataDir)
if err != nil {
return errors.Wrap(err, "unable to determine the installed engine version. Specify which engine image to update with --engine-image set to 'engine-community' or 'engine-enterprise'")
}
opts.EngineImage = localMetadata.EngineImage
}
imageName := fmt.Sprintf("%s/%s:%s", opts.RegistryPrefix, opts.EngineImage, opts.EngineVersion)
// Look for desired image
image, err := c.cclient.GetImage(ctx, imageName)
if err != nil {
if errdefs.IsNotFound(err) {
image, err = c.pullWithAuth(ctx, imageName, out, authConfig)
if err != nil {
return errors.Wrapf(err, "unable to pull image %s", imageName)
}
} else {
return errors.Wrapf(err, "unable to check for image %s", imageName)
}
}
// Make sure we're safe to proceed
newMetadata, err := c.PreflightCheck(ctx, image)
if err != nil {
return err
}
if localMetadata != nil {
if localMetadata.Platform != newMetadata.Platform {
fmt.Fprintf(out, "\nNotice: you have switched to \"%s\". Refer to %s for update instructions.\n\n", newMetadata.Platform, getReleaseNotesURL(imageName))
}
}
if err := c.cclient.Install(ctx, image, containerd.WithInstallReplace, containerd.WithInstallPath("/usr")); err != nil {
return err
}
return versions.WriteRuntimeMetadata(opts.RuntimeMetadataDir, newMetadata)
} | go | func (c *baseClient) DoUpdate(ctx context.Context, opts clitypes.EngineInitOptions, out clitypes.OutStream,
authConfig *types.AuthConfig) error {
ctx = namespaces.WithNamespace(ctx, engineNamespace)
if opts.EngineVersion == "" {
// TODO - Future enhancement: This could be improved to be
// smart about figuring out the latest patch rev for the
// current engine version and automatically apply it so users
// could stay in sync by simply having a scheduled
// `docker engine update`
return fmt.Errorf("pick the version you want to update to with --version")
}
var localMetadata *clitypes.RuntimeMetadata
if opts.EngineImage == "" {
var err error
localMetadata, err = versions.GetCurrentRuntimeMetadata(opts.RuntimeMetadataDir)
if err != nil {
return errors.Wrap(err, "unable to determine the installed engine version. Specify which engine image to update with --engine-image set to 'engine-community' or 'engine-enterprise'")
}
opts.EngineImage = localMetadata.EngineImage
}
imageName := fmt.Sprintf("%s/%s:%s", opts.RegistryPrefix, opts.EngineImage, opts.EngineVersion)
// Look for desired image
image, err := c.cclient.GetImage(ctx, imageName)
if err != nil {
if errdefs.IsNotFound(err) {
image, err = c.pullWithAuth(ctx, imageName, out, authConfig)
if err != nil {
return errors.Wrapf(err, "unable to pull image %s", imageName)
}
} else {
return errors.Wrapf(err, "unable to check for image %s", imageName)
}
}
// Make sure we're safe to proceed
newMetadata, err := c.PreflightCheck(ctx, image)
if err != nil {
return err
}
if localMetadata != nil {
if localMetadata.Platform != newMetadata.Platform {
fmt.Fprintf(out, "\nNotice: you have switched to \"%s\". Refer to %s for update instructions.\n\n", newMetadata.Platform, getReleaseNotesURL(imageName))
}
}
if err := c.cclient.Install(ctx, image, containerd.WithInstallReplace, containerd.WithInstallPath("/usr")); err != nil {
return err
}
return versions.WriteRuntimeMetadata(opts.RuntimeMetadataDir, newMetadata)
} | [
"func",
"(",
"c",
"*",
"baseClient",
")",
"DoUpdate",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"clitypes",
".",
"EngineInitOptions",
",",
"out",
"clitypes",
".",
"OutStream",
",",
"authConfig",
"*",
"types",
".",
"AuthConfig",
")",
"error",
"{",
"ctx",
"=",
"namespaces",
".",
"WithNamespace",
"(",
"ctx",
",",
"engineNamespace",
")",
"\n",
"if",
"opts",
".",
"EngineVersion",
"==",
"\"",
"\"",
"{",
"// TODO - Future enhancement: This could be improved to be",
"// smart about figuring out the latest patch rev for the",
"// current engine version and automatically apply it so users",
"// could stay in sync by simply having a scheduled",
"// `docker engine update`",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"var",
"localMetadata",
"*",
"clitypes",
".",
"RuntimeMetadata",
"\n",
"if",
"opts",
".",
"EngineImage",
"==",
"\"",
"\"",
"{",
"var",
"err",
"error",
"\n",
"localMetadata",
",",
"err",
"=",
"versions",
".",
"GetCurrentRuntimeMetadata",
"(",
"opts",
".",
"RuntimeMetadataDir",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"opts",
".",
"EngineImage",
"=",
"localMetadata",
".",
"EngineImage",
"\n",
"}",
"\n\n",
"imageName",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"opts",
".",
"RegistryPrefix",
",",
"opts",
".",
"EngineImage",
",",
"opts",
".",
"EngineVersion",
")",
"\n\n",
"// Look for desired image",
"image",
",",
"err",
":=",
"c",
".",
"cclient",
".",
"GetImage",
"(",
"ctx",
",",
"imageName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errdefs",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"image",
",",
"err",
"=",
"c",
".",
"pullWithAuth",
"(",
"ctx",
",",
"imageName",
",",
"out",
",",
"authConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"imageName",
")",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"imageName",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Make sure we're safe to proceed",
"newMetadata",
",",
"err",
":=",
"c",
".",
"PreflightCheck",
"(",
"ctx",
",",
"image",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"localMetadata",
"!=",
"nil",
"{",
"if",
"localMetadata",
".",
"Platform",
"!=",
"newMetadata",
".",
"Platform",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\\n",
"\\\"",
"\\\"",
"\\n",
"\\n",
"\"",
",",
"newMetadata",
".",
"Platform",
",",
"getReleaseNotesURL",
"(",
"imageName",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"c",
".",
"cclient",
".",
"Install",
"(",
"ctx",
",",
"image",
",",
"containerd",
".",
"WithInstallReplace",
",",
"containerd",
".",
"WithInstallPath",
"(",
"\"",
"\"",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"versions",
".",
"WriteRuntimeMetadata",
"(",
"opts",
".",
"RuntimeMetadataDir",
",",
"newMetadata",
")",
"\n",
"}"
] | // DoUpdate performs the underlying engine update | [
"DoUpdate",
"performs",
"the",
"underlying",
"engine",
"update"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/containerizedengine/update.go#L51-L104 | train |
docker/cli | internal/containerizedengine/update.go | getReleaseNotesURL | func getReleaseNotesURL(imageName string) string {
versionTag := ""
distributionRef, err := reference.ParseNormalizedNamed(imageName)
if err == nil {
taggedRef, ok := distributionRef.(reference.NamedTagged)
if ok {
versionTag = taggedRef.Tag()
}
}
return fmt.Sprintf("%s/%s", clitypes.ReleaseNotePrefix, versionTag)
} | go | func getReleaseNotesURL(imageName string) string {
versionTag := ""
distributionRef, err := reference.ParseNormalizedNamed(imageName)
if err == nil {
taggedRef, ok := distributionRef.(reference.NamedTagged)
if ok {
versionTag = taggedRef.Tag()
}
}
return fmt.Sprintf("%s/%s", clitypes.ReleaseNotePrefix, versionTag)
} | [
"func",
"getReleaseNotesURL",
"(",
"imageName",
"string",
")",
"string",
"{",
"versionTag",
":=",
"\"",
"\"",
"\n",
"distributionRef",
",",
"err",
":=",
"reference",
".",
"ParseNormalizedNamed",
"(",
"imageName",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"taggedRef",
",",
"ok",
":=",
"distributionRef",
".",
"(",
"reference",
".",
"NamedTagged",
")",
"\n",
"if",
"ok",
"{",
"versionTag",
"=",
"taggedRef",
".",
"Tag",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"clitypes",
".",
"ReleaseNotePrefix",
",",
"versionTag",
")",
"\n",
"}"
] | // getReleaseNotesURL returns a release notes url
// If the image name does not contain a version tag, the base release notes URL is returned | [
"getReleaseNotesURL",
"returns",
"a",
"release",
"notes",
"url",
"If",
"the",
"image",
"name",
"does",
"not",
"contain",
"a",
"version",
"tag",
"the",
"base",
"release",
"notes",
"URL",
"is",
"returned"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/containerizedengine/update.go#L173-L183 | train |
docker/cli | cli/command/context/import.go | RunImport | func RunImport(dockerCli command.Cli, name string, source string) error {
if err := checkContextNameForCreation(dockerCli.ContextStore(), name); err != nil {
return err
}
var reader io.Reader
if source == "-" {
reader = dockerCli.In()
} else {
f, err := os.Open(source)
if err != nil {
return err
}
defer f.Close()
reader = f
}
if err := store.Import(name, dockerCli.ContextStore(), reader); err != nil {
return err
}
fmt.Fprintln(dockerCli.Out(), name)
fmt.Fprintf(dockerCli.Err(), "Successfully imported context %q\n", name)
return nil
} | go | func RunImport(dockerCli command.Cli, name string, source string) error {
if err := checkContextNameForCreation(dockerCli.ContextStore(), name); err != nil {
return err
}
var reader io.Reader
if source == "-" {
reader = dockerCli.In()
} else {
f, err := os.Open(source)
if err != nil {
return err
}
defer f.Close()
reader = f
}
if err := store.Import(name, dockerCli.ContextStore(), reader); err != nil {
return err
}
fmt.Fprintln(dockerCli.Out(), name)
fmt.Fprintf(dockerCli.Err(), "Successfully imported context %q\n", name)
return nil
} | [
"func",
"RunImport",
"(",
"dockerCli",
"command",
".",
"Cli",
",",
"name",
"string",
",",
"source",
"string",
")",
"error",
"{",
"if",
"err",
":=",
"checkContextNameForCreation",
"(",
"dockerCli",
".",
"ContextStore",
"(",
")",
",",
"name",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"reader",
"io",
".",
"Reader",
"\n",
"if",
"source",
"==",
"\"",
"\"",
"{",
"reader",
"=",
"dockerCli",
".",
"In",
"(",
")",
"\n",
"}",
"else",
"{",
"f",
",",
"err",
":=",
"os",
".",
"Open",
"(",
"source",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"reader",
"=",
"f",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"store",
".",
"Import",
"(",
"name",
",",
"dockerCli",
".",
"ContextStore",
"(",
")",
",",
"reader",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintln",
"(",
"dockerCli",
".",
"Out",
"(",
")",
",",
"name",
")",
"\n",
"fmt",
".",
"Fprintf",
"(",
"dockerCli",
".",
"Err",
"(",
")",
",",
"\"",
"\\n",
"\"",
",",
"name",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // RunImport imports a Docker context | [
"RunImport",
"imports",
"a",
"Docker",
"context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/context/import.go#L27-L49 | train |
docker/cli | cli/command/registry/formatter_search.go | NewSearchFormat | func NewSearchFormat(source string) formatter.Format {
switch source {
case "":
return defaultSearchTableFormat
case formatter.TableFormatKey:
return defaultSearchTableFormat
}
return formatter.Format(source)
} | go | func NewSearchFormat(source string) formatter.Format {
switch source {
case "":
return defaultSearchTableFormat
case formatter.TableFormatKey:
return defaultSearchTableFormat
}
return formatter.Format(source)
} | [
"func",
"NewSearchFormat",
"(",
"source",
"string",
")",
"formatter",
".",
"Format",
"{",
"switch",
"source",
"{",
"case",
"\"",
"\"",
":",
"return",
"defaultSearchTableFormat",
"\n",
"case",
"formatter",
".",
"TableFormatKey",
":",
"return",
"defaultSearchTableFormat",
"\n",
"}",
"\n",
"return",
"formatter",
".",
"Format",
"(",
"source",
")",
"\n",
"}"
] | // NewSearchFormat returns a Format for rendering using a network Context | [
"NewSearchFormat",
"returns",
"a",
"Format",
"for",
"rendering",
"using",
"a",
"network",
"Context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/registry/formatter_search.go#L20-L28 | train |
docker/cli | cli/command/registry/formatter_search.go | SearchWrite | func SearchWrite(ctx formatter.Context, results []registry.SearchResult, auto bool, stars int) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, result := range results {
// --automated and -s, --stars are deprecated since Docker 1.12
if (auto && !result.IsAutomated) || (stars > result.StarCount) {
continue
}
searchCtx := &searchContext{trunc: ctx.Trunc, s: result}
if err := format(searchCtx); err != nil {
return err
}
}
return nil
}
searchCtx := searchContext{}
searchCtx.Header = formatter.SubHeaderContext{
"Name": formatter.NameHeader,
"Description": formatter.DescriptionHeader,
"StarCount": starsHeader,
"IsOfficial": officialHeader,
"IsAutomated": automatedHeader,
}
return ctx.Write(&searchCtx, render)
} | go | func SearchWrite(ctx formatter.Context, results []registry.SearchResult, auto bool, stars int) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, result := range results {
// --automated and -s, --stars are deprecated since Docker 1.12
if (auto && !result.IsAutomated) || (stars > result.StarCount) {
continue
}
searchCtx := &searchContext{trunc: ctx.Trunc, s: result}
if err := format(searchCtx); err != nil {
return err
}
}
return nil
}
searchCtx := searchContext{}
searchCtx.Header = formatter.SubHeaderContext{
"Name": formatter.NameHeader,
"Description": formatter.DescriptionHeader,
"StarCount": starsHeader,
"IsOfficial": officialHeader,
"IsAutomated": automatedHeader,
}
return ctx.Write(&searchCtx, render)
} | [
"func",
"SearchWrite",
"(",
"ctx",
"formatter",
".",
"Context",
",",
"results",
"[",
"]",
"registry",
".",
"SearchResult",
",",
"auto",
"bool",
",",
"stars",
"int",
")",
"error",
"{",
"render",
":=",
"func",
"(",
"format",
"func",
"(",
"subContext",
"formatter",
".",
"SubContext",
")",
"error",
")",
"error",
"{",
"for",
"_",
",",
"result",
":=",
"range",
"results",
"{",
"// --automated and -s, --stars are deprecated since Docker 1.12",
"if",
"(",
"auto",
"&&",
"!",
"result",
".",
"IsAutomated",
")",
"||",
"(",
"stars",
">",
"result",
".",
"StarCount",
")",
"{",
"continue",
"\n",
"}",
"\n",
"searchCtx",
":=",
"&",
"searchContext",
"{",
"trunc",
":",
"ctx",
".",
"Trunc",
",",
"s",
":",
"result",
"}",
"\n",
"if",
"err",
":=",
"format",
"(",
"searchCtx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"searchCtx",
":=",
"searchContext",
"{",
"}",
"\n",
"searchCtx",
".",
"Header",
"=",
"formatter",
".",
"SubHeaderContext",
"{",
"\"",
"\"",
":",
"formatter",
".",
"NameHeader",
",",
"\"",
"\"",
":",
"formatter",
".",
"DescriptionHeader",
",",
"\"",
"\"",
":",
"starsHeader",
",",
"\"",
"\"",
":",
"officialHeader",
",",
"\"",
"\"",
":",
"automatedHeader",
",",
"}",
"\n",
"return",
"ctx",
".",
"Write",
"(",
"&",
"searchCtx",
",",
"render",
")",
"\n",
"}"
] | // SearchWrite writes the context | [
"SearchWrite",
"writes",
"the",
"context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/registry/formatter_search.go#L31-L54 | train |
docker/cli | cli/command/context.go | GetDockerContext | func GetDockerContext(storeMetadata store.Metadata) (DockerContext, error) {
if storeMetadata.Metadata == nil {
// can happen if we save endpoints before assigning a context metadata
// it is totally valid, and we should return a default initialized value
return DockerContext{}, nil
}
res, ok := storeMetadata.Metadata.(DockerContext)
if !ok {
return DockerContext{}, errors.New("context metadata is not a valid DockerContext")
}
return res, nil
} | go | func GetDockerContext(storeMetadata store.Metadata) (DockerContext, error) {
if storeMetadata.Metadata == nil {
// can happen if we save endpoints before assigning a context metadata
// it is totally valid, and we should return a default initialized value
return DockerContext{}, nil
}
res, ok := storeMetadata.Metadata.(DockerContext)
if !ok {
return DockerContext{}, errors.New("context metadata is not a valid DockerContext")
}
return res, nil
} | [
"func",
"GetDockerContext",
"(",
"storeMetadata",
"store",
".",
"Metadata",
")",
"(",
"DockerContext",
",",
"error",
")",
"{",
"if",
"storeMetadata",
".",
"Metadata",
"==",
"nil",
"{",
"// can happen if we save endpoints before assigning a context metadata",
"// it is totally valid, and we should return a default initialized value",
"return",
"DockerContext",
"{",
"}",
",",
"nil",
"\n",
"}",
"\n",
"res",
",",
"ok",
":=",
"storeMetadata",
".",
"Metadata",
".",
"(",
"DockerContext",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"DockerContext",
"{",
"}",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"res",
",",
"nil",
"\n",
"}"
] | // GetDockerContext extracts metadata from stored context metadata | [
"GetDockerContext",
"extracts",
"metadata",
"from",
"stored",
"context",
"metadata"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/context.go#L16-L27 | train |
docker/cli | cli/command/stack/ps.go | RunPs | func RunPs(dockerCli command.Cli, flags *pflag.FlagSet, commonOrchestrator command.Orchestrator, opts options.PS) error {
return runOrchestratedCommand(dockerCli, flags, commonOrchestrator,
func() error { return swarm.RunPS(dockerCli, opts) },
func(kli *kubernetes.KubeCli) error { return kubernetes.RunPS(kli, opts) })
} | go | func RunPs(dockerCli command.Cli, flags *pflag.FlagSet, commonOrchestrator command.Orchestrator, opts options.PS) error {
return runOrchestratedCommand(dockerCli, flags, commonOrchestrator,
func() error { return swarm.RunPS(dockerCli, opts) },
func(kli *kubernetes.KubeCli) error { return kubernetes.RunPS(kli, opts) })
} | [
"func",
"RunPs",
"(",
"dockerCli",
"command",
".",
"Cli",
",",
"flags",
"*",
"pflag",
".",
"FlagSet",
",",
"commonOrchestrator",
"command",
".",
"Orchestrator",
",",
"opts",
"options",
".",
"PS",
")",
"error",
"{",
"return",
"runOrchestratedCommand",
"(",
"dockerCli",
",",
"flags",
",",
"commonOrchestrator",
",",
"func",
"(",
")",
"error",
"{",
"return",
"swarm",
".",
"RunPS",
"(",
"dockerCli",
",",
"opts",
")",
"}",
",",
"func",
"(",
"kli",
"*",
"kubernetes",
".",
"KubeCli",
")",
"error",
"{",
"return",
"kubernetes",
".",
"RunPS",
"(",
"kli",
",",
"opts",
")",
"}",
")",
"\n",
"}"
] | // RunPs performs a stack ps against the specified orchestrator | [
"RunPs",
"performs",
"a",
"stack",
"ps",
"against",
"the",
"specified",
"orchestrator"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/ps.go#L40-L44 | train |
docker/cli | internal/pkg/containerized/pauseandrun.go | AtomicImageUpdate | func AtomicImageUpdate(ctx context.Context, container containerd.Container, image containerd.Image, healthcheckFn func() error) error {
updateCompleted := false
err := pauseAndRun(ctx, container, func() error {
if err := container.Update(ctx, WithUpgrade(image)); err != nil {
return errors.Wrap(err, "failed to update to new image")
}
updateCompleted = true
task, err := container.Task(ctx, nil)
if err != nil {
if errdefs.IsNotFound(err) {
return nil
}
return errors.Wrap(err, "failed to lookup task")
}
return task.Kill(ctx, sigTERM)
})
if err != nil {
if updateCompleted {
logrus.WithError(err).Error("failed to update, rolling back")
return rollBack(ctx, container)
}
return err
}
if err := healthcheckFn(); err != nil {
logrus.WithError(err).Error("failed health check, rolling back")
return rollBack(ctx, container)
}
return nil
} | go | func AtomicImageUpdate(ctx context.Context, container containerd.Container, image containerd.Image, healthcheckFn func() error) error {
updateCompleted := false
err := pauseAndRun(ctx, container, func() error {
if err := container.Update(ctx, WithUpgrade(image)); err != nil {
return errors.Wrap(err, "failed to update to new image")
}
updateCompleted = true
task, err := container.Task(ctx, nil)
if err != nil {
if errdefs.IsNotFound(err) {
return nil
}
return errors.Wrap(err, "failed to lookup task")
}
return task.Kill(ctx, sigTERM)
})
if err != nil {
if updateCompleted {
logrus.WithError(err).Error("failed to update, rolling back")
return rollBack(ctx, container)
}
return err
}
if err := healthcheckFn(); err != nil {
logrus.WithError(err).Error("failed health check, rolling back")
return rollBack(ctx, container)
}
return nil
} | [
"func",
"AtomicImageUpdate",
"(",
"ctx",
"context",
".",
"Context",
",",
"container",
"containerd",
".",
"Container",
",",
"image",
"containerd",
".",
"Image",
",",
"healthcheckFn",
"func",
"(",
")",
"error",
")",
"error",
"{",
"updateCompleted",
":=",
"false",
"\n",
"err",
":=",
"pauseAndRun",
"(",
"ctx",
",",
"container",
",",
"func",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"container",
".",
"Update",
"(",
"ctx",
",",
"WithUpgrade",
"(",
"image",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"updateCompleted",
"=",
"true",
"\n",
"task",
",",
"err",
":=",
"container",
".",
"Task",
"(",
"ctx",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"errdefs",
".",
"IsNotFound",
"(",
"err",
")",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"task",
".",
"Kill",
"(",
"ctx",
",",
"sigTERM",
")",
"\n",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"updateCompleted",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"rollBack",
"(",
"ctx",
",",
"container",
")",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"healthcheckFn",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"WithError",
"(",
"err",
")",
".",
"Error",
"(",
"\"",
"\"",
")",
"\n",
"return",
"rollBack",
"(",
"ctx",
",",
"container",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // AtomicImageUpdate will perform an update of the given container with the new image
// and verify success via the provided healthcheckFn. If the healthcheck fails, the
// container will be reverted to the prior image | [
"AtomicImageUpdate",
"will",
"perform",
"an",
"update",
"of",
"the",
"given",
"container",
"with",
"the",
"new",
"image",
"and",
"verify",
"success",
"via",
"the",
"provided",
"healthcheckFn",
".",
"If",
"the",
"healthcheck",
"fails",
"the",
"container",
"will",
"be",
"reverted",
"to",
"the",
"prior",
"image"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/pkg/containerized/pauseandrun.go#L15-L43 | train |
docker/cli | opts/throttledevice.go | ValidateThrottleBpsDevice | func ValidateThrottleBpsDevice(val string) (*blkiodev.ThrottleDevice, 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)
}
rate, err := units.RAMInBytes(split[1])
if err != nil {
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val)
}
if rate < 0 {
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val)
}
return &blkiodev.ThrottleDevice{
Path: split[0],
Rate: uint64(rate),
}, nil
} | go | func ValidateThrottleBpsDevice(val string) (*blkiodev.ThrottleDevice, 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)
}
rate, err := units.RAMInBytes(split[1])
if err != nil {
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val)
}
if rate < 0 {
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>[<unit>]. Number must be a positive integer. Unit is optional and can be kb, mb, or gb", val)
}
return &blkiodev.ThrottleDevice{
Path: split[0],
Rate: uint64(rate),
}, nil
} | [
"func",
"ValidateThrottleBpsDevice",
"(",
"val",
"string",
")",
"(",
"*",
"blkiodev",
".",
"ThrottleDevice",
",",
"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",
"rate",
",",
"err",
":=",
"units",
".",
"RAMInBytes",
"(",
"split",
"[",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"val",
")",
"\n",
"}",
"\n",
"if",
"rate",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"val",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"blkiodev",
".",
"ThrottleDevice",
"{",
"Path",
":",
"split",
"[",
"0",
"]",
",",
"Rate",
":",
"uint64",
"(",
"rate",
")",
",",
"}",
",",
"nil",
"\n",
"}"
] | // ValidateThrottleBpsDevice validates that the specified string has a valid device-rate format. | [
"ValidateThrottleBpsDevice",
"validates",
"that",
"the",
"specified",
"string",
"has",
"a",
"valid",
"device",
"-",
"rate",
"format",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/throttledevice.go#L16-L36 | train |
docker/cli | opts/throttledevice.go | ValidateThrottleIOpsDevice | func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, 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)
}
rate, err := strconv.ParseUint(split[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
}
if rate < 0 {
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
}
return &blkiodev.ThrottleDevice{Path: split[0], Rate: rate}, nil
} | go | func ValidateThrottleIOpsDevice(val string) (*blkiodev.ThrottleDevice, 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)
}
rate, err := strconv.ParseUint(split[1], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
}
if rate < 0 {
return nil, fmt.Errorf("invalid rate for device: %s. The correct format is <device-path>:<number>. Number must be a positive integer", val)
}
return &blkiodev.ThrottleDevice{Path: split[0], Rate: rate}, nil
} | [
"func",
"ValidateThrottleIOpsDevice",
"(",
"val",
"string",
")",
"(",
"*",
"blkiodev",
".",
"ThrottleDevice",
",",
"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",
"rate",
",",
"err",
":=",
"strconv",
".",
"ParseUint",
"(",
"split",
"[",
"1",
"]",
",",
"10",
",",
"64",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"val",
")",
"\n",
"}",
"\n",
"if",
"rate",
"<",
"0",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"val",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"blkiodev",
".",
"ThrottleDevice",
"{",
"Path",
":",
"split",
"[",
"0",
"]",
",",
"Rate",
":",
"rate",
"}",
",",
"nil",
"\n",
"}"
] | // ValidateThrottleIOpsDevice validates that the specified string has a valid device-rate format. | [
"ValidateThrottleIOpsDevice",
"validates",
"that",
"the",
"specified",
"string",
"has",
"a",
"valid",
"device",
"-",
"rate",
"format",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/throttledevice.go#L39-L56 | train |
docker/cli | opts/throttledevice.go | NewThrottledeviceOpt | func NewThrottledeviceOpt(validator ValidatorThrottleFctType) ThrottledeviceOpt {
values := []*blkiodev.ThrottleDevice{}
return ThrottledeviceOpt{
values: values,
validator: validator,
}
} | go | func NewThrottledeviceOpt(validator ValidatorThrottleFctType) ThrottledeviceOpt {
values := []*blkiodev.ThrottleDevice{}
return ThrottledeviceOpt{
values: values,
validator: validator,
}
} | [
"func",
"NewThrottledeviceOpt",
"(",
"validator",
"ValidatorThrottleFctType",
")",
"ThrottledeviceOpt",
"{",
"values",
":=",
"[",
"]",
"*",
"blkiodev",
".",
"ThrottleDevice",
"{",
"}",
"\n",
"return",
"ThrottledeviceOpt",
"{",
"values",
":",
"values",
",",
"validator",
":",
"validator",
",",
"}",
"\n",
"}"
] | // NewThrottledeviceOpt creates a new ThrottledeviceOpt | [
"NewThrottledeviceOpt",
"creates",
"a",
"new",
"ThrottledeviceOpt"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/throttledevice.go#L65-L71 | train |
docker/cli | opts/throttledevice.go | Set | func (opt *ThrottledeviceOpt) Set(val string) error {
var value *blkiodev.ThrottleDevice
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 *ThrottledeviceOpt) Set(val string) error {
var value *blkiodev.ThrottleDevice
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",
"*",
"ThrottledeviceOpt",
")",
"Set",
"(",
"val",
"string",
")",
"error",
"{",
"var",
"value",
"*",
"blkiodev",
".",
"ThrottleDevice",
"\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 ThrottleDevice and sets its name as a key in ThrottledeviceOpt | [
"Set",
"validates",
"a",
"ThrottleDevice",
"and",
"sets",
"its",
"name",
"as",
"a",
"key",
"in",
"ThrottledeviceOpt"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/throttledevice.go#L74-L85 | train |
docker/cli | opts/throttledevice.go | String | func (opt *ThrottledeviceOpt) String() string {
var out []string
for _, v := range opt.values {
out = append(out, v.String())
}
return fmt.Sprintf("%v", out)
} | go | func (opt *ThrottledeviceOpt) String() string {
var out []string
for _, v := range opt.values {
out = append(out, v.String())
}
return fmt.Sprintf("%v", out)
} | [
"func",
"(",
"opt",
"*",
"ThrottledeviceOpt",
")",
"String",
"(",
")",
"string",
"{",
"var",
"out",
"[",
"]",
"string",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"opt",
".",
"values",
"{",
"out",
"=",
"append",
"(",
"out",
",",
"v",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"out",
")",
"\n",
"}"
] | // String returns ThrottledeviceOpt values as a string. | [
"String",
"returns",
"ThrottledeviceOpt",
"values",
"as",
"a",
"string",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/throttledevice.go#L88-L95 | train |
docker/cli | opts/throttledevice.go | GetList | func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice {
var throttledevice []*blkiodev.ThrottleDevice
throttledevice = append(throttledevice, opt.values...)
return throttledevice
} | go | func (opt *ThrottledeviceOpt) GetList() []*blkiodev.ThrottleDevice {
var throttledevice []*blkiodev.ThrottleDevice
throttledevice = append(throttledevice, opt.values...)
return throttledevice
} | [
"func",
"(",
"opt",
"*",
"ThrottledeviceOpt",
")",
"GetList",
"(",
")",
"[",
"]",
"*",
"blkiodev",
".",
"ThrottleDevice",
"{",
"var",
"throttledevice",
"[",
"]",
"*",
"blkiodev",
".",
"ThrottleDevice",
"\n",
"throttledevice",
"=",
"append",
"(",
"throttledevice",
",",
"opt",
".",
"values",
"...",
")",
"\n\n",
"return",
"throttledevice",
"\n",
"}"
] | // GetList returns a slice of pointers to ThrottleDevices. | [
"GetList",
"returns",
"a",
"slice",
"of",
"pointers",
"to",
"ThrottleDevices",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/throttledevice.go#L98-L103 | train |
docker/cli | cli/command/container/stop.go | NewStopCommand | func NewStopCommand(dockerCli command.Cli) *cobra.Command {
var opts stopOptions
cmd := &cobra.Command{
Use: "stop [OPTIONS] CONTAINER [CONTAINER...]",
Short: "Stop one or more running containers",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
opts.timeChanged = cmd.Flags().Changed("time")
return runStop(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.IntVarP(&opts.time, "time", "t", 10, "Seconds to wait for stop before killing it")
return cmd
} | go | func NewStopCommand(dockerCli command.Cli) *cobra.Command {
var opts stopOptions
cmd := &cobra.Command{
Use: "stop [OPTIONS] CONTAINER [CONTAINER...]",
Short: "Stop one or more running containers",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
opts.timeChanged = cmd.Flags().Changed("time")
return runStop(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.IntVarP(&opts.time, "time", "t", 10, "Seconds to wait for stop before killing it")
return cmd
} | [
"func",
"NewStopCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"stopOptions",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"RequiresMinArgs",
"(",
"1",
")",
",",
"RunE",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"opts",
".",
"containers",
"=",
"args",
"\n",
"opts",
".",
"timeChanged",
"=",
"cmd",
".",
"Flags",
"(",
")",
".",
"Changed",
"(",
"\"",
"\"",
")",
"\n",
"return",
"runStop",
"(",
"dockerCli",
",",
"&",
"opts",
")",
"\n",
"}",
",",
"}",
"\n\n",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n",
"flags",
".",
"IntVarP",
"(",
"&",
"opts",
".",
"time",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"10",
",",
"\"",
"\"",
")",
"\n",
"return",
"cmd",
"\n",
"}"
] | // NewStopCommand creates a new cobra.Command for `docker stop` | [
"NewStopCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"stop"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/stop.go#L23-L40 | train |
docker/cli | cli/command/stack/kubernetes/list.go | GetStacks | func GetStacks(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) {
if opts.AllNamespaces || len(opts.Namespaces) == 0 {
if isAllNamespacesDisabled(kubeCli.ConfigFile().Kubernetes) {
opts.AllNamespaces = true
}
return getStacksWithAllNamespaces(kubeCli, opts)
}
return getStacksWithNamespaces(kubeCli, opts, removeDuplicates(opts.Namespaces))
} | go | func GetStacks(kubeCli *KubeCli, opts options.List) ([]*formatter.Stack, error) {
if opts.AllNamespaces || len(opts.Namespaces) == 0 {
if isAllNamespacesDisabled(kubeCli.ConfigFile().Kubernetes) {
opts.AllNamespaces = true
}
return getStacksWithAllNamespaces(kubeCli, opts)
}
return getStacksWithNamespaces(kubeCli, opts, removeDuplicates(opts.Namespaces))
} | [
"func",
"GetStacks",
"(",
"kubeCli",
"*",
"KubeCli",
",",
"opts",
"options",
".",
"List",
")",
"(",
"[",
"]",
"*",
"formatter",
".",
"Stack",
",",
"error",
")",
"{",
"if",
"opts",
".",
"AllNamespaces",
"||",
"len",
"(",
"opts",
".",
"Namespaces",
")",
"==",
"0",
"{",
"if",
"isAllNamespacesDisabled",
"(",
"kubeCli",
".",
"ConfigFile",
"(",
")",
".",
"Kubernetes",
")",
"{",
"opts",
".",
"AllNamespaces",
"=",
"true",
"\n",
"}",
"\n",
"return",
"getStacksWithAllNamespaces",
"(",
"kubeCli",
",",
"opts",
")",
"\n",
"}",
"\n",
"return",
"getStacksWithNamespaces",
"(",
"kubeCli",
",",
"opts",
",",
"removeDuplicates",
"(",
"opts",
".",
"Namespaces",
")",
")",
"\n",
"}"
] | // GetStacks lists the kubernetes stacks | [
"GetStacks",
"lists",
"the",
"kubernetes",
"stacks"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/kubernetes/list.go#L21-L29 | train |
docker/cli | cli/registry/client/client.go | NewRegistryClient | func NewRegistryClient(resolver AuthConfigResolver, userAgent string, insecure bool) RegistryClient {
return &client{
authConfigResolver: resolver,
insecureRegistry: insecure,
userAgent: userAgent,
}
} | go | func NewRegistryClient(resolver AuthConfigResolver, userAgent string, insecure bool) RegistryClient {
return &client{
authConfigResolver: resolver,
insecureRegistry: insecure,
userAgent: userAgent,
}
} | [
"func",
"NewRegistryClient",
"(",
"resolver",
"AuthConfigResolver",
",",
"userAgent",
"string",
",",
"insecure",
"bool",
")",
"RegistryClient",
"{",
"return",
"&",
"client",
"{",
"authConfigResolver",
":",
"resolver",
",",
"insecureRegistry",
":",
"insecure",
",",
"userAgent",
":",
"userAgent",
",",
"}",
"\n",
"}"
] | // NewRegistryClient returns a new RegistryClient with a resolver | [
"NewRegistryClient",
"returns",
"a",
"new",
"RegistryClient",
"with",
"a",
"resolver"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/client.go#L32-L38 | train |
docker/cli | cli/registry/client/client.go | MountBlob | func (c *client) MountBlob(ctx context.Context, sourceRef reference.Canonical, targetRef reference.Named) error {
repoEndpoint, err := newDefaultRepositoryEndpoint(targetRef, c.insecureRegistry)
if err != nil {
return err
}
repo, err := c.getRepositoryForReference(ctx, targetRef, repoEndpoint)
if err != nil {
return err
}
lu, err := repo.Blobs(ctx).Create(ctx, distributionclient.WithMountFrom(sourceRef))
switch err.(type) {
case distribution.ErrBlobMounted:
logrus.Debugf("mount of blob %s succeeded", sourceRef)
return nil
case nil:
default:
return errors.Wrapf(err, "failed to mount blob %s to %s", sourceRef, targetRef)
}
lu.Cancel(ctx)
logrus.Debugf("mount of blob %s created", sourceRef)
return ErrBlobCreated{From: sourceRef, Target: targetRef}
} | go | func (c *client) MountBlob(ctx context.Context, sourceRef reference.Canonical, targetRef reference.Named) error {
repoEndpoint, err := newDefaultRepositoryEndpoint(targetRef, c.insecureRegistry)
if err != nil {
return err
}
repo, err := c.getRepositoryForReference(ctx, targetRef, repoEndpoint)
if err != nil {
return err
}
lu, err := repo.Blobs(ctx).Create(ctx, distributionclient.WithMountFrom(sourceRef))
switch err.(type) {
case distribution.ErrBlobMounted:
logrus.Debugf("mount of blob %s succeeded", sourceRef)
return nil
case nil:
default:
return errors.Wrapf(err, "failed to mount blob %s to %s", sourceRef, targetRef)
}
lu.Cancel(ctx)
logrus.Debugf("mount of blob %s created", sourceRef)
return ErrBlobCreated{From: sourceRef, Target: targetRef}
} | [
"func",
"(",
"c",
"*",
"client",
")",
"MountBlob",
"(",
"ctx",
"context",
".",
"Context",
",",
"sourceRef",
"reference",
".",
"Canonical",
",",
"targetRef",
"reference",
".",
"Named",
")",
"error",
"{",
"repoEndpoint",
",",
"err",
":=",
"newDefaultRepositoryEndpoint",
"(",
"targetRef",
",",
"c",
".",
"insecureRegistry",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"repo",
",",
"err",
":=",
"c",
".",
"getRepositoryForReference",
"(",
"ctx",
",",
"targetRef",
",",
"repoEndpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"lu",
",",
"err",
":=",
"repo",
".",
"Blobs",
"(",
"ctx",
")",
".",
"Create",
"(",
"ctx",
",",
"distributionclient",
".",
"WithMountFrom",
"(",
"sourceRef",
")",
")",
"\n",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"distribution",
".",
"ErrBlobMounted",
":",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"sourceRef",
")",
"\n",
"return",
"nil",
"\n",
"case",
"nil",
":",
"default",
":",
"return",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"sourceRef",
",",
"targetRef",
")",
"\n",
"}",
"\n",
"lu",
".",
"Cancel",
"(",
"ctx",
")",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"sourceRef",
")",
"\n",
"return",
"ErrBlobCreated",
"{",
"From",
":",
"sourceRef",
",",
"Target",
":",
"targetRef",
"}",
"\n",
"}"
] | // MountBlob into the registry, so it can be referenced by a manifest | [
"MountBlob",
"into",
"the",
"registry",
"so",
"it",
"can",
"be",
"referenced",
"by",
"a",
"manifest"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/client.go#L78-L99 | train |
docker/cli | cli/registry/client/client.go | PutManifest | func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest distribution.Manifest) (digest.Digest, error) {
repoEndpoint, err := newDefaultRepositoryEndpoint(ref, c.insecureRegistry)
if err != nil {
return digest.Digest(""), err
}
repo, err := c.getRepositoryForReference(ctx, ref, repoEndpoint)
if err != nil {
return digest.Digest(""), err
}
manifestService, err := repo.Manifests(ctx)
if err != nil {
return digest.Digest(""), err
}
_, opts, err := getManifestOptionsFromReference(ref)
if err != nil {
return digest.Digest(""), err
}
dgst, err := manifestService.Put(ctx, manifest, opts...)
return dgst, errors.Wrapf(err, "failed to put manifest %s", ref)
} | go | func (c *client) PutManifest(ctx context.Context, ref reference.Named, manifest distribution.Manifest) (digest.Digest, error) {
repoEndpoint, err := newDefaultRepositoryEndpoint(ref, c.insecureRegistry)
if err != nil {
return digest.Digest(""), err
}
repo, err := c.getRepositoryForReference(ctx, ref, repoEndpoint)
if err != nil {
return digest.Digest(""), err
}
manifestService, err := repo.Manifests(ctx)
if err != nil {
return digest.Digest(""), err
}
_, opts, err := getManifestOptionsFromReference(ref)
if err != nil {
return digest.Digest(""), err
}
dgst, err := manifestService.Put(ctx, manifest, opts...)
return dgst, errors.Wrapf(err, "failed to put manifest %s", ref)
} | [
"func",
"(",
"c",
"*",
"client",
")",
"PutManifest",
"(",
"ctx",
"context",
".",
"Context",
",",
"ref",
"reference",
".",
"Named",
",",
"manifest",
"distribution",
".",
"Manifest",
")",
"(",
"digest",
".",
"Digest",
",",
"error",
")",
"{",
"repoEndpoint",
",",
"err",
":=",
"newDefaultRepositoryEndpoint",
"(",
"ref",
",",
"c",
".",
"insecureRegistry",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"digest",
".",
"Digest",
"(",
"\"",
"\"",
")",
",",
"err",
"\n",
"}",
"\n\n",
"repo",
",",
"err",
":=",
"c",
".",
"getRepositoryForReference",
"(",
"ctx",
",",
"ref",
",",
"repoEndpoint",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"digest",
".",
"Digest",
"(",
"\"",
"\"",
")",
",",
"err",
"\n",
"}",
"\n\n",
"manifestService",
",",
"err",
":=",
"repo",
".",
"Manifests",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"digest",
".",
"Digest",
"(",
"\"",
"\"",
")",
",",
"err",
"\n",
"}",
"\n\n",
"_",
",",
"opts",
",",
"err",
":=",
"getManifestOptionsFromReference",
"(",
"ref",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"digest",
".",
"Digest",
"(",
"\"",
"\"",
")",
",",
"err",
"\n",
"}",
"\n\n",
"dgst",
",",
"err",
":=",
"manifestService",
".",
"Put",
"(",
"ctx",
",",
"manifest",
",",
"opts",
"...",
")",
"\n",
"return",
"dgst",
",",
"errors",
".",
"Wrapf",
"(",
"err",
",",
"\"",
"\"",
",",
"ref",
")",
"\n",
"}"
] | // PutManifest sends the manifest to a registry and returns the new digest | [
"PutManifest",
"sends",
"the",
"manifest",
"to",
"a",
"registry",
"and",
"returns",
"the",
"new",
"digest"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/client.go#L102-L125 | train |
docker/cli | cli/registry/client/client.go | GetManifest | func (c *client) GetManifest(ctx context.Context, ref reference.Named) (manifesttypes.ImageManifest, error) {
var result manifesttypes.ImageManifest
fetch := func(ctx context.Context, repo distribution.Repository, ref reference.Named) (bool, error) {
var err error
result, err = fetchManifest(ctx, repo, ref)
return result.Ref != nil, err
}
err := c.iterateEndpoints(ctx, ref, fetch)
return result, err
} | go | func (c *client) GetManifest(ctx context.Context, ref reference.Named) (manifesttypes.ImageManifest, error) {
var result manifesttypes.ImageManifest
fetch := func(ctx context.Context, repo distribution.Repository, ref reference.Named) (bool, error) {
var err error
result, err = fetchManifest(ctx, repo, ref)
return result.Ref != nil, err
}
err := c.iterateEndpoints(ctx, ref, fetch)
return result, err
} | [
"func",
"(",
"c",
"*",
"client",
")",
"GetManifest",
"(",
"ctx",
"context",
".",
"Context",
",",
"ref",
"reference",
".",
"Named",
")",
"(",
"manifesttypes",
".",
"ImageManifest",
",",
"error",
")",
"{",
"var",
"result",
"manifesttypes",
".",
"ImageManifest",
"\n",
"fetch",
":=",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"repo",
"distribution",
".",
"Repository",
",",
"ref",
"reference",
".",
"Named",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"result",
",",
"err",
"=",
"fetchManifest",
"(",
"ctx",
",",
"repo",
",",
"ref",
")",
"\n",
"return",
"result",
".",
"Ref",
"!=",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"err",
":=",
"c",
".",
"iterateEndpoints",
"(",
"ctx",
",",
"ref",
",",
"fetch",
")",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] | // GetManifest returns an ImageManifest for the reference | [
"GetManifest",
"returns",
"an",
"ImageManifest",
"for",
"the",
"reference"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/client.go#L164-L174 | train |
docker/cli | cli/registry/client/client.go | GetManifestList | func (c *client) GetManifestList(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error) {
result := []manifesttypes.ImageManifest{}
fetch := func(ctx context.Context, repo distribution.Repository, ref reference.Named) (bool, error) {
var err error
result, err = fetchList(ctx, repo, ref)
return len(result) > 0, err
}
err := c.iterateEndpoints(ctx, ref, fetch)
return result, err
} | go | func (c *client) GetManifestList(ctx context.Context, ref reference.Named) ([]manifesttypes.ImageManifest, error) {
result := []manifesttypes.ImageManifest{}
fetch := func(ctx context.Context, repo distribution.Repository, ref reference.Named) (bool, error) {
var err error
result, err = fetchList(ctx, repo, ref)
return len(result) > 0, err
}
err := c.iterateEndpoints(ctx, ref, fetch)
return result, err
} | [
"func",
"(",
"c",
"*",
"client",
")",
"GetManifestList",
"(",
"ctx",
"context",
".",
"Context",
",",
"ref",
"reference",
".",
"Named",
")",
"(",
"[",
"]",
"manifesttypes",
".",
"ImageManifest",
",",
"error",
")",
"{",
"result",
":=",
"[",
"]",
"manifesttypes",
".",
"ImageManifest",
"{",
"}",
"\n",
"fetch",
":=",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"repo",
"distribution",
".",
"Repository",
",",
"ref",
"reference",
".",
"Named",
")",
"(",
"bool",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"result",
",",
"err",
"=",
"fetchList",
"(",
"ctx",
",",
"repo",
",",
"ref",
")",
"\n",
"return",
"len",
"(",
"result",
")",
">",
"0",
",",
"err",
"\n",
"}",
"\n\n",
"err",
":=",
"c",
".",
"iterateEndpoints",
"(",
"ctx",
",",
"ref",
",",
"fetch",
")",
"\n",
"return",
"result",
",",
"err",
"\n",
"}"
] | // GetManifestList returns a list of ImageManifest for the reference | [
"GetManifestList",
"returns",
"a",
"list",
"of",
"ImageManifest",
"for",
"the",
"reference"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/client.go#L177-L187 | train |
docker/cli | cli/registry/client/client.go | GetRegistryAuth | func GetRegistryAuth(ctx context.Context, resolver AuthConfigResolver, imageName string) (*types.AuthConfig, error) {
distributionRef, err := reference.ParseNormalizedNamed(imageName)
if err != nil {
return nil, fmt.Errorf("Failed to parse image name: %s: %s", imageName, err)
}
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, resolver, distributionRef.String())
if err != nil {
return nil, fmt.Errorf("Failed to get imgRefAndAuth: %s", err)
}
return imgRefAndAuth.AuthConfig(), nil
} | go | func GetRegistryAuth(ctx context.Context, resolver AuthConfigResolver, imageName string) (*types.AuthConfig, error) {
distributionRef, err := reference.ParseNormalizedNamed(imageName)
if err != nil {
return nil, fmt.Errorf("Failed to parse image name: %s: %s", imageName, err)
}
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, resolver, distributionRef.String())
if err != nil {
return nil, fmt.Errorf("Failed to get imgRefAndAuth: %s", err)
}
return imgRefAndAuth.AuthConfig(), nil
} | [
"func",
"GetRegistryAuth",
"(",
"ctx",
"context",
".",
"Context",
",",
"resolver",
"AuthConfigResolver",
",",
"imageName",
"string",
")",
"(",
"*",
"types",
".",
"AuthConfig",
",",
"error",
")",
"{",
"distributionRef",
",",
"err",
":=",
"reference",
".",
"ParseNormalizedNamed",
"(",
"imageName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"imageName",
",",
"err",
")",
"\n",
"}",
"\n",
"imgRefAndAuth",
",",
"err",
":=",
"trust",
".",
"GetImageReferencesAndAuth",
"(",
"ctx",
",",
"nil",
",",
"resolver",
",",
"distributionRef",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"return",
"imgRefAndAuth",
".",
"AuthConfig",
"(",
")",
",",
"nil",
"\n",
"}"
] | // GetRegistryAuth returns the auth config given an input image | [
"GetRegistryAuth",
"returns",
"the",
"auth",
"config",
"given",
"an",
"input",
"image"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/registry/client/client.go#L201-L211 | train |
docker/cli | cli/command/container/opts.go | parseSecurityOpts | func parseSecurityOpts(securityOpts []string) ([]string, error) {
for key, opt := range securityOpts {
con := strings.SplitN(opt, "=", 2)
if len(con) == 1 && con[0] != "no-new-privileges" {
if strings.Contains(opt, ":") {
con = strings.SplitN(opt, ":", 2)
} else {
return securityOpts, errors.Errorf("Invalid --security-opt: %q", opt)
}
}
if con[0] == "seccomp" && con[1] != "unconfined" {
f, err := ioutil.ReadFile(con[1])
if err != nil {
return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
}
b := bytes.NewBuffer(nil)
if err := json.Compact(b, f); err != nil {
return securityOpts, errors.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err)
}
securityOpts[key] = fmt.Sprintf("seccomp=%s", b.Bytes())
}
}
return securityOpts, nil
} | go | func parseSecurityOpts(securityOpts []string) ([]string, error) {
for key, opt := range securityOpts {
con := strings.SplitN(opt, "=", 2)
if len(con) == 1 && con[0] != "no-new-privileges" {
if strings.Contains(opt, ":") {
con = strings.SplitN(opt, ":", 2)
} else {
return securityOpts, errors.Errorf("Invalid --security-opt: %q", opt)
}
}
if con[0] == "seccomp" && con[1] != "unconfined" {
f, err := ioutil.ReadFile(con[1])
if err != nil {
return securityOpts, errors.Errorf("opening seccomp profile (%s) failed: %v", con[1], err)
}
b := bytes.NewBuffer(nil)
if err := json.Compact(b, f); err != nil {
return securityOpts, errors.Errorf("compacting json for seccomp profile (%s) failed: %v", con[1], err)
}
securityOpts[key] = fmt.Sprintf("seccomp=%s", b.Bytes())
}
}
return securityOpts, nil
} | [
"func",
"parseSecurityOpts",
"(",
"securityOpts",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"string",
",",
"error",
")",
"{",
"for",
"key",
",",
"opt",
":=",
"range",
"securityOpts",
"{",
"con",
":=",
"strings",
".",
"SplitN",
"(",
"opt",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"if",
"len",
"(",
"con",
")",
"==",
"1",
"&&",
"con",
"[",
"0",
"]",
"!=",
"\"",
"\"",
"{",
"if",
"strings",
".",
"Contains",
"(",
"opt",
",",
"\"",
"\"",
")",
"{",
"con",
"=",
"strings",
".",
"SplitN",
"(",
"opt",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"}",
"else",
"{",
"return",
"securityOpts",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"opt",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"con",
"[",
"0",
"]",
"==",
"\"",
"\"",
"&&",
"con",
"[",
"1",
"]",
"!=",
"\"",
"\"",
"{",
"f",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"con",
"[",
"1",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"securityOpts",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"con",
"[",
"1",
"]",
",",
"err",
")",
"\n",
"}",
"\n",
"b",
":=",
"bytes",
".",
"NewBuffer",
"(",
"nil",
")",
"\n",
"if",
"err",
":=",
"json",
".",
"Compact",
"(",
"b",
",",
"f",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"securityOpts",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"con",
"[",
"1",
"]",
",",
"err",
")",
"\n",
"}",
"\n",
"securityOpts",
"[",
"key",
"]",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"b",
".",
"Bytes",
"(",
")",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"securityOpts",
",",
"nil",
"\n",
"}"
] | // takes a local seccomp daemon, reads the file contents for sending to the daemon | [
"takes",
"a",
"local",
"seccomp",
"daemon",
"reads",
"the",
"file",
"contents",
"for",
"sending",
"to",
"the",
"daemon"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/opts.go#L806-L830 | train |
docker/cli | cli/command/container/opts.go | parseSystemPaths | func parseSystemPaths(securityOpts []string) (filtered, maskedPaths, readonlyPaths []string) {
filtered = securityOpts[:0]
for _, opt := range securityOpts {
if opt == "systempaths=unconfined" {
maskedPaths = []string{}
readonlyPaths = []string{}
} else {
filtered = append(filtered, opt)
}
}
return filtered, maskedPaths, readonlyPaths
} | go | func parseSystemPaths(securityOpts []string) (filtered, maskedPaths, readonlyPaths []string) {
filtered = securityOpts[:0]
for _, opt := range securityOpts {
if opt == "systempaths=unconfined" {
maskedPaths = []string{}
readonlyPaths = []string{}
} else {
filtered = append(filtered, opt)
}
}
return filtered, maskedPaths, readonlyPaths
} | [
"func",
"parseSystemPaths",
"(",
"securityOpts",
"[",
"]",
"string",
")",
"(",
"filtered",
",",
"maskedPaths",
",",
"readonlyPaths",
"[",
"]",
"string",
")",
"{",
"filtered",
"=",
"securityOpts",
"[",
":",
"0",
"]",
"\n",
"for",
"_",
",",
"opt",
":=",
"range",
"securityOpts",
"{",
"if",
"opt",
"==",
"\"",
"\"",
"{",
"maskedPaths",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"readonlyPaths",
"=",
"[",
"]",
"string",
"{",
"}",
"\n",
"}",
"else",
"{",
"filtered",
"=",
"append",
"(",
"filtered",
",",
"opt",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"filtered",
",",
"maskedPaths",
",",
"readonlyPaths",
"\n",
"}"
] | // parseSystemPaths checks if `systempaths=unconfined` security option is set,
// and returns the `MaskedPaths` and `ReadonlyPaths` accordingly. An updated
// list of security options is returned with this option removed, because the
// `unconfined` option is handled client-side, and should not be sent to the
// daemon. | [
"parseSystemPaths",
"checks",
"if",
"systempaths",
"=",
"unconfined",
"security",
"option",
"is",
"set",
"and",
"returns",
"the",
"MaskedPaths",
"and",
"ReadonlyPaths",
"accordingly",
".",
"An",
"updated",
"list",
"of",
"security",
"options",
"is",
"returned",
"with",
"this",
"option",
"removed",
"because",
"the",
"unconfined",
"option",
"is",
"handled",
"client",
"-",
"side",
"and",
"should",
"not",
"be",
"sent",
"to",
"the",
"daemon",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/opts.go#L837-L849 | train |
docker/cli | cli/command/container/opts.go | parseStorageOpts | func parseStorageOpts(storageOpts []string) (map[string]string, error) {
m := make(map[string]string)
for _, option := range storageOpts {
if strings.Contains(option, "=") {
opt := strings.SplitN(option, "=", 2)
m[opt[0]] = opt[1]
} else {
return nil, errors.Errorf("invalid storage option")
}
}
return m, nil
} | go | func parseStorageOpts(storageOpts []string) (map[string]string, error) {
m := make(map[string]string)
for _, option := range storageOpts {
if strings.Contains(option, "=") {
opt := strings.SplitN(option, "=", 2)
m[opt[0]] = opt[1]
} else {
return nil, errors.Errorf("invalid storage option")
}
}
return m, nil
} | [
"func",
"parseStorageOpts",
"(",
"storageOpts",
"[",
"]",
"string",
")",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"error",
")",
"{",
"m",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
")",
"\n",
"for",
"_",
",",
"option",
":=",
"range",
"storageOpts",
"{",
"if",
"strings",
".",
"Contains",
"(",
"option",
",",
"\"",
"\"",
")",
"{",
"opt",
":=",
"strings",
".",
"SplitN",
"(",
"option",
",",
"\"",
"\"",
",",
"2",
")",
"\n",
"m",
"[",
"opt",
"[",
"0",
"]",
"]",
"=",
"opt",
"[",
"1",
"]",
"\n",
"}",
"else",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"m",
",",
"nil",
"\n",
"}"
] | // parses storage options per container into a map | [
"parses",
"storage",
"options",
"per",
"container",
"into",
"a",
"map"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/opts.go#L852-L863 | train |
docker/cli | cli/command/container/opts.go | parseDevice | func parseDevice(device, serverOS string) (container.DeviceMapping, error) {
switch serverOS {
case "linux":
return parseLinuxDevice(device)
case "windows":
return parseWindowsDevice(device)
}
return container.DeviceMapping{}, errors.Errorf("unknown server OS: %s", serverOS)
} | go | func parseDevice(device, serverOS string) (container.DeviceMapping, error) {
switch serverOS {
case "linux":
return parseLinuxDevice(device)
case "windows":
return parseWindowsDevice(device)
}
return container.DeviceMapping{}, errors.Errorf("unknown server OS: %s", serverOS)
} | [
"func",
"parseDevice",
"(",
"device",
",",
"serverOS",
"string",
")",
"(",
"container",
".",
"DeviceMapping",
",",
"error",
")",
"{",
"switch",
"serverOS",
"{",
"case",
"\"",
"\"",
":",
"return",
"parseLinuxDevice",
"(",
"device",
")",
"\n",
"case",
"\"",
"\"",
":",
"return",
"parseWindowsDevice",
"(",
"device",
")",
"\n",
"}",
"\n",
"return",
"container",
".",
"DeviceMapping",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"serverOS",
")",
"\n",
"}"
] | // parseDevice parses a device mapping string to a container.DeviceMapping struct | [
"parseDevice",
"parses",
"a",
"device",
"mapping",
"string",
"to",
"a",
"container",
".",
"DeviceMapping",
"struct"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/opts.go#L866-L874 | train |
docker/cli | cli/command/container/opts.go | parseLinuxDevice | func parseLinuxDevice(device string) (container.DeviceMapping, error) {
src := ""
dst := ""
permissions := "rwm"
arr := strings.Split(device, ":")
switch len(arr) {
case 3:
permissions = arr[2]
fallthrough
case 2:
if validDeviceMode(arr[1]) {
permissions = arr[1]
} else {
dst = arr[1]
}
fallthrough
case 1:
src = arr[0]
default:
return container.DeviceMapping{}, errors.Errorf("invalid device specification: %s", device)
}
if dst == "" {
dst = src
}
deviceMapping := container.DeviceMapping{
PathOnHost: src,
PathInContainer: dst,
CgroupPermissions: permissions,
}
return deviceMapping, nil
} | go | func parseLinuxDevice(device string) (container.DeviceMapping, error) {
src := ""
dst := ""
permissions := "rwm"
arr := strings.Split(device, ":")
switch len(arr) {
case 3:
permissions = arr[2]
fallthrough
case 2:
if validDeviceMode(arr[1]) {
permissions = arr[1]
} else {
dst = arr[1]
}
fallthrough
case 1:
src = arr[0]
default:
return container.DeviceMapping{}, errors.Errorf("invalid device specification: %s", device)
}
if dst == "" {
dst = src
}
deviceMapping := container.DeviceMapping{
PathOnHost: src,
PathInContainer: dst,
CgroupPermissions: permissions,
}
return deviceMapping, nil
} | [
"func",
"parseLinuxDevice",
"(",
"device",
"string",
")",
"(",
"container",
".",
"DeviceMapping",
",",
"error",
")",
"{",
"src",
":=",
"\"",
"\"",
"\n",
"dst",
":=",
"\"",
"\"",
"\n",
"permissions",
":=",
"\"",
"\"",
"\n",
"arr",
":=",
"strings",
".",
"Split",
"(",
"device",
",",
"\"",
"\"",
")",
"\n",
"switch",
"len",
"(",
"arr",
")",
"{",
"case",
"3",
":",
"permissions",
"=",
"arr",
"[",
"2",
"]",
"\n",
"fallthrough",
"\n",
"case",
"2",
":",
"if",
"validDeviceMode",
"(",
"arr",
"[",
"1",
"]",
")",
"{",
"permissions",
"=",
"arr",
"[",
"1",
"]",
"\n",
"}",
"else",
"{",
"dst",
"=",
"arr",
"[",
"1",
"]",
"\n",
"}",
"\n",
"fallthrough",
"\n",
"case",
"1",
":",
"src",
"=",
"arr",
"[",
"0",
"]",
"\n",
"default",
":",
"return",
"container",
".",
"DeviceMapping",
"{",
"}",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"device",
")",
"\n",
"}",
"\n\n",
"if",
"dst",
"==",
"\"",
"\"",
"{",
"dst",
"=",
"src",
"\n",
"}",
"\n\n",
"deviceMapping",
":=",
"container",
".",
"DeviceMapping",
"{",
"PathOnHost",
":",
"src",
",",
"PathInContainer",
":",
"dst",
",",
"CgroupPermissions",
":",
"permissions",
",",
"}",
"\n",
"return",
"deviceMapping",
",",
"nil",
"\n",
"}"
] | // parseLinuxDevice parses a device mapping string to a container.DeviceMapping struct
// knowing that the target is a Linux daemon | [
"parseLinuxDevice",
"parses",
"a",
"device",
"mapping",
"string",
"to",
"a",
"container",
".",
"DeviceMapping",
"struct",
"knowing",
"that",
"the",
"target",
"is",
"a",
"Linux",
"daemon"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/opts.go#L878-L910 | train |
docker/cli | cli/command/container/opts.go | parseWindowsDevice | func parseWindowsDevice(device string) (container.DeviceMapping, error) {
return container.DeviceMapping{PathOnHost: device}, nil
} | go | func parseWindowsDevice(device string) (container.DeviceMapping, error) {
return container.DeviceMapping{PathOnHost: device}, nil
} | [
"func",
"parseWindowsDevice",
"(",
"device",
"string",
")",
"(",
"container",
".",
"DeviceMapping",
",",
"error",
")",
"{",
"return",
"container",
".",
"DeviceMapping",
"{",
"PathOnHost",
":",
"device",
"}",
",",
"nil",
"\n",
"}"
] | // parseWindowsDevice parses a device mapping string to a container.DeviceMapping struct
// knowing that the target is a Windows daemon | [
"parseWindowsDevice",
"parses",
"a",
"device",
"mapping",
"string",
"to",
"a",
"container",
".",
"DeviceMapping",
"struct",
"knowing",
"that",
"the",
"target",
"is",
"a",
"Windows",
"daemon"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/opts.go#L914-L916 | train |
docker/cli | cli/command/container/opts.go | validateDevice | func validateDevice(val string, serverOS string) (string, error) {
switch serverOS {
case "linux":
return validateLinuxPath(val, validDeviceMode)
case "windows":
// Windows does validation entirely server-side
return val, nil
}
return "", errors.Errorf("unknown server OS: %s", serverOS)
} | go | func validateDevice(val string, serverOS string) (string, error) {
switch serverOS {
case "linux":
return validateLinuxPath(val, validDeviceMode)
case "windows":
// Windows does validation entirely server-side
return val, nil
}
return "", errors.Errorf("unknown server OS: %s", serverOS)
} | [
"func",
"validateDevice",
"(",
"val",
"string",
",",
"serverOS",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"switch",
"serverOS",
"{",
"case",
"\"",
"\"",
":",
"return",
"validateLinuxPath",
"(",
"val",
",",
"validDeviceMode",
")",
"\n",
"case",
"\"",
"\"",
":",
"// Windows does validation entirely server-side",
"return",
"val",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"serverOS",
")",
"\n",
"}"
] | // validateDevice validates a path for devices | [
"validateDevice",
"validates",
"a",
"path",
"for",
"devices"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/opts.go#L950-L959 | train |
docker/cli | cli/command/container/opts.go | validateAttach | func validateAttach(val string) (string, error) {
s := strings.ToLower(val)
for _, str := range []string{"stdin", "stdout", "stderr"} {
if s == str {
return s, nil
}
}
return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR")
} | go | func validateAttach(val string) (string, error) {
s := strings.ToLower(val)
for _, str := range []string{"stdin", "stdout", "stderr"} {
if s == str {
return s, nil
}
}
return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR")
} | [
"func",
"validateAttach",
"(",
"val",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"s",
":=",
"strings",
".",
"ToLower",
"(",
"val",
")",
"\n",
"for",
"_",
",",
"str",
":=",
"range",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
"}",
"{",
"if",
"s",
"==",
"str",
"{",
"return",
"s",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"val",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] | // validateAttach validates that the specified string is a valid attach option. | [
"validateAttach",
"validates",
"that",
"the",
"specified",
"string",
"is",
"a",
"valid",
"attach",
"option",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/opts.go#L1007-L1015 | train |
docker/cli | cli/command/container/run.go | NewRunCommand | func NewRunCommand(dockerCli command.Cli) *cobra.Command {
var opts runOptions
var copts *containerOptions
cmd := &cobra.Command{
Use: "run [OPTIONS] IMAGE [COMMAND] [ARG...]",
Short: "Run a command in a new container",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
copts.Image = args[0]
if len(args) > 1 {
copts.Args = args[1:]
}
return runRun(dockerCli, cmd.Flags(), &opts, copts)
},
}
flags := cmd.Flags()
flags.SetInterspersed(false)
// These are flags not stored in Config/HostConfig
flags.BoolVarP(&opts.detach, "detach", "d", false, "Run container in background and print container ID")
flags.BoolVar(&opts.sigProxy, "sig-proxy", true, "Proxy received signals to the process")
flags.StringVar(&opts.name, "name", "", "Assign a name to the container")
flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container")
// Add an explicit help that doesn't have a `-h` to prevent the conflict
// with hostname
flags.Bool("help", false, "Print usage")
command.AddPlatformFlag(flags, &opts.platform)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
copts = addFlags(flags)
return cmd
} | go | func NewRunCommand(dockerCli command.Cli) *cobra.Command {
var opts runOptions
var copts *containerOptions
cmd := &cobra.Command{
Use: "run [OPTIONS] IMAGE [COMMAND] [ARG...]",
Short: "Run a command in a new container",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
copts.Image = args[0]
if len(args) > 1 {
copts.Args = args[1:]
}
return runRun(dockerCli, cmd.Flags(), &opts, copts)
},
}
flags := cmd.Flags()
flags.SetInterspersed(false)
// These are flags not stored in Config/HostConfig
flags.BoolVarP(&opts.detach, "detach", "d", false, "Run container in background and print container ID")
flags.BoolVar(&opts.sigProxy, "sig-proxy", true, "Proxy received signals to the process")
flags.StringVar(&opts.name, "name", "", "Assign a name to the container")
flags.StringVar(&opts.detachKeys, "detach-keys", "", "Override the key sequence for detaching a container")
// Add an explicit help that doesn't have a `-h` to prevent the conflict
// with hostname
flags.Bool("help", false, "Print usage")
command.AddPlatformFlag(flags, &opts.platform)
command.AddTrustVerificationFlags(flags, &opts.untrusted, dockerCli.ContentTrustEnabled())
copts = addFlags(flags)
return cmd
} | [
"func",
"NewRunCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"runOptions",
"\n",
"var",
"copts",
"*",
"containerOptions",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"RequiresMinArgs",
"(",
"1",
")",
",",
"RunE",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"copts",
".",
"Image",
"=",
"args",
"[",
"0",
"]",
"\n",
"if",
"len",
"(",
"args",
")",
">",
"1",
"{",
"copts",
".",
"Args",
"=",
"args",
"[",
"1",
":",
"]",
"\n",
"}",
"\n",
"return",
"runRun",
"(",
"dockerCli",
",",
"cmd",
".",
"Flags",
"(",
")",
",",
"&",
"opts",
",",
"copts",
")",
"\n",
"}",
",",
"}",
"\n\n",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n",
"flags",
".",
"SetInterspersed",
"(",
"false",
")",
"\n\n",
"// These are flags not stored in Config/HostConfig",
"flags",
".",
"BoolVarP",
"(",
"&",
"opts",
".",
"detach",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"false",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"BoolVar",
"(",
"&",
"opts",
".",
"sigProxy",
",",
"\"",
"\"",
",",
"true",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"StringVar",
"(",
"&",
"opts",
".",
"name",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"StringVar",
"(",
"&",
"opts",
".",
"detachKeys",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"// Add an explicit help that doesn't have a `-h` to prevent the conflict",
"// with hostname",
"flags",
".",
"Bool",
"(",
"\"",
"\"",
",",
"false",
",",
"\"",
"\"",
")",
"\n\n",
"command",
".",
"AddPlatformFlag",
"(",
"flags",
",",
"&",
"opts",
".",
"platform",
")",
"\n",
"command",
".",
"AddTrustVerificationFlags",
"(",
"flags",
",",
"&",
"opts",
".",
"untrusted",
",",
"dockerCli",
".",
"ContentTrustEnabled",
"(",
")",
")",
"\n",
"copts",
"=",
"addFlags",
"(",
"flags",
")",
"\n",
"return",
"cmd",
"\n",
"}"
] | // NewRunCommand create a new `docker run` command | [
"NewRunCommand",
"create",
"a",
"new",
"docker",
"run",
"command"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/run.go#L34-L68 | train |
docker/cli | cli/command/container/run.go | reportError | func reportError(stderr io.Writer, name string, str string, withHelp bool) {
str = strings.TrimSuffix(str, ".") + "."
if withHelp {
str += "\nSee '" + os.Args[0] + " " + name + " --help'."
}
fmt.Fprintf(stderr, "%s: %s\n", os.Args[0], str)
} | go | func reportError(stderr io.Writer, name string, str string, withHelp bool) {
str = strings.TrimSuffix(str, ".") + "."
if withHelp {
str += "\nSee '" + os.Args[0] + " " + name + " --help'."
}
fmt.Fprintf(stderr, "%s: %s\n", os.Args[0], str)
} | [
"func",
"reportError",
"(",
"stderr",
"io",
".",
"Writer",
",",
"name",
"string",
",",
"str",
"string",
",",
"withHelp",
"bool",
")",
"{",
"str",
"=",
"strings",
".",
"TrimSuffix",
"(",
"str",
",",
"\"",
"\"",
")",
"+",
"\"",
"\"",
"\n",
"if",
"withHelp",
"{",
"str",
"+=",
"\"",
"\\n",
"\"",
"+",
"os",
".",
"Args",
"[",
"0",
"]",
"+",
"\"",
"\"",
"+",
"name",
"+",
"\"",
"\"",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"stderr",
",",
"\"",
"\\n",
"\"",
",",
"os",
".",
"Args",
"[",
"0",
"]",
",",
"str",
")",
"\n",
"}"
] | // reportError is a utility method that prints a user-friendly message
// containing the error that occurred during parsing and a suggestion to get help | [
"reportError",
"is",
"a",
"utility",
"method",
"that",
"prints",
"a",
"user",
"-",
"friendly",
"message",
"containing",
"the",
"error",
"that",
"occurred",
"during",
"parsing",
"and",
"a",
"suggestion",
"to",
"get",
"help"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/run.go#L289-L295 | train |
docker/cli | cli/command/image/build.go | validateTag | func validateTag(rawRepo string) (string, error) {
_, err := reference.ParseNormalizedNamed(rawRepo)
if err != nil {
return "", err
}
return rawRepo, nil
} | go | func validateTag(rawRepo string) (string, error) {
_, err := reference.ParseNormalizedNamed(rawRepo)
if err != nil {
return "", err
}
return rawRepo, nil
} | [
"func",
"validateTag",
"(",
"rawRepo",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"_",
",",
"err",
":=",
"reference",
".",
"ParseNormalizedNamed",
"(",
"rawRepo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"rawRepo",
",",
"nil",
"\n",
"}"
] | // validateTag checks if the given image name can be resolved. | [
"validateTag",
"checks",
"if",
"the",
"given",
"image",
"name",
"can",
"be",
"resolved",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build.go#L509-L516 | train |
docker/cli | cli/command/image/build.go | replaceDockerfileForContentTrust | func replaceDockerfileForContentTrust(ctx context.Context, inputTarStream io.ReadCloser, dockerfileName string, translator translatorFunc, resolvedTags *[]*resolvedTag) io.ReadCloser {
pipeReader, pipeWriter := io.Pipe()
go func() {
tarReader := tar.NewReader(inputTarStream)
tarWriter := tar.NewWriter(pipeWriter)
defer inputTarStream.Close()
for {
hdr, err := tarReader.Next()
if err == io.EOF {
// Signals end of archive.
tarWriter.Close()
pipeWriter.Close()
return
}
if err != nil {
pipeWriter.CloseWithError(err)
return
}
content := io.Reader(tarReader)
if hdr.Name == dockerfileName {
// This entry is the Dockerfile. Since the tar archive was
// generated from a directory on the local filesystem, the
// Dockerfile will only appear once in the archive.
var newDockerfile []byte
newDockerfile, *resolvedTags, err = rewriteDockerfileFromForContentTrust(ctx, content, translator)
if err != nil {
pipeWriter.CloseWithError(err)
return
}
hdr.Size = int64(len(newDockerfile))
content = bytes.NewBuffer(newDockerfile)
}
if err := tarWriter.WriteHeader(hdr); err != nil {
pipeWriter.CloseWithError(err)
return
}
if _, err := io.Copy(tarWriter, content); err != nil {
pipeWriter.CloseWithError(err)
return
}
}
}()
return pipeReader
} | go | func replaceDockerfileForContentTrust(ctx context.Context, inputTarStream io.ReadCloser, dockerfileName string, translator translatorFunc, resolvedTags *[]*resolvedTag) io.ReadCloser {
pipeReader, pipeWriter := io.Pipe()
go func() {
tarReader := tar.NewReader(inputTarStream)
tarWriter := tar.NewWriter(pipeWriter)
defer inputTarStream.Close()
for {
hdr, err := tarReader.Next()
if err == io.EOF {
// Signals end of archive.
tarWriter.Close()
pipeWriter.Close()
return
}
if err != nil {
pipeWriter.CloseWithError(err)
return
}
content := io.Reader(tarReader)
if hdr.Name == dockerfileName {
// This entry is the Dockerfile. Since the tar archive was
// generated from a directory on the local filesystem, the
// Dockerfile will only appear once in the archive.
var newDockerfile []byte
newDockerfile, *resolvedTags, err = rewriteDockerfileFromForContentTrust(ctx, content, translator)
if err != nil {
pipeWriter.CloseWithError(err)
return
}
hdr.Size = int64(len(newDockerfile))
content = bytes.NewBuffer(newDockerfile)
}
if err := tarWriter.WriteHeader(hdr); err != nil {
pipeWriter.CloseWithError(err)
return
}
if _, err := io.Copy(tarWriter, content); err != nil {
pipeWriter.CloseWithError(err)
return
}
}
}()
return pipeReader
} | [
"func",
"replaceDockerfileForContentTrust",
"(",
"ctx",
"context",
".",
"Context",
",",
"inputTarStream",
"io",
".",
"ReadCloser",
",",
"dockerfileName",
"string",
",",
"translator",
"translatorFunc",
",",
"resolvedTags",
"*",
"[",
"]",
"*",
"resolvedTag",
")",
"io",
".",
"ReadCloser",
"{",
"pipeReader",
",",
"pipeWriter",
":=",
"io",
".",
"Pipe",
"(",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"tarReader",
":=",
"tar",
".",
"NewReader",
"(",
"inputTarStream",
")",
"\n",
"tarWriter",
":=",
"tar",
".",
"NewWriter",
"(",
"pipeWriter",
")",
"\n\n",
"defer",
"inputTarStream",
".",
"Close",
"(",
")",
"\n\n",
"for",
"{",
"hdr",
",",
"err",
":=",
"tarReader",
".",
"Next",
"(",
")",
"\n",
"if",
"err",
"==",
"io",
".",
"EOF",
"{",
"// Signals end of archive.",
"tarWriter",
".",
"Close",
"(",
")",
"\n",
"pipeWriter",
".",
"Close",
"(",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"pipeWriter",
".",
"CloseWithError",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"content",
":=",
"io",
".",
"Reader",
"(",
"tarReader",
")",
"\n",
"if",
"hdr",
".",
"Name",
"==",
"dockerfileName",
"{",
"// This entry is the Dockerfile. Since the tar archive was",
"// generated from a directory on the local filesystem, the",
"// Dockerfile will only appear once in the archive.",
"var",
"newDockerfile",
"[",
"]",
"byte",
"\n",
"newDockerfile",
",",
"*",
"resolvedTags",
",",
"err",
"=",
"rewriteDockerfileFromForContentTrust",
"(",
"ctx",
",",
"content",
",",
"translator",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"pipeWriter",
".",
"CloseWithError",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"hdr",
".",
"Size",
"=",
"int64",
"(",
"len",
"(",
"newDockerfile",
")",
")",
"\n",
"content",
"=",
"bytes",
".",
"NewBuffer",
"(",
"newDockerfile",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"tarWriter",
".",
"WriteHeader",
"(",
"hdr",
")",
";",
"err",
"!=",
"nil",
"{",
"pipeWriter",
".",
"CloseWithError",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"Copy",
"(",
"tarWriter",
",",
"content",
")",
";",
"err",
"!=",
"nil",
"{",
"pipeWriter",
".",
"CloseWithError",
"(",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"pipeReader",
"\n",
"}"
] | // replaceDockerfileForContentTrust wraps the given input tar archive stream and
// uses the translator to replace the Dockerfile which uses a trusted reference.
// Returns a new tar archive stream with the replaced Dockerfile. | [
"replaceDockerfileForContentTrust",
"wraps",
"the",
"given",
"input",
"tar",
"archive",
"stream",
"and",
"uses",
"the",
"translator",
"to",
"replace",
"the",
"Dockerfile",
"which",
"uses",
"a",
"trusted",
"reference",
".",
"Returns",
"a",
"new",
"tar",
"archive",
"stream",
"with",
"the",
"replaced",
"Dockerfile",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/build.go#L575-L624 | train |
docker/cli | cli/command/stack/formatter/formatter.go | StackWrite | func StackWrite(ctx formatter.Context, stacks []*Stack) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, stack := range stacks {
if err := format(&stackContext{s: stack}); err != nil {
return err
}
}
return nil
}
return ctx.Write(newStackContext(), render)
} | go | func StackWrite(ctx formatter.Context, stacks []*Stack) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, stack := range stacks {
if err := format(&stackContext{s: stack}); err != nil {
return err
}
}
return nil
}
return ctx.Write(newStackContext(), render)
} | [
"func",
"StackWrite",
"(",
"ctx",
"formatter",
".",
"Context",
",",
"stacks",
"[",
"]",
"*",
"Stack",
")",
"error",
"{",
"render",
":=",
"func",
"(",
"format",
"func",
"(",
"subContext",
"formatter",
".",
"SubContext",
")",
"error",
")",
"error",
"{",
"for",
"_",
",",
"stack",
":=",
"range",
"stacks",
"{",
"if",
"err",
":=",
"format",
"(",
"&",
"stackContext",
"{",
"s",
":",
"stack",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"Write",
"(",
"newStackContext",
"(",
")",
",",
"render",
")",
"\n",
"}"
] | // StackWrite writes formatted stacks using the Context | [
"StackWrite",
"writes",
"formatted",
"stacks",
"using",
"the",
"Context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/formatter/formatter.go#L42-L52 | train |
docker/cli | docs/yaml/yaml.go | GenYamlTreeCustom | func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string) error {
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
continue
}
if err := GenYamlTreeCustom(c, dir, filePrepender); err != nil {
return err
}
}
basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".yaml"
filename := filepath.Join(dir, basename)
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
if _, err := io.WriteString(f, filePrepender(filename)); err != nil {
return err
}
return GenYamlCustom(cmd, f)
} | go | func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string) error {
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
continue
}
if err := GenYamlTreeCustom(c, dir, filePrepender); err != nil {
return err
}
}
basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".yaml"
filename := filepath.Join(dir, basename)
f, err := os.Create(filename)
if err != nil {
return err
}
defer f.Close()
if _, err := io.WriteString(f, filePrepender(filename)); err != nil {
return err
}
return GenYamlCustom(cmd, f)
} | [
"func",
"GenYamlTreeCustom",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"dir",
"string",
",",
"filePrepender",
"func",
"(",
"string",
")",
"string",
")",
"error",
"{",
"for",
"_",
",",
"c",
":=",
"range",
"cmd",
".",
"Commands",
"(",
")",
"{",
"if",
"!",
"c",
".",
"IsAvailableCommand",
"(",
")",
"||",
"c",
".",
"IsAdditionalHelpTopicCommand",
"(",
")",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"GenYamlTreeCustom",
"(",
"c",
",",
"dir",
",",
"filePrepender",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"basename",
":=",
"strings",
".",
"Replace",
"(",
"cmd",
".",
"CommandPath",
"(",
")",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"+",
"\"",
"\"",
"\n",
"filename",
":=",
"filepath",
".",
"Join",
"(",
"dir",
",",
"basename",
")",
"\n",
"f",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"if",
"_",
",",
"err",
":=",
"io",
".",
"WriteString",
"(",
"f",
",",
"filePrepender",
"(",
"filename",
")",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"GenYamlCustom",
"(",
"cmd",
",",
"f",
")",
"\n",
"}"
] | // GenYamlTreeCustom creates yaml structured ref files | [
"GenYamlTreeCustom",
"creates",
"yaml",
"structured",
"ref",
"files"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/docs/yaml/yaml.go#L62-L84 | train |
docker/cli | cli/compose/types/types.go | ConvertDurationPtr | func ConvertDurationPtr(d *Duration) *time.Duration {
if d == nil {
return nil
}
res := time.Duration(*d)
return &res
} | go | func ConvertDurationPtr(d *Duration) *time.Duration {
if d == nil {
return nil
}
res := time.Duration(*d)
return &res
} | [
"func",
"ConvertDurationPtr",
"(",
"d",
"*",
"Duration",
")",
"*",
"time",
".",
"Duration",
"{",
"if",
"d",
"==",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"res",
":=",
"time",
".",
"Duration",
"(",
"*",
"d",
")",
"\n",
"return",
"&",
"res",
"\n",
"}"
] | // ConvertDurationPtr converts a typedefined Duration pointer to a time.Duration pointer with the same value. | [
"ConvertDurationPtr",
"converts",
"a",
"typedefined",
"Duration",
"pointer",
"to",
"a",
"time",
".",
"Duration",
"pointer",
"with",
"the",
"same",
"value",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L73-L79 | train |
docker/cli | cli/compose/types/types.go | LookupEnv | func (cd ConfigDetails) LookupEnv(key string) (string, bool) {
v, ok := cd.Environment[key]
return v, ok
} | go | func (cd ConfigDetails) LookupEnv(key string) (string, bool) {
v, ok := cd.Environment[key]
return v, ok
} | [
"func",
"(",
"cd",
"ConfigDetails",
")",
"LookupEnv",
"(",
"key",
"string",
")",
"(",
"string",
",",
"bool",
")",
"{",
"v",
",",
"ok",
":=",
"cd",
".",
"Environment",
"[",
"key",
"]",
"\n",
"return",
"v",
",",
"ok",
"\n",
"}"
] | // LookupEnv provides a lookup function for environment variables | [
"LookupEnv",
"provides",
"a",
"lookup",
"function",
"for",
"environment",
"variables"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L92-L95 | train |
docker/cli | cli/compose/types/types.go | MarshalJSON | func (c Config) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"version": c.Version,
"services": c.Services,
}
if len(c.Networks) > 0 {
m["networks"] = c.Networks
}
if len(c.Volumes) > 0 {
m["volumes"] = c.Volumes
}
if len(c.Secrets) > 0 {
m["secrets"] = c.Secrets
}
if len(c.Configs) > 0 {
m["configs"] = c.Configs
}
for k, v := range c.Extras {
m[k] = v
}
return json.Marshal(m)
} | go | func (c Config) MarshalJSON() ([]byte, error) {
m := map[string]interface{}{
"version": c.Version,
"services": c.Services,
}
if len(c.Networks) > 0 {
m["networks"] = c.Networks
}
if len(c.Volumes) > 0 {
m["volumes"] = c.Volumes
}
if len(c.Secrets) > 0 {
m["secrets"] = c.Secrets
}
if len(c.Configs) > 0 {
m["configs"] = c.Configs
}
for k, v := range c.Extras {
m[k] = v
}
return json.Marshal(m)
} | [
"func",
"(",
"c",
"Config",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"m",
":=",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"{",
"\"",
"\"",
":",
"c",
".",
"Version",
",",
"\"",
"\"",
":",
"c",
".",
"Services",
",",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"Networks",
")",
">",
"0",
"{",
"m",
"[",
"\"",
"\"",
"]",
"=",
"c",
".",
"Networks",
"\n",
"}",
"\n",
"if",
"len",
"(",
"c",
".",
"Volumes",
")",
">",
"0",
"{",
"m",
"[",
"\"",
"\"",
"]",
"=",
"c",
".",
"Volumes",
"\n",
"}",
"\n",
"if",
"len",
"(",
"c",
".",
"Secrets",
")",
">",
"0",
"{",
"m",
"[",
"\"",
"\"",
"]",
"=",
"c",
".",
"Secrets",
"\n",
"}",
"\n",
"if",
"len",
"(",
"c",
".",
"Configs",
")",
">",
"0",
"{",
"m",
"[",
"\"",
"\"",
"]",
"=",
"c",
".",
"Configs",
"\n",
"}",
"\n",
"for",
"k",
",",
"v",
":=",
"range",
"c",
".",
"Extras",
"{",
"m",
"[",
"k",
"]",
"=",
"v",
"\n",
"}",
"\n",
"return",
"json",
".",
"Marshal",
"(",
"m",
")",
"\n",
"}"
] | // MarshalJSON makes Config implement json.Marshaler | [
"MarshalJSON",
"makes",
"Config",
"implement",
"json",
".",
"Marshaler"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L110-L132 | train |
docker/cli | cli/compose/types/types.go | MarshalYAML | func (s Services) MarshalYAML() (interface{}, error) {
services := map[string]ServiceConfig{}
for _, service := range s {
services[service.Name] = service
}
return services, nil
} | go | func (s Services) MarshalYAML() (interface{}, error) {
services := map[string]ServiceConfig{}
for _, service := range s {
services[service.Name] = service
}
return services, nil
} | [
"func",
"(",
"s",
"Services",
")",
"MarshalYAML",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"services",
":=",
"map",
"[",
"string",
"]",
"ServiceConfig",
"{",
"}",
"\n",
"for",
"_",
",",
"service",
":=",
"range",
"s",
"{",
"services",
"[",
"service",
".",
"Name",
"]",
"=",
"service",
"\n",
"}",
"\n",
"return",
"services",
",",
"nil",
"\n",
"}"
] | // MarshalYAML makes Services implement yaml.Marshaller | [
"MarshalYAML",
"makes",
"Services",
"implement",
"yaml",
".",
"Marshaller"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L138-L144 | train |
docker/cli | cli/compose/types/types.go | MarshalJSON | func (s Services) MarshalJSON() ([]byte, error) {
data, err := s.MarshalYAML()
if err != nil {
return nil, err
}
return json.MarshalIndent(data, "", " ")
} | go | func (s Services) MarshalJSON() ([]byte, error) {
data, err := s.MarshalYAML()
if err != nil {
return nil, err
}
return json.MarshalIndent(data, "", " ")
} | [
"func",
"(",
"s",
"Services",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"data",
",",
"err",
":=",
"s",
".",
"MarshalYAML",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"json",
".",
"MarshalIndent",
"(",
"data",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // MarshalJSON makes Services implement json.Marshaler | [
"MarshalJSON",
"makes",
"Services",
"implement",
"json",
".",
"Marshaler"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L147-L153 | train |
docker/cli | cli/compose/types/types.go | MarshalJSON | func (u UnitBytes) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%d"`, u)), nil
} | go | func (u UnitBytes) MarshalJSON() ([]byte, error) {
return []byte(fmt.Sprintf(`"%d"`, u)), nil
} | [
"func",
"(",
"u",
"UnitBytes",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"`\"%d\"`",
",",
"u",
")",
")",
",",
"nil",
"\n",
"}"
] | // MarshalJSON makes UnitBytes implement json.Marshaler | [
"MarshalJSON",
"makes",
"UnitBytes",
"implement",
"json",
".",
"Marshaler"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L338-L340 | train |
docker/cli | cli/compose/types/types.go | MarshalYAML | func (u *UlimitsConfig) MarshalYAML() (interface{}, error) {
if u.Single != 0 {
return u.Single, nil
}
return u, nil
} | go | func (u *UlimitsConfig) MarshalYAML() (interface{}, error) {
if u.Single != 0 {
return u.Single, nil
}
return u, nil
} | [
"func",
"(",
"u",
"*",
"UlimitsConfig",
")",
"MarshalYAML",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"u",
".",
"Single",
"!=",
"0",
"{",
"return",
"u",
".",
"Single",
",",
"nil",
"\n",
"}",
"\n",
"return",
"u",
",",
"nil",
"\n",
"}"
] | // MarshalYAML makes UlimitsConfig implement yaml.Marshaller | [
"MarshalYAML",
"makes",
"UlimitsConfig",
"implement",
"yaml",
".",
"Marshaller"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L427-L432 | train |
docker/cli | cli/compose/types/types.go | MarshalJSON | func (u *UlimitsConfig) MarshalJSON() ([]byte, error) {
if u.Single != 0 {
return json.Marshal(u.Single)
}
// Pass as a value to avoid re-entering this method and use the default implementation
return json.Marshal(*u)
} | go | func (u *UlimitsConfig) MarshalJSON() ([]byte, error) {
if u.Single != 0 {
return json.Marshal(u.Single)
}
// Pass as a value to avoid re-entering this method and use the default implementation
return json.Marshal(*u)
} | [
"func",
"(",
"u",
"*",
"UlimitsConfig",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"u",
".",
"Single",
"!=",
"0",
"{",
"return",
"json",
".",
"Marshal",
"(",
"u",
".",
"Single",
")",
"\n",
"}",
"\n",
"// Pass as a value to avoid re-entering this method and use the default implementation",
"return",
"json",
".",
"Marshal",
"(",
"*",
"u",
")",
"\n",
"}"
] | // MarshalJSON makes UlimitsConfig implement json.Marshaller | [
"MarshalJSON",
"makes",
"UlimitsConfig",
"implement",
"json",
".",
"Marshaller"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L435-L441 | train |
docker/cli | cli/compose/types/types.go | MarshalYAML | func (e External) MarshalYAML() (interface{}, error) {
if e.Name == "" {
return e.External, nil
}
return External{Name: e.Name}, nil
} | go | func (e External) MarshalYAML() (interface{}, error) {
if e.Name == "" {
return e.External, nil
}
return External{Name: e.Name}, nil
} | [
"func",
"(",
"e",
"External",
")",
"MarshalYAML",
"(",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"e",
".",
"Name",
"==",
"\"",
"\"",
"{",
"return",
"e",
".",
"External",
",",
"nil",
"\n",
"}",
"\n",
"return",
"External",
"{",
"Name",
":",
"e",
".",
"Name",
"}",
",",
"nil",
"\n",
"}"
] | // MarshalYAML makes External implement yaml.Marshaller | [
"MarshalYAML",
"makes",
"External",
"implement",
"yaml",
".",
"Marshaller"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L486-L491 | train |
docker/cli | cli/compose/types/types.go | MarshalJSON | func (e External) MarshalJSON() ([]byte, error) {
if e.Name == "" {
return []byte(fmt.Sprintf("%v", e.External)), nil
}
return []byte(fmt.Sprintf(`{"name": %q}`, e.Name)), nil
} | go | func (e External) MarshalJSON() ([]byte, error) {
if e.Name == "" {
return []byte(fmt.Sprintf("%v", e.External)), nil
}
return []byte(fmt.Sprintf(`{"name": %q}`, e.Name)), nil
} | [
"func",
"(",
"e",
"External",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"e",
".",
"Name",
"==",
"\"",
"\"",
"{",
"return",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"e",
".",
"External",
")",
")",
",",
"nil",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"(",
"fmt",
".",
"Sprintf",
"(",
"`{\"name\": %q}`",
",",
"e",
".",
"Name",
")",
")",
",",
"nil",
"\n",
"}"
] | // MarshalJSON makes External implement json.Marshaller | [
"MarshalJSON",
"makes",
"External",
"implement",
"json",
".",
"Marshaller"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/compose/types/types.go#L494-L499 | train |
docker/cli | cli/command/image/trust.go | TrustedPush | func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error {
responseBody, err := imagePushPrivileged(ctx, cli, authConfig, ref, requestPrivilege)
if err != nil {
return err
}
defer responseBody.Close()
return PushTrustedReference(cli, repoInfo, ref, authConfig, responseBody)
} | go | func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig types.AuthConfig, requestPrivilege types.RequestPrivilegeFunc) error {
responseBody, err := imagePushPrivileged(ctx, cli, authConfig, ref, requestPrivilege)
if err != nil {
return err
}
defer responseBody.Close()
return PushTrustedReference(cli, repoInfo, ref, authConfig, responseBody)
} | [
"func",
"TrustedPush",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"repoInfo",
"*",
"registry",
".",
"RepositoryInfo",
",",
"ref",
"reference",
".",
"Named",
",",
"authConfig",
"types",
".",
"AuthConfig",
",",
"requestPrivilege",
"types",
".",
"RequestPrivilegeFunc",
")",
"error",
"{",
"responseBody",
",",
"err",
":=",
"imagePushPrivileged",
"(",
"ctx",
",",
"cli",
",",
"authConfig",
",",
"ref",
",",
"requestPrivilege",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"defer",
"responseBody",
".",
"Close",
"(",
")",
"\n\n",
"return",
"PushTrustedReference",
"(",
"cli",
",",
"repoInfo",
",",
"ref",
",",
"authConfig",
",",
"responseBody",
")",
"\n",
"}"
] | // TrustedPush handles content trust pushing of an image | [
"TrustedPush",
"handles",
"content",
"trust",
"pushing",
"of",
"an",
"image"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/trust.go#L34-L43 | train |
docker/cli | cli/command/image/trust.go | imagePushPrivileged | func imagePushPrivileged(ctx context.Context, cli command.Cli, authConfig types.AuthConfig, ref reference.Reference, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) {
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil {
return nil, err
}
options := types.ImagePushOptions{
RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege,
}
return cli.Client().ImagePush(ctx, reference.FamiliarString(ref), options)
} | go | func imagePushPrivileged(ctx context.Context, cli command.Cli, authConfig types.AuthConfig, ref reference.Reference, requestPrivilege types.RequestPrivilegeFunc) (io.ReadCloser, error) {
encodedAuth, err := command.EncodeAuthToBase64(authConfig)
if err != nil {
return nil, err
}
options := types.ImagePushOptions{
RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege,
}
return cli.Client().ImagePush(ctx, reference.FamiliarString(ref), options)
} | [
"func",
"imagePushPrivileged",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"authConfig",
"types",
".",
"AuthConfig",
",",
"ref",
"reference",
".",
"Reference",
",",
"requestPrivilege",
"types",
".",
"RequestPrivilegeFunc",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"encodedAuth",
",",
"err",
":=",
"command",
".",
"EncodeAuthToBase64",
"(",
"authConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"options",
":=",
"types",
".",
"ImagePushOptions",
"{",
"RegistryAuth",
":",
"encodedAuth",
",",
"PrivilegeFunc",
":",
"requestPrivilege",
",",
"}",
"\n\n",
"return",
"cli",
".",
"Client",
"(",
")",
".",
"ImagePush",
"(",
"ctx",
",",
"reference",
".",
"FamiliarString",
"(",
"ref",
")",
",",
"options",
")",
"\n",
"}"
] | // imagePushPrivileged push the image | [
"imagePushPrivileged",
"push",
"the",
"image"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/trust.go#L171-L182 | train |
docker/cli | cli/command/image/trust.go | trustedPull | func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth, opts PullOptions) error {
refs, err := getTrustedPullTargets(cli, imgRefAndAuth)
if err != nil {
return err
}
ref := imgRefAndAuth.Reference()
for i, r := range refs {
displayTag := r.name
if displayTag != "" {
displayTag = ":" + displayTag
}
fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), reference.FamiliarName(ref), displayTag, r.digest)
trustedRef, err := reference.WithDigest(reference.TrimNamed(ref), r.digest)
if err != nil {
return err
}
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, AuthResolver(cli), trustedRef.String())
if err != nil {
return err
}
if err := imagePullPrivileged(ctx, cli, updatedImgRefAndAuth, PullOptions{
all: false,
platform: opts.platform,
quiet: opts.quiet,
remote: opts.remote,
}); err != nil {
return err
}
tagged, err := reference.WithTag(reference.TrimNamed(ref), r.name)
if err != nil {
return err
}
if err := TagTrusted(ctx, cli, trustedRef, tagged); err != nil {
return err
}
}
return nil
} | go | func trustedPull(ctx context.Context, cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth, opts PullOptions) error {
refs, err := getTrustedPullTargets(cli, imgRefAndAuth)
if err != nil {
return err
}
ref := imgRefAndAuth.Reference()
for i, r := range refs {
displayTag := r.name
if displayTag != "" {
displayTag = ":" + displayTag
}
fmt.Fprintf(cli.Out(), "Pull (%d of %d): %s%s@%s\n", i+1, len(refs), reference.FamiliarName(ref), displayTag, r.digest)
trustedRef, err := reference.WithDigest(reference.TrimNamed(ref), r.digest)
if err != nil {
return err
}
updatedImgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, AuthResolver(cli), trustedRef.String())
if err != nil {
return err
}
if err := imagePullPrivileged(ctx, cli, updatedImgRefAndAuth, PullOptions{
all: false,
platform: opts.platform,
quiet: opts.quiet,
remote: opts.remote,
}); err != nil {
return err
}
tagged, err := reference.WithTag(reference.TrimNamed(ref), r.name)
if err != nil {
return err
}
if err := TagTrusted(ctx, cli, trustedRef, tagged); err != nil {
return err
}
}
return nil
} | [
"func",
"trustedPull",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"imgRefAndAuth",
"trust",
".",
"ImageRefAndAuth",
",",
"opts",
"PullOptions",
")",
"error",
"{",
"refs",
",",
"err",
":=",
"getTrustedPullTargets",
"(",
"cli",
",",
"imgRefAndAuth",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ref",
":=",
"imgRefAndAuth",
".",
"Reference",
"(",
")",
"\n",
"for",
"i",
",",
"r",
":=",
"range",
"refs",
"{",
"displayTag",
":=",
"r",
".",
"name",
"\n",
"if",
"displayTag",
"!=",
"\"",
"\"",
"{",
"displayTag",
"=",
"\"",
"\"",
"+",
"displayTag",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"cli",
".",
"Out",
"(",
")",
",",
"\"",
"\\n",
"\"",
",",
"i",
"+",
"1",
",",
"len",
"(",
"refs",
")",
",",
"reference",
".",
"FamiliarName",
"(",
"ref",
")",
",",
"displayTag",
",",
"r",
".",
"digest",
")",
"\n\n",
"trustedRef",
",",
"err",
":=",
"reference",
".",
"WithDigest",
"(",
"reference",
".",
"TrimNamed",
"(",
"ref",
")",
",",
"r",
".",
"digest",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"updatedImgRefAndAuth",
",",
"err",
":=",
"trust",
".",
"GetImageReferencesAndAuth",
"(",
"ctx",
",",
"nil",
",",
"AuthResolver",
"(",
"cli",
")",
",",
"trustedRef",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"imagePullPrivileged",
"(",
"ctx",
",",
"cli",
",",
"updatedImgRefAndAuth",
",",
"PullOptions",
"{",
"all",
":",
"false",
",",
"platform",
":",
"opts",
".",
"platform",
",",
"quiet",
":",
"opts",
".",
"quiet",
",",
"remote",
":",
"opts",
".",
"remote",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"tagged",
",",
"err",
":=",
"reference",
".",
"WithTag",
"(",
"reference",
".",
"TrimNamed",
"(",
"ref",
")",
",",
"r",
".",
"name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"TagTrusted",
"(",
"ctx",
",",
"cli",
",",
"trustedRef",
",",
"tagged",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // trustedPull handles content trust pulling of an image | [
"trustedPull",
"handles",
"content",
"trust",
"pulling",
"of",
"an",
"image"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/trust.go#L185-L226 | train |
docker/cli | cli/command/image/trust.go | imagePullPrivileged | func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth, opts PullOptions) error {
ref := reference.FamiliarString(imgRefAndAuth.Reference())
encodedAuth, err := command.EncodeAuthToBase64(*imgRefAndAuth.AuthConfig())
if err != nil {
return err
}
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(cli, imgRefAndAuth.RepoInfo().Index, "pull")
options := types.ImagePullOptions{
RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege,
All: opts.all,
Platform: opts.platform,
}
responseBody, err := cli.Client().ImagePull(ctx, ref, options)
if err != nil {
return err
}
defer responseBody.Close()
out := cli.Out()
if opts.quiet {
out = streams.NewOut(ioutil.Discard)
}
return jsonmessage.DisplayJSONMessagesToStream(responseBody, out, nil)
} | go | func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth trust.ImageRefAndAuth, opts PullOptions) error {
ref := reference.FamiliarString(imgRefAndAuth.Reference())
encodedAuth, err := command.EncodeAuthToBase64(*imgRefAndAuth.AuthConfig())
if err != nil {
return err
}
requestPrivilege := command.RegistryAuthenticationPrivilegedFunc(cli, imgRefAndAuth.RepoInfo().Index, "pull")
options := types.ImagePullOptions{
RegistryAuth: encodedAuth,
PrivilegeFunc: requestPrivilege,
All: opts.all,
Platform: opts.platform,
}
responseBody, err := cli.Client().ImagePull(ctx, ref, options)
if err != nil {
return err
}
defer responseBody.Close()
out := cli.Out()
if opts.quiet {
out = streams.NewOut(ioutil.Discard)
}
return jsonmessage.DisplayJSONMessagesToStream(responseBody, out, nil)
} | [
"func",
"imagePullPrivileged",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"imgRefAndAuth",
"trust",
".",
"ImageRefAndAuth",
",",
"opts",
"PullOptions",
")",
"error",
"{",
"ref",
":=",
"reference",
".",
"FamiliarString",
"(",
"imgRefAndAuth",
".",
"Reference",
"(",
")",
")",
"\n\n",
"encodedAuth",
",",
"err",
":=",
"command",
".",
"EncodeAuthToBase64",
"(",
"*",
"imgRefAndAuth",
".",
"AuthConfig",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"requestPrivilege",
":=",
"command",
".",
"RegistryAuthenticationPrivilegedFunc",
"(",
"cli",
",",
"imgRefAndAuth",
".",
"RepoInfo",
"(",
")",
".",
"Index",
",",
"\"",
"\"",
")",
"\n",
"options",
":=",
"types",
".",
"ImagePullOptions",
"{",
"RegistryAuth",
":",
"encodedAuth",
",",
"PrivilegeFunc",
":",
"requestPrivilege",
",",
"All",
":",
"opts",
".",
"all",
",",
"Platform",
":",
"opts",
".",
"platform",
",",
"}",
"\n",
"responseBody",
",",
"err",
":=",
"cli",
".",
"Client",
"(",
")",
".",
"ImagePull",
"(",
"ctx",
",",
"ref",
",",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"responseBody",
".",
"Close",
"(",
")",
"\n\n",
"out",
":=",
"cli",
".",
"Out",
"(",
")",
"\n",
"if",
"opts",
".",
"quiet",
"{",
"out",
"=",
"streams",
".",
"NewOut",
"(",
"ioutil",
".",
"Discard",
")",
"\n",
"}",
"\n",
"return",
"jsonmessage",
".",
"DisplayJSONMessagesToStream",
"(",
"responseBody",
",",
"out",
",",
"nil",
")",
"\n",
"}"
] | // imagePullPrivileged pulls the image and displays it to the output | [
"imagePullPrivileged",
"pulls",
"the",
"image",
"and",
"displays",
"it",
"to",
"the",
"output"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/trust.go#L278-L303 | train |
docker/cli | cli/command/image/trust.go | TrustedReference | func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged, rs registry.Service) (reference.Canonical, error) {
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, rs, AuthResolver(cli), ref.String())
if err != nil {
return nil, err
}
notaryRepo, err := cli.NotaryClient(imgRefAndAuth, []string{"pull"})
if err != nil {
return nil, errors.Wrap(err, "error establishing connection to trust repository")
}
t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
if err != nil {
return nil, trust.NotaryError(imgRefAndAuth.RepoInfo().Name.Name(), err)
}
// Only list tags in the top level targets role or the releases delegation role - ignore
// all other delegation roles
if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
return nil, trust.NotaryError(imgRefAndAuth.RepoInfo().Name.Name(), client.ErrNoSuchTarget(ref.Tag()))
}
r, err := convertTarget(t.Target)
if err != nil {
return nil, err
}
return reference.WithDigest(reference.TrimNamed(ref), r.digest)
} | go | func TrustedReference(ctx context.Context, cli command.Cli, ref reference.NamedTagged, rs registry.Service) (reference.Canonical, error) {
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, rs, AuthResolver(cli), ref.String())
if err != nil {
return nil, err
}
notaryRepo, err := cli.NotaryClient(imgRefAndAuth, []string{"pull"})
if err != nil {
return nil, errors.Wrap(err, "error establishing connection to trust repository")
}
t, err := notaryRepo.GetTargetByName(ref.Tag(), trust.ReleasesRole, data.CanonicalTargetsRole)
if err != nil {
return nil, trust.NotaryError(imgRefAndAuth.RepoInfo().Name.Name(), err)
}
// Only list tags in the top level targets role or the releases delegation role - ignore
// all other delegation roles
if t.Role != trust.ReleasesRole && t.Role != data.CanonicalTargetsRole {
return nil, trust.NotaryError(imgRefAndAuth.RepoInfo().Name.Name(), client.ErrNoSuchTarget(ref.Tag()))
}
r, err := convertTarget(t.Target)
if err != nil {
return nil, err
}
return reference.WithDigest(reference.TrimNamed(ref), r.digest)
} | [
"func",
"TrustedReference",
"(",
"ctx",
"context",
".",
"Context",
",",
"cli",
"command",
".",
"Cli",
",",
"ref",
"reference",
".",
"NamedTagged",
",",
"rs",
"registry",
".",
"Service",
")",
"(",
"reference",
".",
"Canonical",
",",
"error",
")",
"{",
"imgRefAndAuth",
",",
"err",
":=",
"trust",
".",
"GetImageReferencesAndAuth",
"(",
"ctx",
",",
"rs",
",",
"AuthResolver",
"(",
"cli",
")",
",",
"ref",
".",
"String",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"notaryRepo",
",",
"err",
":=",
"cli",
".",
"NotaryClient",
"(",
"imgRefAndAuth",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"err",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"t",
",",
"err",
":=",
"notaryRepo",
".",
"GetTargetByName",
"(",
"ref",
".",
"Tag",
"(",
")",
",",
"trust",
".",
"ReleasesRole",
",",
"data",
".",
"CanonicalTargetsRole",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"trust",
".",
"NotaryError",
"(",
"imgRefAndAuth",
".",
"RepoInfo",
"(",
")",
".",
"Name",
".",
"Name",
"(",
")",
",",
"err",
")",
"\n",
"}",
"\n",
"// Only list tags in the top level targets role or the releases delegation role - ignore",
"// all other delegation roles",
"if",
"t",
".",
"Role",
"!=",
"trust",
".",
"ReleasesRole",
"&&",
"t",
".",
"Role",
"!=",
"data",
".",
"CanonicalTargetsRole",
"{",
"return",
"nil",
",",
"trust",
".",
"NotaryError",
"(",
"imgRefAndAuth",
".",
"RepoInfo",
"(",
")",
".",
"Name",
".",
"Name",
"(",
")",
",",
"client",
".",
"ErrNoSuchTarget",
"(",
"ref",
".",
"Tag",
"(",
")",
")",
")",
"\n",
"}",
"\n",
"r",
",",
"err",
":=",
"convertTarget",
"(",
"t",
".",
"Target",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n\n",
"}",
"\n",
"return",
"reference",
".",
"WithDigest",
"(",
"reference",
".",
"TrimNamed",
"(",
"ref",
")",
",",
"r",
".",
"digest",
")",
"\n",
"}"
] | // TrustedReference returns the canonical trusted reference for an image reference | [
"TrustedReference",
"returns",
"the",
"canonical",
"trusted",
"reference",
"for",
"an",
"image",
"reference"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/trust.go#L306-L332 | train |
docker/cli | cli/command/image/trust.go | AuthResolver | func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
return func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
return command.ResolveAuthConfig(ctx, cli, index)
}
} | go | func AuthResolver(cli command.Cli) func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
return func(ctx context.Context, index *registrytypes.IndexInfo) types.AuthConfig {
return command.ResolveAuthConfig(ctx, cli, index)
}
} | [
"func",
"AuthResolver",
"(",
"cli",
"command",
".",
"Cli",
")",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"*",
"registrytypes",
".",
"IndexInfo",
")",
"types",
".",
"AuthConfig",
"{",
"return",
"func",
"(",
"ctx",
"context",
".",
"Context",
",",
"index",
"*",
"registrytypes",
".",
"IndexInfo",
")",
"types",
".",
"AuthConfig",
"{",
"return",
"command",
".",
"ResolveAuthConfig",
"(",
"ctx",
",",
"cli",
",",
"index",
")",
"\n",
"}",
"\n",
"}"
] | // AuthResolver returns an auth resolver function from a command.Cli | [
"AuthResolver",
"returns",
"an",
"auth",
"resolver",
"function",
"from",
"a",
"command",
".",
"Cli"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/image/trust.go#L359-L363 | train |
docker/cli | cli/command/service/formatter.go | NewFormat | func NewFormat(source string) formatter.Format {
switch source {
case formatter.PrettyFormatKey:
return serviceInspectPrettyTemplate
default:
return formatter.Format(strings.TrimPrefix(source, formatter.RawFormatKey))
}
} | go | func NewFormat(source string) formatter.Format {
switch source {
case formatter.PrettyFormatKey:
return serviceInspectPrettyTemplate
default:
return formatter.Format(strings.TrimPrefix(source, formatter.RawFormatKey))
}
} | [
"func",
"NewFormat",
"(",
"source",
"string",
")",
"formatter",
".",
"Format",
"{",
"switch",
"source",
"{",
"case",
"formatter",
".",
"PrettyFormatKey",
":",
"return",
"serviceInspectPrettyTemplate",
"\n",
"default",
":",
"return",
"formatter",
".",
"Format",
"(",
"strings",
".",
"TrimPrefix",
"(",
"source",
",",
"formatter",
".",
"RawFormatKey",
")",
")",
"\n",
"}",
"\n",
"}"
] | // NewFormat returns a Format for rendering using a Context | [
"NewFormat",
"returns",
"a",
"Format",
"for",
"rendering",
"using",
"a",
"Context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/service/formatter.go#L170-L177 | train |
docker/cli | cli/command/service/formatter.go | InspectFormatWrite | func InspectFormatWrite(ctx formatter.Context, refs []string, getRef, getNetwork inspect.GetRefFunc) error {
if ctx.Format != serviceInspectPrettyTemplate {
return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef)
}
render := func(format func(subContext formatter.SubContext) error) error {
for _, ref := range refs {
serviceI, _, err := getRef(ref)
if err != nil {
return err
}
service, ok := serviceI.(swarm.Service)
if !ok {
return errors.Errorf("got wrong object to inspect")
}
if err := format(&serviceInspectContext{Service: service, networkNames: resolveNetworks(service, getNetwork)}); err != nil {
return err
}
}
return nil
}
return ctx.Write(&serviceInspectContext{}, render)
} | go | func InspectFormatWrite(ctx formatter.Context, refs []string, getRef, getNetwork inspect.GetRefFunc) error {
if ctx.Format != serviceInspectPrettyTemplate {
return inspect.Inspect(ctx.Output, refs, string(ctx.Format), getRef)
}
render := func(format func(subContext formatter.SubContext) error) error {
for _, ref := range refs {
serviceI, _, err := getRef(ref)
if err != nil {
return err
}
service, ok := serviceI.(swarm.Service)
if !ok {
return errors.Errorf("got wrong object to inspect")
}
if err := format(&serviceInspectContext{Service: service, networkNames: resolveNetworks(service, getNetwork)}); err != nil {
return err
}
}
return nil
}
return ctx.Write(&serviceInspectContext{}, render)
} | [
"func",
"InspectFormatWrite",
"(",
"ctx",
"formatter",
".",
"Context",
",",
"refs",
"[",
"]",
"string",
",",
"getRef",
",",
"getNetwork",
"inspect",
".",
"GetRefFunc",
")",
"error",
"{",
"if",
"ctx",
".",
"Format",
"!=",
"serviceInspectPrettyTemplate",
"{",
"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",
"{",
"serviceI",
",",
"_",
",",
"err",
":=",
"getRef",
"(",
"ref",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"service",
",",
"ok",
":=",
"serviceI",
".",
"(",
"swarm",
".",
"Service",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"format",
"(",
"&",
"serviceInspectContext",
"{",
"Service",
":",
"service",
",",
"networkNames",
":",
"resolveNetworks",
"(",
"service",
",",
"getNetwork",
")",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"return",
"ctx",
".",
"Write",
"(",
"&",
"serviceInspectContext",
"{",
"}",
",",
"render",
")",
"\n",
"}"
] | // InspectFormatWrite renders the context for a list of services | [
"InspectFormatWrite",
"renders",
"the",
"context",
"for",
"a",
"list",
"of",
"services"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/service/formatter.go#L192-L213 | train |
docker/cli | cli/command/service/formatter.go | NewListFormat | func NewListFormat(source string, quiet bool) formatter.Format {
switch source {
case formatter.TableFormatKey:
if quiet {
return formatter.DefaultQuietFormat
}
return defaultServiceTableFormat
case formatter.RawFormatKey:
if quiet {
return `id: {{.ID}}`
}
return `id: {{.ID}}\nname: {{.Name}}\nmode: {{.Mode}}\nreplicas: {{.Replicas}}\nimage: {{.Image}}\nports: {{.Ports}}\n`
}
return formatter.Format(source)
} | go | func NewListFormat(source string, quiet bool) formatter.Format {
switch source {
case formatter.TableFormatKey:
if quiet {
return formatter.DefaultQuietFormat
}
return defaultServiceTableFormat
case formatter.RawFormatKey:
if quiet {
return `id: {{.ID}}`
}
return `id: {{.ID}}\nname: {{.Name}}\nmode: {{.Mode}}\nreplicas: {{.Replicas}}\nimage: {{.Image}}\nports: {{.Ports}}\n`
}
return formatter.Format(source)
} | [
"func",
"NewListFormat",
"(",
"source",
"string",
",",
"quiet",
"bool",
")",
"formatter",
".",
"Format",
"{",
"switch",
"source",
"{",
"case",
"formatter",
".",
"TableFormatKey",
":",
"if",
"quiet",
"{",
"return",
"formatter",
".",
"DefaultQuietFormat",
"\n",
"}",
"\n",
"return",
"defaultServiceTableFormat",
"\n",
"case",
"formatter",
".",
"RawFormatKey",
":",
"if",
"quiet",
"{",
"return",
"`id: {{.ID}}`",
"\n",
"}",
"\n",
"return",
"`id: {{.ID}}\\nname: {{.Name}}\\nmode: {{.Mode}}\\nreplicas: {{.Replicas}}\\nimage: {{.Image}}\\nports: {{.Ports}}\\n`",
"\n",
"}",
"\n",
"return",
"formatter",
".",
"Format",
"(",
"source",
")",
"\n",
"}"
] | // NewListFormat returns a Format for rendering using a service Context | [
"NewListFormat",
"returns",
"a",
"Format",
"for",
"rendering",
"using",
"a",
"service",
"Context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/service/formatter.go#L507-L521 | train |
docker/cli | cli/command/service/formatter.go | ListFormatWrite | func ListFormatWrite(ctx formatter.Context, services []swarm.Service, info map[string]ListInfo) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, service := range services {
serviceCtx := &serviceContext{service: service, mode: info[service.ID].Mode, replicas: info[service.ID].Replicas}
if err := format(serviceCtx); err != nil {
return err
}
}
return nil
}
serviceCtx := serviceContext{}
serviceCtx.Header = formatter.SubHeaderContext{
"ID": serviceIDHeader,
"Name": formatter.NameHeader,
"Mode": modeHeader,
"Replicas": replicasHeader,
"Image": formatter.ImageHeader,
"Ports": formatter.PortsHeader,
}
return ctx.Write(&serviceCtx, render)
} | go | func ListFormatWrite(ctx formatter.Context, services []swarm.Service, info map[string]ListInfo) error {
render := func(format func(subContext formatter.SubContext) error) error {
for _, service := range services {
serviceCtx := &serviceContext{service: service, mode: info[service.ID].Mode, replicas: info[service.ID].Replicas}
if err := format(serviceCtx); err != nil {
return err
}
}
return nil
}
serviceCtx := serviceContext{}
serviceCtx.Header = formatter.SubHeaderContext{
"ID": serviceIDHeader,
"Name": formatter.NameHeader,
"Mode": modeHeader,
"Replicas": replicasHeader,
"Image": formatter.ImageHeader,
"Ports": formatter.PortsHeader,
}
return ctx.Write(&serviceCtx, render)
} | [
"func",
"ListFormatWrite",
"(",
"ctx",
"formatter",
".",
"Context",
",",
"services",
"[",
"]",
"swarm",
".",
"Service",
",",
"info",
"map",
"[",
"string",
"]",
"ListInfo",
")",
"error",
"{",
"render",
":=",
"func",
"(",
"format",
"func",
"(",
"subContext",
"formatter",
".",
"SubContext",
")",
"error",
")",
"error",
"{",
"for",
"_",
",",
"service",
":=",
"range",
"services",
"{",
"serviceCtx",
":=",
"&",
"serviceContext",
"{",
"service",
":",
"service",
",",
"mode",
":",
"info",
"[",
"service",
".",
"ID",
"]",
".",
"Mode",
",",
"replicas",
":",
"info",
"[",
"service",
".",
"ID",
"]",
".",
"Replicas",
"}",
"\n",
"if",
"err",
":=",
"format",
"(",
"serviceCtx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"serviceCtx",
":=",
"serviceContext",
"{",
"}",
"\n",
"serviceCtx",
".",
"Header",
"=",
"formatter",
".",
"SubHeaderContext",
"{",
"\"",
"\"",
":",
"serviceIDHeader",
",",
"\"",
"\"",
":",
"formatter",
".",
"NameHeader",
",",
"\"",
"\"",
":",
"modeHeader",
",",
"\"",
"\"",
":",
"replicasHeader",
",",
"\"",
"\"",
":",
"formatter",
".",
"ImageHeader",
",",
"\"",
"\"",
":",
"formatter",
".",
"PortsHeader",
",",
"}",
"\n",
"return",
"ctx",
".",
"Write",
"(",
"&",
"serviceCtx",
",",
"render",
")",
"\n",
"}"
] | // ListFormatWrite writes the context | [
"ListFormatWrite",
"writes",
"the",
"context"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/service/formatter.go#L530-L550 | train |
docker/cli | cli/command/container/restart.go | NewRestartCommand | func NewRestartCommand(dockerCli command.Cli) *cobra.Command {
var opts restartOptions
cmd := &cobra.Command{
Use: "restart [OPTIONS] CONTAINER [CONTAINER...]",
Short: "Restart one or more containers",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
opts.nSecondsChanged = cmd.Flags().Changed("time")
return runRestart(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.IntVarP(&opts.nSeconds, "time", "t", 10, "Seconds to wait for stop before killing the container")
return cmd
} | go | func NewRestartCommand(dockerCli command.Cli) *cobra.Command {
var opts restartOptions
cmd := &cobra.Command{
Use: "restart [OPTIONS] CONTAINER [CONTAINER...]",
Short: "Restart one or more containers",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
opts.containers = args
opts.nSecondsChanged = cmd.Flags().Changed("time")
return runRestart(dockerCli, &opts)
},
}
flags := cmd.Flags()
flags.IntVarP(&opts.nSeconds, "time", "t", 10, "Seconds to wait for stop before killing the container")
return cmd
} | [
"func",
"NewRestartCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"var",
"opts",
"restartOptions",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"RequiresMinArgs",
"(",
"1",
")",
",",
"RunE",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"opts",
".",
"containers",
"=",
"args",
"\n",
"opts",
".",
"nSecondsChanged",
"=",
"cmd",
".",
"Flags",
"(",
")",
".",
"Changed",
"(",
"\"",
"\"",
")",
"\n",
"return",
"runRestart",
"(",
"dockerCli",
",",
"&",
"opts",
")",
"\n",
"}",
",",
"}",
"\n\n",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n",
"flags",
".",
"IntVarP",
"(",
"&",
"opts",
".",
"nSeconds",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"10",
",",
"\"",
"\"",
")",
"\n",
"return",
"cmd",
"\n",
"}"
] | // NewRestartCommand creates a new cobra.Command for `docker restart` | [
"NewRestartCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"restart"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/container/restart.go#L23-L40 | train |
docker/cli | cli-plugins/manager/suffix_windows.go | trimExeSuffix | func trimExeSuffix(s string) (string, error) {
ext := filepath.Ext(s)
if ext == "" {
return "", errors.Errorf("path %q lacks required file extension", s)
}
exe := ".exe"
if !strings.EqualFold(ext, exe) {
return "", errors.Errorf("path %q lacks required %q suffix", s, exe)
}
return strings.TrimSuffix(s, ext), nil
} | go | func trimExeSuffix(s string) (string, error) {
ext := filepath.Ext(s)
if ext == "" {
return "", errors.Errorf("path %q lacks required file extension", s)
}
exe := ".exe"
if !strings.EqualFold(ext, exe) {
return "", errors.Errorf("path %q lacks required %q suffix", s, exe)
}
return strings.TrimSuffix(s, ext), nil
} | [
"func",
"trimExeSuffix",
"(",
"s",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"ext",
":=",
"filepath",
".",
"Ext",
"(",
"s",
")",
"\n",
"if",
"ext",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
")",
"\n",
"}",
"\n\n",
"exe",
":=",
"\"",
"\"",
"\n",
"if",
"!",
"strings",
".",
"EqualFold",
"(",
"ext",
",",
"exe",
")",
"{",
"return",
"\"",
"\"",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"s",
",",
"exe",
")",
"\n",
"}",
"\n",
"return",
"strings",
".",
"TrimSuffix",
"(",
"s",
",",
"ext",
")",
",",
"nil",
"\n",
"}"
] | // This is made slightly more complex due to needing to be case insensitive. | [
"This",
"is",
"made",
"slightly",
"more",
"complex",
"due",
"to",
"needing",
"to",
"be",
"case",
"insensitive",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli-plugins/manager/suffix_windows.go#L11-L22 | train |
docker/cli | cli/command/trust/key_generate.go | validateKeyArgs | func validateKeyArgs(keyName string, targetDir string) error {
if !validKeyName(keyName) {
return fmt.Errorf("key name \"%s\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character", keyName)
}
pubKeyFileName := keyName + ".pub"
if _, err := os.Stat(targetDir); err != nil {
return fmt.Errorf("public key path does not exist: \"%s\"", targetDir)
}
targetPath := filepath.Join(targetDir, pubKeyFileName)
if _, err := os.Stat(targetPath); err == nil {
return fmt.Errorf("public key file already exists: \"%s\"", targetPath)
}
return nil
} | go | func validateKeyArgs(keyName string, targetDir string) error {
if !validKeyName(keyName) {
return fmt.Errorf("key name \"%s\" must start with lowercase alphanumeric characters and can include \"-\" or \"_\" after the first character", keyName)
}
pubKeyFileName := keyName + ".pub"
if _, err := os.Stat(targetDir); err != nil {
return fmt.Errorf("public key path does not exist: \"%s\"", targetDir)
}
targetPath := filepath.Join(targetDir, pubKeyFileName)
if _, err := os.Stat(targetPath); err == nil {
return fmt.Errorf("public key file already exists: \"%s\"", targetPath)
}
return nil
} | [
"func",
"validateKeyArgs",
"(",
"keyName",
"string",
",",
"targetDir",
"string",
")",
"error",
"{",
"if",
"!",
"validKeyName",
"(",
"keyName",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\\\"",
"\"",
",",
"keyName",
")",
"\n",
"}",
"\n\n",
"pubKeyFileName",
":=",
"keyName",
"+",
"\"",
"\"",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"targetDir",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"targetDir",
")",
"\n",
"}",
"\n",
"targetPath",
":=",
"filepath",
".",
"Join",
"(",
"targetDir",
",",
"pubKeyFileName",
")",
"\n",
"if",
"_",
",",
"err",
":=",
"os",
".",
"Stat",
"(",
"targetPath",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"targetPath",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // validate that all of the key names are unique and are alphanumeric + _ + -
// and that we do not already have public key files in the target dir on disk | [
"validate",
"that",
"all",
"of",
"the",
"key",
"names",
"are",
"unique",
"and",
"are",
"alphanumeric",
"+",
"_",
"+",
"-",
"and",
"that",
"we",
"do",
"not",
"already",
"have",
"public",
"key",
"files",
"in",
"the",
"target",
"dir",
"on",
"disk"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/trust/key_generate.go#L49-L63 | train |
docker/cli | internal/pkg/containerized/hostpaths.go | WithAllCapabilities | func WithAllCapabilities(_ context.Context, _ oci.Client, c *containers.Container, s *specs.Spec) error {
caps := []string{
"CAP_CHOWN",
"CAP_DAC_OVERRIDE",
"CAP_DAC_READ_SEARCH",
"CAP_FOWNER",
"CAP_FSETID",
"CAP_KILL",
"CAP_SETGID",
"CAP_SETUID",
"CAP_SETPCAP",
"CAP_LINUX_IMMUTABLE",
"CAP_NET_BIND_SERVICE",
"CAP_NET_BROADCAST",
"CAP_NET_ADMIN",
"CAP_NET_RAW",
"CAP_IPC_LOCK",
"CAP_IPC_OWNER",
"CAP_SYS_MODULE",
"CAP_SYS_RAWIO",
"CAP_SYS_CHROOT",
"CAP_SYS_PTRACE",
"CAP_SYS_PACCT",
"CAP_SYS_ADMIN",
"CAP_SYS_BOOT",
"CAP_SYS_NICE",
"CAP_SYS_RESOURCE",
"CAP_SYS_TIME",
"CAP_SYS_TTY_CONFIG",
"CAP_MKNOD",
"CAP_LEASE",
"CAP_AUDIT_WRITE",
"CAP_AUDIT_CONTROL",
"CAP_SETFCAP",
"CAP_MAC_OVERRIDE",
"CAP_MAC_ADMIN",
"CAP_SYSLOG",
"CAP_WAKE_ALARM",
"CAP_BLOCK_SUSPEND",
"CAP_AUDIT_READ",
}
if s.Process.Capabilities == nil {
s.Process.Capabilities = &specs.LinuxCapabilities{}
}
s.Process.Capabilities.Bounding = caps
s.Process.Capabilities.Effective = caps
s.Process.Capabilities.Inheritable = caps
s.Process.Capabilities.Permitted = caps
return nil
} | go | func WithAllCapabilities(_ context.Context, _ oci.Client, c *containers.Container, s *specs.Spec) error {
caps := []string{
"CAP_CHOWN",
"CAP_DAC_OVERRIDE",
"CAP_DAC_READ_SEARCH",
"CAP_FOWNER",
"CAP_FSETID",
"CAP_KILL",
"CAP_SETGID",
"CAP_SETUID",
"CAP_SETPCAP",
"CAP_LINUX_IMMUTABLE",
"CAP_NET_BIND_SERVICE",
"CAP_NET_BROADCAST",
"CAP_NET_ADMIN",
"CAP_NET_RAW",
"CAP_IPC_LOCK",
"CAP_IPC_OWNER",
"CAP_SYS_MODULE",
"CAP_SYS_RAWIO",
"CAP_SYS_CHROOT",
"CAP_SYS_PTRACE",
"CAP_SYS_PACCT",
"CAP_SYS_ADMIN",
"CAP_SYS_BOOT",
"CAP_SYS_NICE",
"CAP_SYS_RESOURCE",
"CAP_SYS_TIME",
"CAP_SYS_TTY_CONFIG",
"CAP_MKNOD",
"CAP_LEASE",
"CAP_AUDIT_WRITE",
"CAP_AUDIT_CONTROL",
"CAP_SETFCAP",
"CAP_MAC_OVERRIDE",
"CAP_MAC_ADMIN",
"CAP_SYSLOG",
"CAP_WAKE_ALARM",
"CAP_BLOCK_SUSPEND",
"CAP_AUDIT_READ",
}
if s.Process.Capabilities == nil {
s.Process.Capabilities = &specs.LinuxCapabilities{}
}
s.Process.Capabilities.Bounding = caps
s.Process.Capabilities.Effective = caps
s.Process.Capabilities.Inheritable = caps
s.Process.Capabilities.Permitted = caps
return nil
} | [
"func",
"WithAllCapabilities",
"(",
"_",
"context",
".",
"Context",
",",
"_",
"oci",
".",
"Client",
",",
"c",
"*",
"containers",
".",
"Container",
",",
"s",
"*",
"specs",
".",
"Spec",
")",
"error",
"{",
"caps",
":=",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"}",
"\n",
"if",
"s",
".",
"Process",
".",
"Capabilities",
"==",
"nil",
"{",
"s",
".",
"Process",
".",
"Capabilities",
"=",
"&",
"specs",
".",
"LinuxCapabilities",
"{",
"}",
"\n",
"}",
"\n",
"s",
".",
"Process",
".",
"Capabilities",
".",
"Bounding",
"=",
"caps",
"\n",
"s",
".",
"Process",
".",
"Capabilities",
".",
"Effective",
"=",
"caps",
"\n",
"s",
".",
"Process",
".",
"Capabilities",
".",
"Inheritable",
"=",
"caps",
"\n",
"s",
".",
"Process",
".",
"Capabilities",
".",
"Permitted",
"=",
"caps",
"\n",
"return",
"nil",
"\n",
"}"
] | // WithAllCapabilities enables all capabilities required to run privileged containers | [
"WithAllCapabilities",
"enables",
"all",
"capabilities",
"required",
"to",
"run",
"privileged",
"containers"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/internal/pkg/containerized/hostpaths.go#L12-L61 | train |
docker/cli | cli/command/stack/loader/loader.go | LoadComposefile | func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.Config, error) {
configDetails, err := getConfigDetails(opts.Composefiles, dockerCli.In())
if err != nil {
return nil, err
}
dicts := getDictsFrom(configDetails.ConfigFiles)
config, err := loader.Load(configDetails)
if err != nil {
if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n",
propertyWarnings(fpe.Properties))
}
return nil, err
}
unsupportedProperties := loader.GetUnsupportedProperties(dicts...)
if len(unsupportedProperties) > 0 {
fmt.Fprintf(dockerCli.Err(), "Ignoring unsupported options: %s\n\n",
strings.Join(unsupportedProperties, ", "))
}
deprecatedProperties := loader.GetDeprecatedProperties(dicts...)
if len(deprecatedProperties) > 0 {
fmt.Fprintf(dockerCli.Err(), "Ignoring deprecated options:\n\n%s\n\n",
propertyWarnings(deprecatedProperties))
}
return config, nil
} | go | func LoadComposefile(dockerCli command.Cli, opts options.Deploy) (*composetypes.Config, error) {
configDetails, err := getConfigDetails(opts.Composefiles, dockerCli.In())
if err != nil {
return nil, err
}
dicts := getDictsFrom(configDetails.ConfigFiles)
config, err := loader.Load(configDetails)
if err != nil {
if fpe, ok := err.(*loader.ForbiddenPropertiesError); ok {
return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n",
propertyWarnings(fpe.Properties))
}
return nil, err
}
unsupportedProperties := loader.GetUnsupportedProperties(dicts...)
if len(unsupportedProperties) > 0 {
fmt.Fprintf(dockerCli.Err(), "Ignoring unsupported options: %s\n\n",
strings.Join(unsupportedProperties, ", "))
}
deprecatedProperties := loader.GetDeprecatedProperties(dicts...)
if len(deprecatedProperties) > 0 {
fmt.Fprintf(dockerCli.Err(), "Ignoring deprecated options:\n\n%s\n\n",
propertyWarnings(deprecatedProperties))
}
return config, nil
} | [
"func",
"LoadComposefile",
"(",
"dockerCli",
"command",
".",
"Cli",
",",
"opts",
"options",
".",
"Deploy",
")",
"(",
"*",
"composetypes",
".",
"Config",
",",
"error",
")",
"{",
"configDetails",
",",
"err",
":=",
"getConfigDetails",
"(",
"opts",
".",
"Composefiles",
",",
"dockerCli",
".",
"In",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"dicts",
":=",
"getDictsFrom",
"(",
"configDetails",
".",
"ConfigFiles",
")",
"\n",
"config",
",",
"err",
":=",
"loader",
".",
"Load",
"(",
"configDetails",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"if",
"fpe",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"loader",
".",
"ForbiddenPropertiesError",
")",
";",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"Errorf",
"(",
"\"",
"\\n",
"\\n",
"\\n",
"\"",
",",
"propertyWarnings",
"(",
"fpe",
".",
"Properties",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"unsupportedProperties",
":=",
"loader",
".",
"GetUnsupportedProperties",
"(",
"dicts",
"...",
")",
"\n",
"if",
"len",
"(",
"unsupportedProperties",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"dockerCli",
".",
"Err",
"(",
")",
",",
"\"",
"\\n",
"\\n",
"\"",
",",
"strings",
".",
"Join",
"(",
"unsupportedProperties",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"deprecatedProperties",
":=",
"loader",
".",
"GetDeprecatedProperties",
"(",
"dicts",
"...",
")",
"\n",
"if",
"len",
"(",
"deprecatedProperties",
")",
">",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"dockerCli",
".",
"Err",
"(",
")",
",",
"\"",
"\\n",
"\\n",
"\\n",
"\\n",
"\"",
",",
"propertyWarnings",
"(",
"deprecatedProperties",
")",
")",
"\n",
"}",
"\n",
"return",
"config",
",",
"nil",
"\n",
"}"
] | // LoadComposefile parse the composefile specified in the cli and returns its Config and version. | [
"LoadComposefile",
"parse",
"the",
"composefile",
"specified",
"in",
"the",
"cli",
"and",
"returns",
"its",
"Config",
"and",
"version",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/stack/loader/loader.go#L21-L50 | train |
docker/cli | cli/command/system/events.go | NewEventsCommand | func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
options := eventsOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "events [OPTIONS]",
Short: "Get real time events from the server",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runEvents(dockerCli, &options)
},
}
flags := cmd.Flags()
flags.StringVar(&options.since, "since", "", "Show all events created since timestamp")
flags.StringVar(&options.until, "until", "", "Stream events until this timestamp")
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.StringVar(&options.format, "format", "", "Format the output using the given Go template")
return cmd
} | go | func NewEventsCommand(dockerCli command.Cli) *cobra.Command {
options := eventsOptions{filter: opts.NewFilterOpt()}
cmd := &cobra.Command{
Use: "events [OPTIONS]",
Short: "Get real time events from the server",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runEvents(dockerCli, &options)
},
}
flags := cmd.Flags()
flags.StringVar(&options.since, "since", "", "Show all events created since timestamp")
flags.StringVar(&options.until, "until", "", "Stream events until this timestamp")
flags.VarP(&options.filter, "filter", "f", "Filter output based on conditions provided")
flags.StringVar(&options.format, "format", "", "Format the output using the given Go template")
return cmd
} | [
"func",
"NewEventsCommand",
"(",
"dockerCli",
"command",
".",
"Cli",
")",
"*",
"cobra",
".",
"Command",
"{",
"options",
":=",
"eventsOptions",
"{",
"filter",
":",
"opts",
".",
"NewFilterOpt",
"(",
")",
"}",
"\n\n",
"cmd",
":=",
"&",
"cobra",
".",
"Command",
"{",
"Use",
":",
"\"",
"\"",
",",
"Short",
":",
"\"",
"\"",
",",
"Args",
":",
"cli",
".",
"NoArgs",
",",
"RunE",
":",
"func",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"return",
"runEvents",
"(",
"dockerCli",
",",
"&",
"options",
")",
"\n",
"}",
",",
"}",
"\n\n",
"flags",
":=",
"cmd",
".",
"Flags",
"(",
")",
"\n",
"flags",
".",
"StringVar",
"(",
"&",
"options",
".",
"since",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"StringVar",
"(",
"&",
"options",
".",
"until",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"VarP",
"(",
"&",
"options",
".",
"filter",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"flags",
".",
"StringVar",
"(",
"&",
"options",
".",
"format",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n\n",
"return",
"cmd",
"\n",
"}"
] | // NewEventsCommand creates a new cobra.Command for `docker events` | [
"NewEventsCommand",
"creates",
"a",
"new",
"cobra",
".",
"Command",
"for",
"docker",
"events"
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/events.go#L30-L49 | train |
docker/cli | cli/command/system/events.go | prettyPrintEvent | func prettyPrintEvent(out io.Writer, event eventtypes.Message) error {
if event.TimeNano != 0 {
fmt.Fprintf(out, "%s ", time.Unix(0, event.TimeNano).Format(rfc3339NanoFixed))
} else if event.Time != 0 {
fmt.Fprintf(out, "%s ", time.Unix(event.Time, 0).Format(rfc3339NanoFixed))
}
fmt.Fprintf(out, "%s %s %s", event.Type, event.Action, event.Actor.ID)
if len(event.Actor.Attributes) > 0 {
var attrs []string
var keys []string
for k := range event.Actor.Attributes {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := event.Actor.Attributes[k]
attrs = append(attrs, fmt.Sprintf("%s=%s", k, v))
}
fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", "))
}
fmt.Fprint(out, "\n")
return nil
} | go | func prettyPrintEvent(out io.Writer, event eventtypes.Message) error {
if event.TimeNano != 0 {
fmt.Fprintf(out, "%s ", time.Unix(0, event.TimeNano).Format(rfc3339NanoFixed))
} else if event.Time != 0 {
fmt.Fprintf(out, "%s ", time.Unix(event.Time, 0).Format(rfc3339NanoFixed))
}
fmt.Fprintf(out, "%s %s %s", event.Type, event.Action, event.Actor.ID)
if len(event.Actor.Attributes) > 0 {
var attrs []string
var keys []string
for k := range event.Actor.Attributes {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := event.Actor.Attributes[k]
attrs = append(attrs, fmt.Sprintf("%s=%s", k, v))
}
fmt.Fprintf(out, " (%s)", strings.Join(attrs, ", "))
}
fmt.Fprint(out, "\n")
return nil
} | [
"func",
"prettyPrintEvent",
"(",
"out",
"io",
".",
"Writer",
",",
"event",
"eventtypes",
".",
"Message",
")",
"error",
"{",
"if",
"event",
".",
"TimeNano",
"!=",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\"",
",",
"time",
".",
"Unix",
"(",
"0",
",",
"event",
".",
"TimeNano",
")",
".",
"Format",
"(",
"rfc3339NanoFixed",
")",
")",
"\n",
"}",
"else",
"if",
"event",
".",
"Time",
"!=",
"0",
"{",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\"",
",",
"time",
".",
"Unix",
"(",
"event",
".",
"Time",
",",
"0",
")",
".",
"Format",
"(",
"rfc3339NanoFixed",
")",
")",
"\n",
"}",
"\n\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\"",
",",
"event",
".",
"Type",
",",
"event",
".",
"Action",
",",
"event",
".",
"Actor",
".",
"ID",
")",
"\n\n",
"if",
"len",
"(",
"event",
".",
"Actor",
".",
"Attributes",
")",
">",
"0",
"{",
"var",
"attrs",
"[",
"]",
"string",
"\n",
"var",
"keys",
"[",
"]",
"string",
"\n",
"for",
"k",
":=",
"range",
"event",
".",
"Actor",
".",
"Attributes",
"{",
"keys",
"=",
"append",
"(",
"keys",
",",
"k",
")",
"\n",
"}",
"\n",
"sort",
".",
"Strings",
"(",
"keys",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"keys",
"{",
"v",
":=",
"event",
".",
"Actor",
".",
"Attributes",
"[",
"k",
"]",
"\n",
"attrs",
"=",
"append",
"(",
"attrs",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"k",
",",
"v",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"out",
",",
"\"",
"\"",
",",
"strings",
".",
"Join",
"(",
"attrs",
",",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprint",
"(",
"out",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // prettyPrintEvent prints all types of event information.
// Each output includes the event type, actor id, name and action.
// Actor attributes are printed at the end if the actor has any. | [
"prettyPrintEvent",
"prints",
"all",
"types",
"of",
"event",
"information",
".",
"Each",
"output",
"includes",
"the",
"event",
"type",
"actor",
"id",
"name",
"and",
"action",
".",
"Actor",
"attributes",
"are",
"printed",
"at",
"the",
"end",
"if",
"the",
"actor",
"has",
"any",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/cli/command/system/events.go#L113-L137 | train |
docker/cli | opts/duration.go | Set | func (d *PositiveDurationOpt) Set(s string) error {
err := d.DurationOpt.Set(s)
if err != nil {
return err
}
if *d.DurationOpt.value < 0 {
return errors.Errorf("duration cannot be negative")
}
return nil
} | go | func (d *PositiveDurationOpt) Set(s string) error {
err := d.DurationOpt.Set(s)
if err != nil {
return err
}
if *d.DurationOpt.value < 0 {
return errors.Errorf("duration cannot be negative")
}
return nil
} | [
"func",
"(",
"d",
"*",
"PositiveDurationOpt",
")",
"Set",
"(",
"s",
"string",
")",
"error",
"{",
"err",
":=",
"d",
".",
"DurationOpt",
".",
"Set",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"*",
"d",
".",
"DurationOpt",
".",
"value",
"<",
"0",
"{",
"return",
"errors",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Set a new value on the option. Setting a negative duration value will cause
// an error to be returned. | [
"Set",
"a",
"new",
"value",
"on",
"the",
"option",
".",
"Setting",
"a",
"negative",
"duration",
"value",
"will",
"cause",
"an",
"error",
"to",
"be",
"returned",
"."
] | 3273c2e23546dddd0ff8bb499f4aba02fe60bf30 | https://github.com/docker/cli/blob/3273c2e23546dddd0ff8bb499f4aba02fe60bf30/opts/duration.go#L17-L26 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.