cp

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package cp implements the 'cp' command for copying files to Google Cloud Storage.

Index

Constants

This section is empty.

Variables

View Source
var Command = &cli.Command{
	Name:      "cp",
	Usage:     "Copy files and objects to and from Google Cloud Storage",
	ArgsUsage: "[SOURCE ...] DESTINATION",
	Flags: []cli.Flag{
		&cli.BoolFlag{Name: "recursive", Aliases: []string{"r"}, Usage: "Recursive copy"},
		&cli.BoolFlag{Name: "no-clobber", Aliases: []string{"n"}, Usage: "Do not overwrite existing files"},
		&cli.BoolFlag{Name: "verbose", Aliases: []string{"v"}, Usage: "Show progress periodically while copying"},
		&cli.StringFlag{Name: "cache-control", Usage: "Set cache-control header"},
		&cli.StringFlag{Name: "content-type", Usage: "Set content-type header"},
		&cli.StringFlag{Name: "storage-class", Usage: "Set storage class"},
		&cli.IntFlag{
			Name:        "parallelism",
			Aliases:     []string{"j"},
			Usage:       "Number of parallel copy workers",
			Value:       0,
			DefaultText: "number of CPU cores",
		},
	},
	Action: func(ctx context.Context, cmd *cli.Command) error {
		if cmd.Args().Len() < 2 {
			return fmt.Errorf("%w: cp command requires at least 2 arguments", utils.ErrInvalidArgs)
		}

		args := cmd.Args().Slice()
		srcs := args[:len(args)-1]
		dest := args[len(args)-1]

		opts := &copyOptions{
			recursive:    cmd.Bool("recursive"),
			noClobber:    cmd.Bool("no-clobber"),
			verbose:      cmd.Bool("verbose"),
			cacheControl: cmd.String("cache-control"),
			contentType:  cmd.String("content-type"),
			storageClass: cmd.String("storage-class"),
		}
		opts.parallelism = cmd.Int("parallelism")
		opts.setDefaults()

		client, err := utils.NewClient(ctx, buildClientOptions(opts.parallelism)...)
		if err != nil {
			return fmt.Errorf("failed to create GCS client: %w", err)
		}
		defer client.Close()

		for _, src := range srcs {
			if err := performCopy(ctx, client, src, dest, opts); err != nil {
				return err
			}
		}

		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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