2022-08-28 11:21:57 +00:00
|
|
|
// Package mkdir provides the mkdir command.
|
2016-08-05 16:12:27 +00:00
|
|
|
package mkdir
|
|
|
|
|
|
|
|
import (
|
2019-06-17 08:34:30 +00:00
|
|
|
"context"
|
2020-07-08 10:56:09 +00:00
|
|
|
"strings"
|
2019-06-17 08:34:30 +00:00
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/cmd"
|
2020-07-08 10:56:09 +00:00
|
|
|
"github.com/rclone/rclone/fs"
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2016-08-05 16:12:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-10-11 15:58:11 +00:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2016-08-05 16:12:27 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 15:58:11 +00:00
|
|
|
var commandDefinition = &cobra.Command{
|
2016-08-05 16:12:27 +00:00
|
|
|
Use: "mkdir remote:path",
|
|
|
|
Short: `Make the path if it doesn't already exist.`,
|
|
|
|
Run: func(command *cobra.Command, args []string) {
|
|
|
|
cmd.CheckArgs(1, 1, command, args)
|
2018-05-07 16:58:16 +00:00
|
|
|
fdst := cmd.NewFsDir(args)
|
2020-07-08 10:56:09 +00:00
|
|
|
if !fdst.Features().CanHaveEmptyDirectories && strings.Contains(fdst.Root(), "/") {
|
|
|
|
fs.Logf(fdst, "Warning: running mkdir on a remote which can't have empty directories does nothing")
|
|
|
|
}
|
2016-12-04 16:52:24 +00:00
|
|
|
cmd.Run(true, false, command, func() error {
|
2019-06-17 08:34:30 +00:00
|
|
|
return operations.Mkdir(context.Background(), fdst, "")
|
2016-08-05 16:12:27 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|