()
| 201 | } |
| 202 | |
| 203 | func 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 | |
| 212 | Config 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. |
searching dependent graphs…