2018-03-29 07:10:19 +00:00
|
|
|
package link
|
|
|
|
|
|
|
|
import (
|
2019-06-17 08:34:30 +00:00
|
|
|
"context"
|
2018-03-29 07:10:19 +00:00
|
|
|
"fmt"
|
|
|
|
|
2019-07-28 17:47:38 +00:00
|
|
|
"github.com/rclone/rclone/cmd"
|
|
|
|
"github.com/rclone/rclone/fs/operations"
|
2018-03-29 07:10:19 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-10-11 15:58:11 +00:00
|
|
|
cmd.Root.AddCommand(commandDefinition)
|
2018-03-29 07:10:19 +00:00
|
|
|
}
|
|
|
|
|
2019-10-11 15:58:11 +00:00
|
|
|
var commandDefinition = &cobra.Command{
|
2018-03-29 07:10:19 +00:00
|
|
|
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 {
|
2019-06-17 08:34:30 +00:00
|
|
|
link, err := operations.PublicLink(context.Background(), fsrc, remote)
|
2018-03-29 07:10:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-09-04 19:02:35 +00:00
|
|
|
if link != "" {
|
|
|
|
fmt.Println(link)
|
|
|
|
}
|
2018-03-29 07:10:19 +00:00
|
|
|
return nil
|
|
|
|
})
|
|
|
|
},
|
|
|
|
}
|