MCPcopy Create free account
hub / github.com/containerd/nerdctl / newApp

Function newApp

cmd/nerdctl/main.go:203–371  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

201}
202
203func newApp() (*cobra.Command, error) {
204 tomlPath := ncdefaults.NerdctlTOML()
205 if v, ok := os.LookupEnv("NERDCTL_TOML"); ok {
206 tomlPath = v
207 }
208
209 short := "nerdctl is a command line interface for containerd"
210 long := fmt.Sprintf(`%s
211
212Config file ($NERDCTL_TOML): %s
213`, short, tomlPath)
214 var rootCmd = &cobra.Command{
215 Use: "nerdctl",
216 Short: short,
217 Long: long,
218 Version: strings.TrimPrefix(version.GetVersion(), "v"),
219 SilenceUsage: true,
220 SilenceErrors: true,
221 TraverseChildren: true, // required for global short hands like -a, -H, -n
222 }
223
224 rootCmd.SetUsageFunc(usage)
225 aliasToBeInherited, err := initRootCmdFlags(rootCmd, tomlPath)
226 if err != nil {
227 return nil, err
228 }
229
230 if err := resetSavedSETUID(); err != nil {
231 return nil, err
232 }
233
234 rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
235 globalOptions, err := helpers.ProcessRootCmdFlags(cmd)
236 if err != nil {
237 return err
238 }
239 debug := globalOptions.DebugFull
240 if !debug {
241 debug = globalOptions.Debug
242 }
243 if debug {
244 log.SetLevel(log.DebugLevel.String())
245 }
246 address := globalOptions.Address
247 if strings.Contains(address, "://") && !strings.HasPrefix(address, "unix://") {
248 return fmt.Errorf("invalid address %q", address)
249 }
250 cgroupManager := globalOptions.CgroupManager
251 if runtime.GOOS == "linux" {
252 switch cgroupManager {
253 case "systemd", "cgroupfs", "none":
254 default:
255 return fmt.Errorf("invalid cgroup-manager %q (supported values: \"systemd\", \"cgroupfs\", \"none\")", cgroupManager)
256 }
257 }
258
259 // Since we store containers' stateful information on the filesystem per namespace, we need namespaces to be
260 // valid, safe path segments.

Callers 2

xmainFunction · 0.85

Calls 15

GetVersionFunction · 0.92
ProcessRootCmdFlagsFunction · 0.92
IsFilesystemSafeFunction · 0.92
ParentMainFunction · 0.92
CreateCommandFunction · 0.92
RunCommandFunction · 0.92
UpdateCommandFunction · 0.92
ExecCommandFunction · 0.92
PsCommandFunction · 0.92
LogsCommandFunction · 0.92
PortCommandFunction · 0.92
StopCommandFunction · 0.92

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…