func App()

in sources/host-ctr/cmd/host-ctr/main.go [62:175]


func App() *cli.App {
	// Command-line arguments
	var (
		containerID      string
		source           string
		containerdSocket string
		namespace        string
		superpowered     bool
		registryConfig   string
		cType            string
	)

	app := cli.NewApp()
	app.Name = "host-ctr"
	app.Usage = "manage host containers"

	// Global options
	app.Flags = []cli.Flag{
		&cli.StringFlag{
			Name:        "containerd-socket",
			Aliases:     []string{"s"},
			Usage:       "path to the containerd socket",
			Value:       "/run/host-containerd/containerd.sock",
			Destination: &containerdSocket,
		},
		&cli.StringFlag{
			Name:        "namespace",
			Aliases:     []string{"n"},
			Usage:       "the containerd namespace to operate in",
			Value:       "default",
			Destination: &namespace,
		},
	}

	// Subcommands
	app.Commands = []*cli.Command{
		{
			Name:  "run",
			Usage: "run host container with the specified image",
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:        "source",
					Usage:       "the image source",
					Destination: &source,
					Required:    true,
				},
				&cli.StringFlag{
					Name:        "container-id",
					Usage:       "the id of the container to manage",
					Destination: &containerID,
					Required:    true,
				},
				&cli.BoolFlag{
					Name:        "superpowered",
					Usage:       "specifies whether to create the container with `superpowered` privileges",
					Destination: &superpowered,
					Value:       false,
				},
				&cli.StringFlag{
					Name:        "registry-config",
					Usage:       "path to image registry configuration",
					Destination: &registryConfig,
				},
				&cli.StringFlag{
					Name:        "container-type",
					Usage:       "specifies one of: [host, bootstrap]",
					Destination: &cType,
					Value:       "host",
				},
			},
			Action: func(c *cli.Context) error {
				return runCtr(containerdSocket, namespace, containerID, source, superpowered, registryConfig, containerType(cType))
			},
		},
		{
			Name:        "pull-image",
			Usage:       "pull the specified container image",
			Description: "pull the specified container image to make it available in the containerd image store",
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:        "source",
					Usage:       "the image source",
					Destination: &source,
					Required:    true,
				},
				&cli.StringFlag{
					Name:        "registry-config",
					Usage:       "path to image registry configuration",
					Destination: &registryConfig,
				},
			},
			Action: func(c *cli.Context) error {
				return pullImageOnly(containerdSocket, namespace, source, registryConfig)
			},
		},
		{
			Name:  "clean-up",
			Usage: "delete specified container's resources if it exists",
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:        "container-id",
					Usage:       "the id of the container to clean up",
					Destination: &containerID,
					Required:    true,
				},
			},
			Action: func(c *cli.Context) error {
				return cleanUp(containerdSocket, namespace, containerID)
			},
		},
	}

	return app
}