MCPcopy Create free account
hub / github.com/dropbox/dbxcli / shareLinkCreate

Function shareLinkCreate

cmd/share_link_create.go:50–114  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

48}
49
50func shareLinkCreate(cmd *cobra.Command, args []string) error {
51 if len(args) != 1 {
52 return invalidArgumentsErrorWithDetails("`share-link create` requires a `path` argument", argumentErrorDetails("path"))
53 }
54
55 path, err := validatePath(args[0])
56 if err != nil {
57 return err
58 }
59 if path == "" {
60 return invalidArgumentsErrorWithDetails("cannot create a shared link for Dropbox root", mergeJSONErrorDetails(operationErrorDetails("share_link_create"), pathErrorDetails("/")))
61 }
62
63 opts, err := parseShareLinkCreateOptions(cmd)
64 if err != nil {
65 return err
66 }
67
68 dbx := newSharedLinkClient(config)
69 link, err := createSharedLink(dbx, path, opts)
70 usedExisting := false
71 if err != nil {
72 link, err = existingSharedLink(dbx, path, err)
73 if err != nil {
74 return withJSONErrorDetails(err, operationErrorDetails("share_link_create"), pathErrorDetails(path))
75 }
76 link, err = applyExistingSharedLinkCreateOptions(dbx, link, opts)
77 if err != nil {
78 return withJSONErrorDetails(err, operationErrorDetails("share_link_create"), pathErrorDetails(path))
79 }
80 usedExisting = true
81 }
82
83 url, ok := sharedLinkURL(link)
84 if !ok {
85 return withJSONErrorDetails(errors.New("shared link response did not include a URL"), operationErrorDetails("share_link_create"), pathErrorDetails(path))
86 }
87
88 out := commandOutput(cmd)
89 if usedExisting {
90 commandVerboseStatus(cmd, "Using existing shared link for %s", path)
91 } else {
92 commandVerboseStatus(cmd, "Created shared link for %s", path)
93 }
94
95 result, ok := shareLinkJSONMetadataFromDropbox(link)
96 if !ok {
97 return withJSONErrorDetails(errors.New("found unknown shared link type"), operationErrorDetails("share_link_create"), pathErrorDetails(path))
98 }
99
100 status := shareLinkJSONStatusCreated
101 if usedExisting {
102 status = shareLinkJSONStatusExisting
103 }
104
105 return out.Render(func(w io.Writer) error {
106 _, err := fmt.Fprintln(w, url)
107 return err

Calls 15

argumentErrorDetailsFunction · 0.85
validatePathFunction · 0.85
mergeJSONErrorDetailsFunction · 0.85
operationErrorDetailsFunction · 0.85
pathErrorDetailsFunction · 0.85
createSharedLinkFunction · 0.85
existingSharedLinkFunction · 0.85
withJSONErrorDetailsFunction · 0.85
sharedLinkURLFunction · 0.85