mv

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cli.Command{
	Name:  "mv",
	Usage: "Move/rename files or directories",
	Flags: []cli.Flag{
		&cli.BoolFlag{Name: "interactive", Aliases: []string{"i"}, Usage: "Prompt before overwrite"},
	},
	Action: func(ctx context.Context, cmd *cli.Command) error {
		interactive := cmd.Bool("interactive")

		files := cmd.Args().Slice()
		if len(files) < 2 {
			return fmt.Errorf("missing file operand")
		}

		source := files[:len(files)-1]
		dest := files[len(files)-1]

		destInfo, err := os.Stat(dest)
		if err != nil {
			if os.IsNotExist(err) {
				if len(source) != 1 {
					return fmt.Errorf("target '%s' is not a directory", dest)
				}
				dest = filepath.Join(filepath.Dir(dest), filepath.Base(source[0]))
			} else {
				return err
			}
		} else if destInfo.IsDir() {
			for _, s := range source {
				dest = filepath.Join(dest, filepath.Base(s))
			}
		}

		for _, s := range source {
			if err := moveFile(s, dest, interactive); 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