container

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Commands = []*common.CliCommand{
	common.NewCliSubcommand(
		"container",
		[]*common.CliCommand{
			common.NewCliCommand(
				"list",
				"Retrieves all existing containers",
				"",
				func(args []string, conn *grpc.ClientConn) (exits.ExitCode, error) {
					client := pb.NewContainerServiceClient(conn)
					if err := List(client); err != nil {
						return exits.CONTAINER_ERROR, err
					}
					return exits.SUCCESS, nil
				},
			),
			common.NewCliCommand(
				"get",
				"Retrieves a specified container",
				"<id>",
				func(args []string, conn *grpc.ClientConn) (exits.ExitCode, error) {
					client := pb.NewContainerServiceClient(conn)
					if err := List(client); err != nil {
						return exits.CONTAINER_ERROR, err
					}
					return exits.SUCCESS, nil
				},
			),
			common.NewCliCommand(
				"delete",
				"Deletes a specified container. Before that, stops it if it is running.",
				"<id>",
				func(args []string, conn *grpc.ClientConn) (exits.ExitCode, error) {
					client := pb.NewContainerServiceClient(conn)
					id, exitCode, err := common.ParseUint32Arg(&args)
					if err != nil {
						return exitCode, fmt.Errorf("failed to parse 'id' argument: %w", err)
					}

					if err := Delete(client, id); err != nil {
						return exits.CONTAINER_ERROR, err
					}
					return exits.SUCCESS, nil
				},
			),
			common.NewCliCommand(
				"create",
				"Creates and starts a new container resource",
				"< file.yaml",
				func(args []string, conn *grpc.ClientConn) (exits.ExitCode, error) {
					client := pb.NewContainerServiceClient(conn)

					yamlBytes, err := io.ReadAll(os.Stdin)
					if err != nil {
						return exits.CONTAINER_ERROR, err
					}

					if err := Create(client, yamlBytes); err != nil {
						return exits.CONTAINER_ERROR, err
					}
					return exits.SUCCESS, nil
				},
			),
			common.NewCliCommand(
				"exec",
				"Starts a shell process inside a specified container or executes a specific command, if specified",
				"<id> [cmd]",
				func(args []string, conn *grpc.ClientConn) (exits.ExitCode, error) {
					client := pb.NewContainerServiceClient(conn)
					id, exitCode, err := common.ParseUint32Arg(&args)
					if err != nil {
						return exitCode, fmt.Errorf("failed to parse 'id' argument: %w", err)
					}

					if err := Exec(client, id, args); err != nil {
						return exits.CONTAINER_ERROR, err
					}
					return exits.SUCCESS, nil
				},
			),
			common.NewCliCommand(
				"start",
				"Starts a specified container resource",
				"<id>",
				func(args []string, conn *grpc.ClientConn) (exits.ExitCode, error) {
					client := pb.NewContainerServiceClient(conn)
					id, exitCode, err := common.ParseUint32Arg(&args)
					if err != nil {
						return exitCode, fmt.Errorf("failed to parse 'id' argument: %w", err)
					}

					if err := Start(client, id); err != nil {
						return exits.CONTAINER_ERROR, err
					}
					return exits.SUCCESS, nil
				},
			),
			common.NewCliCommand(
				"stop",
				"Stops a specified container resource",
				"<id>",
				func(args []string, conn *grpc.ClientConn) (exits.ExitCode, error) {
					client := pb.NewContainerServiceClient(conn)
					id, exitCode, err := common.ParseUint32Arg(&args)
					if err != nil {
						return exitCode, fmt.Errorf("failed to parse 'id' argument: %w", err)
					}

					if err := Stop(client, id); err != nil {
						return exits.CONTAINER_ERROR, err
					}
					return exits.SUCCESS, nil
				},
			),
		},
	),
}

Functions

func Create

func Create(client pb.ContainerServiceClient, yamlBytes []byte) error

func Delete

func Delete(client pb.ContainerServiceClient, id uint32) error

func Exec

func Exec(client pb.ContainerServiceClient, id uint32, args []string) error

func Get

func Get(client pb.ContainerServiceClient, id uint32) error

func List

func List(client pb.ContainerServiceClient) error

func Start

func Start(client pb.ContainerServiceClient, id uint32) error

func Stop

func Stop(client pb.ContainerServiceClient, id uint32) error

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL