MCPcopy Index your code
hub / github.com/linuxkit/linuxkit / newCmd

Function newCmd

src/cmd/linuxkit/cmd.go:46–124  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44}
45
46func newCmd() *cobra.Command {
47 var (
48 flagQuiet bool
49 flagVerbose int
50 flagVerboseName = "verbose"
51 mirrorsRaw []string
52 certFiles []string
53 )
54 cmd := &cobra.Command{
55 Use: "linuxkit",
56 DisableAutoGenTag: true,
57 SilenceUsage: true,
58 PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
59 readConfig()
60
61 // convert the provided mirrors to a map
62 for _, m := range mirrorsRaw {
63 if m == "" {
64 continue
65 }
66 parts := strings.SplitN(m, "=", 2)
67 // if no equals sign, use the whole string as the mirror for all registries
68 // not otherwise specified
69 var key, value string
70 if len(parts) == 1 {
71 key = "*"
72 value = parts[0]
73 } else {
74 key = parts[0]
75 value = parts[1]
76 }
77 // value must start with http:// or https://
78 if !strings.HasPrefix(value, "http://") && !strings.HasPrefix(value, "https://") {
79 return fmt.Errorf("mirror %q must start with http:// or https://", value)
80 }
81 // special logic for docker.io because of its odd references
82 if key == "docker.io" || key == "docker.io/" {
83 for _, prefix := range []string{"docker.io", "index.docker.io", "registry-1.docker.io"} {
84 registry.SetProxy(prefix, value)
85 }
86 } else {
87 registry.SetProxy(key, value)
88 }
89 }
90
91 for _, f := range certFiles {
92 if f == "" {
93 continue
94 }
95 cert, err := os.ReadFile(f)
96 if err != nil {
97 return fmt.Errorf("failed to read certificate file %q: %w", f, err)
98 }
99 // Add the certificate file to the registry
100 registry.AddCert(cert)
101 }
102
103 // Set up logging

Callers 1

mainFunction · 0.85

Calls 10

readConfigFunction · 0.85
buildCmdFunction · 0.85
cacheCmdFunction · 0.85
metadataCmdFunction · 0.85
pkgCmdFunction · 0.85
pushCmdFunction · 0.85
runCmdFunction · 0.85
serveCmdFunction · 0.85
versionCmdFunction · 0.85
defaultLinuxkitCacheFunction · 0.85

Tested by

no test coverage detected