github.com/xhghs/rclone@v1.51.1-0.20200430155106-e186a28cced8/cmd/link/link.go (about) 1 package link 2 3 import ( 4 "context" 5 "fmt" 6 7 "github.com/rclone/rclone/cmd" 8 "github.com/rclone/rclone/fs/operations" 9 "github.com/spf13/cobra" 10 ) 11 12 func init() { 13 cmd.Root.AddCommand(commandDefinition) 14 } 15 16 var commandDefinition = &cobra.Command{ 17 Use: "link remote:path", 18 Short: `Generate public link to file/folder.`, 19 Long: ` 20 rclone link will create or retrieve a public link to the given file or folder. 21 22 rclone link remote:path/to/file 23 rclone link remote:path/to/folder/ 24 25 If successful, the last line of the output will contain the link. Exact 26 capabilities depend on the remote, but the link will always be created with 27 the least constraints – e.g. no expiry, no password protection, accessible 28 without account. 29 `, 30 Run: func(command *cobra.Command, args []string) { 31 cmd.CheckArgs(1, 1, command, args) 32 fsrc, remote := cmd.NewFsFile(args[0]) 33 cmd.Run(false, false, command, func() error { 34 link, err := operations.PublicLink(context.Background(), fsrc, remote) 35 if err != nil { 36 return err 37 } 38 if link != "" { 39 fmt.Println(link) 40 } 41 return nil 42 }) 43 }, 44 }