rclone/cmd/rmdirs/rmdirs.go
Nick Craig-Wood bff702a6f1 docs: group the global flags and make them appear on command and flags pages
This adds an additional parameter to the creation of each flag. This
specifies one or more flag groups. This **must** be set for global
flags and **must not** be set for local flags.

This causes flags.md to be built with sections to aid comprehension
and it causes the documentation pages for each command (and the
`--help`) to be built showing the flags groups as specified in the
`groups` annotation on the command.

See: https://forum.rclone.org/t/make-docs-for-mortals-not-only-rclone-gurus/39476/
2023-08-02 12:53:09 +01:00

53 lines
1.5 KiB
Go

// Package rmdir provides the rmdir command.
package rmdir
import (
"context"
"github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs/operations"
"github.com/spf13/cobra"
)
var (
leaveRoot = false
)
func init() {
cmd.Root.AddCommand(rmdirsCmd)
rmdirsCmd.Flags().BoolVarP(&leaveRoot, "leave-root", "", leaveRoot, "Do not remove root directory if empty")
}
var rmdirsCmd = &cobra.Command{
Use: "rmdirs remote:path",
Short: `Remove empty directories under the path.`,
Long: `
This recursively removes any empty directories (including directories
that only contain empty directories), that it finds under the path.
The root path itself will also be removed if it is empty, unless
you supply the ` + "`--leave-root`" + ` flag.
Use command [rmdir](/commands/rclone_rmdir/) to delete just the empty
directory given by path, not recurse.
This is useful for tidying up remotes that rclone has left a lot of
empty directories in. For example the [delete](/commands/rclone_delete/)
command will delete files but leave the directory structure (unless
used with option ` + "`--rmdirs`" + `).
To delete a path and any objects in it, use [purge](/commands/rclone_purge/)
command.
`,
Annotations: map[string]string{
"versionIntroduced": "v1.35",
"groups": "Important",
},
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fdst := cmd.NewFsDir(args)
cmd.Run(true, false, command, func() error {
return operations.Rmdirs(context.Background(), fdst, "", leaveRoot)
})
},
}