rclone/cmd/link/link.go

45 lines
1.1 KiB
Go
Raw Normal View History

package link
import (
"context"
"fmt"
"github.com/rclone/rclone/cmd"
"github.com/rclone/rclone/fs/operations"
"github.com/spf13/cobra"
)
func init() {
2019-10-11 23:58:11 +08:00
cmd.Root.AddCommand(commandDefinition)
}
2019-10-11 23:58:11 +08:00
var commandDefinition = &cobra.Command{
Use: "link remote:path",
Short: `Generate public link to file/folder.`,
Long: `
rclone link will create or retrieve a public link to the given file or folder.
rclone link remote:path/to/file
rclone link remote:path/to/folder/
If successful, the last line of the output will contain the link. Exact
capabilities depend on the remote, but the link will always be created with
the least constraints e.g. no expiry, no password protection, accessible
without account.
`,
Run: func(command *cobra.Command, args []string) {
cmd.CheckArgs(1, 1, command, args)
fsrc, remote := cmd.NewFsFile(args[0])
cmd.Run(false, false, command, func() error {
link, err := operations.PublicLink(context.Background(), fsrc, remote)
if err != nil {
return err
}
2018-09-05 03:02:35 +08:00
if link != "" {
fmt.Println(link)
}
return nil
})
},
}