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

Function search

cmd/search.go:51–94  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

49}
50
51func search(cmd *cobra.Command, args []string) (err error) {
52 if len(args) == 0 {
53 return invalidArgumentsErrorWithDetails("`search` requires a `query` argument", argumentErrorDetails("query"))
54 }
55 if len(args) > 2 {
56 return invalidArgumentsErrorWithDetails("`search` accepts at most one optional `path-scope` argument", mergeJSONErrorDetails(argumentErrorDetails("path-scope"), pathErrorDetails(args[2])))
57 }
58
59 var scope string
60 if len(args) == 2 {
61 scope = args[1]
62 if !strings.HasPrefix(scope, "/") {
63 return invalidArgumentsErrorWithDetails("`search` `path-scope` must begin with \"/\"", mergeJSONErrorDetails(argumentErrorDetails("path-scope"), pathErrorDetails(scope)))
64 }
65 }
66
67 opts, err := parseSearchOptions(cmd)
68 if err != nil {
69 return err
70 }
71 arg := newSearchV2Arg(args[0], scope, opts)
72
73 dbx := filesNewFunc(config)
74 res, err := dbx.SearchV2Context(currentContext(), arg)
75 if err != nil {
76 return err
77 }
78
79 var entries []files.IsMetadata
80 entries = appendSearchMatches(entries, res.Matches, opts.limit)
81
82 for res.HasMore && !searchLimitReached(entries, opts.limit) {
83 contArg := files.NewSearchV2ContinueArg(res.Cursor)
84 res, err = dbx.SearchContinueV2Context(currentContext(), contArg)
85 if err != nil {
86 return err
87 }
88 entries = appendSearchMatches(entries, res.Matches, opts.limit)
89 }
90
91 sortEntries(entries, opts.list)
92
93 return renderSearchOutput(cmd, args[0], scope, entries, opts)
94}
95
96func parseSearchOptions(cmd *cobra.Command) (searchCommandOptions, error) {
97 content, _ := cmd.Flags().GetBool("content")

Calls 13

argumentErrorDetailsFunction · 0.85
mergeJSONErrorDetailsFunction · 0.85
pathErrorDetailsFunction · 0.85
parseSearchOptionsFunction · 0.85
newSearchV2ArgFunction · 0.85
currentContextFunction · 0.85
appendSearchMatchesFunction · 0.85
searchLimitReachedFunction · 0.85
sortEntriesFunction · 0.85
renderSearchOutputFunction · 0.85
SearchV2ContextMethod · 0.65