MCPcopy
hub / github.com/upstash/context7 / resolveCommand

Function resolveCommand

packages/cli/src/commands/docs.ts:52–115  ·  view source on GitHub ↗
(
  library: string,
  query: string | undefined,
  options: { json?: boolean }
)

Source from the content-addressed store, hash-verified

50}
51
52async function resolveCommand(
53 library: string,
54 query: string | undefined,
55 options: { json?: boolean }
56): Promise<void> {
57 trackEvent("command", { name: "library" });
58
59 const spinner = isTTY ? ora(`Searching for "${library}"...`).start() : null;
60 const accessToken = getAccessToken();
61
62 let data;
63 try {
64 data = await resolveLibrary(library, query, accessToken);
65 } catch (err) {
66 spinner?.fail(`Error: ${err instanceof Error ? err.message : String(err)}`);
67 if (!spinner) log.error(err instanceof Error ? err.message : String(err));
68 process.exitCode = 1;
69 return;
70 }
71
72 if (data.error) {
73 spinner?.fail(data.message || data.error);
74 if (!spinner) log.error(data.message || data.error);
75 process.exitCode = 1;
76 return;
77 }
78
79 if (!data.results || data.results.length === 0) {
80 spinner?.warn(`No libraries found matching "${library}"`);
81 if (!spinner) log.warn(`No libraries found matching "${library}"`);
82 return;
83 }
84
85 const results = data.results;
86
87 spinner?.stop();
88
89 if (options.json) {
90 console.log(JSON.stringify(results, null, 2));
91 return;
92 }
93
94 log.blank();
95
96 if (data.searchFilterApplied) {
97 log.warn(
98 "Your results only include libraries matching your teamspace's library filters. To adjust quality thresholds or blocked libraries, update your filters at https://context7.com/dashboard?tab=policies"
99 );
100 log.blank();
101 }
102
103 for (let i = 0; i < results.length; i++) {
104 log.plain(formatLibraryResult(results[i], i));
105 log.blank();
106 }
107
108 if (isTTY && results.length > 0) {
109 const best = results[0];

Callers 1

registerDocsCommandsFunction · 0.85

Calls 4

trackEventFunction · 0.85
getAccessTokenFunction · 0.85
resolveLibraryFunction · 0.85
formatLibraryResultFunction · 0.85

Tested by

no test coverage detected