@somewhere-cloud/cli 0.38.159 → 0.38.160

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.38.160
4
+
5
+ - Find complete examples with `somewhere docs example`. Search returns an outline and the best matching section in full. Add `--include-api` to include API reference topics.
6
+
3
7
  ## 0.38.159
4
8
 
5
9
  - Docs summaries show how much of the topic you received and give commands for the remaining sections, the whole topic, and search. The same summary goes to a terminal, pipe or file. Use `somewhere docs <topic> --full` when you need the complete topic.
@@ -88055,13 +88055,15 @@ function renderDocsIndex(pages, groups) {
88055
88055
  lines.push("", "Quick links:");
88056
88056
  for (const [name, entry] of Object.entries(TOPICS))
88057
88057
  lines.push(` ${name.padEnd(10)} ${entry.blurb}`);
88058
- lines.push("", `Open a topic: ${cliInvocation()} docs <topic> `, `Open a section: ${cliInvocation()} docs <topic> --section <id>`, `Whole topic: ${cliInvocation()} docs <topic> --full`, `Search all docs: ${cliInvocation()} docs --search "<words>"`, `Download Markdown: ${cliInvocation()} docs pull`, `Full manual: ${cliInvocation()} docs --full (very large)`);
88058
+ lines.push("", `Open a topic: ${cliInvocation()} docs <topic> `, `Open a section: ${cliInvocation()} docs <topic> --section <id>`, `Whole topic: ${cliInvocation()} docs <topic> --full`, `Search all docs: ${cliInvocation()} docs --search "<words>" [--include-api]`, `Examples: ${cliInvocation()} docs example [slug]`, `Download Markdown: ${cliInvocation()} docs pull`, `Full manual: ${cliInvocation()} docs --full (very large)`);
88059
88059
  return lines.join("\n") + "\n";
88060
88060
  }
88061
- async function fetchDocsSearch(query, topic) {
88061
+ async function fetchDocsSearch(query, topic, includeApi) {
88062
88062
  const params = new URLSearchParams({ q: query });
88063
88063
  if (topic)
88064
88064
  params.set("topic", topic);
88065
+ if (includeApi)
88066
+ params.set("include_api", "true");
88065
88067
  const res = await fetchWithProxy(`${DOCS_BASE2}${DOCS_SEARCH_PATH}?${params}`, {
88066
88068
  headers: { "User-Agent": "somewhere-cli" }
88067
88069
  });
@@ -88130,6 +88132,8 @@ async function fetchPublishedDocsView(topic, view) {
88130
88132
  const params = new URLSearchParams({ view: view.kind === "default" ? "summary" : view.kind });
88131
88133
  if (view.kind === "section")
88132
88134
  params.set("section", view.id);
88135
+ if (view.kind === "example" && view.slug)
88136
+ params.set("slug", view.slug);
88133
88137
  const response = await fetchWithProxy(`${DOCS_BASE2}/docs/${encodeURIComponent(topic.toLowerCase())}.txt?${params}`);
88134
88138
  if (!response.ok || !response.headers.get("content-type")?.includes("application/json"))
88135
88139
  return null;
@@ -88148,15 +88152,17 @@ function displayDocs(content) {
88148
88152
  return withNewline(hasViewNotice(content) ? content.replace(/^\[docs\][^\n]*\n/, "") : content);
88149
88153
  }
88150
88154
  function registerDocs(program2) {
88151
- program2.command("docs [topic] [terms...]").description(`Read platform docs. No login needed \u2014 every topic is public. With no topic, prints the topic index. Search with \`${cliInvocation()} docs --search "<words>"\`. Quick topics: ` + Object.keys(TOPICS).join(", ") + `. Example manual topic: \`${cliInvocation()} docs sw.db\`.`).option("--list", `List available topics (the same index bare \`${cliInvocation()} docs\` prints)`).option("--full", "Print the complete topic; with no topic, print the full manual").option("--search <words>", "Search matching sections across all live docs topics").option("--section <id>", "Print one section of a topic (ids are listed in the summary)").option("--json", "Print the selected document in a JSON envelope").addHelpText("after", `
88155
+ program2.command("docs [topic] [terms...]").description(`Read platform docs. No login needed \u2014 every topic is public. With no topic, prints the topic index. Search with \`${cliInvocation()} docs --search "<words>"\`. Quick topics: ` + Object.keys(TOPICS).join(", ") + `. Example manual topic: \`${cliInvocation()} docs sw.db\`.`).option("--list", `List available topics (the same index bare \`${cliInvocation()} docs\` prints)`).option("--full", "Print the complete topic; with no topic, print the full manual").option("--search <words>", "Find matching builder docs and read the top section whole").option("--include-api", "Include the HTTP API catalog and developer tool reference in search").option("--section <id>", "Print one section of a topic (ids are listed in the summary)").option("--json", "Print the selected document in a JSON envelope").addHelpText("after", `
88152
88156
  Examples:
88153
88157
  ${cliInvocation()} docs # topic index
88154
- ${cliInvocation()} docs --search "magic link" # matching sections across every topic
88158
+ ${cliInvocation()} docs --search "magic link" # matching builder docs
88155
88159
  ${cliInvocation()} docs pull # download Markdown into .somewhere/docs/
88156
88160
  ${cliInvocation()} docs sw.auth # topic summary when the whole topic is long
88157
88161
  ${cliInvocation()} docs sw.auth --full # complete topic for a terminal, pipe or file
88158
88162
  ${cliInvocation()} docs sw.auth setRoles # search within this topic
88159
88163
  ${cliInvocation()} docs sw.auth --section <id> # one section
88164
+ ${cliInvocation()} docs example team-board # one complete example
88165
+ ${cliInvocation()} docs example # list available examples
88160
88166
  ${cliInvocation()} docs --full # the whole manual (very large)
88161
88167
 
88162
88168
  \`${cliInvocation()} docs search\` with no term opens the search primitive topic.
@@ -88167,8 +88173,33 @@ Examples:
88167
88173
  return;
88168
88174
  }
88169
88175
  warnIfDocsNewerThanCli();
88176
+ if (topic === "example" && opts.search === void 0) {
88177
+ if (terms.length > 1 || opts.list || opts.section !== void 0 || opts.includeApi || opts.full) {
88178
+ error(`Use docs ${topic} [slug] with optional --json.`);
88179
+ process.exitCode = 1;
88180
+ return;
88181
+ }
88182
+ try {
88183
+ const result = await fetchPublishedDocsView(topic, { kind: topic, slug: terms[0] });
88184
+ if (!result || result.view !== topic) {
88185
+ throw new Error(`Could not read docs ${topic} at ${DOCS_BASE2}.`);
88186
+ }
88187
+ await warnIfLocalDocsOlder(result.version);
88188
+ const content = withNewline(result.content);
88189
+ if (opts.json)
88190
+ printJson({ topic: result.topic, view: result.view, complete: result.complete, content });
88191
+ else
88192
+ process.stdout.write(content);
88193
+ if (!result.complete)
88194
+ process.exitCode = 1;
88195
+ } catch (cause) {
88196
+ error(cause instanceof Error ? cause.message : String(cause), cause);
88197
+ process.exitCode = 1;
88198
+ }
88199
+ return;
88200
+ }
88170
88201
  if (topic === "pull") {
88171
- if (terms.length || opts.list || opts.full || opts.section !== void 0 || opts.search !== void 0) {
88202
+ if (terms.length || opts.list || opts.full || opts.section !== void 0 || opts.search !== void 0 || opts.includeApi) {
88172
88203
  error("docs pull accepts only --json.");
88173
88204
  process.exitCode = 1;
88174
88205
  return;
@@ -88200,9 +88231,14 @@ Examples:
88200
88231
  }
88201
88232
  const searching = opts.search !== void 0 || terms.length > 0;
88202
88233
  const within = topic && topic !== "search" ? ALIASES[topic] ?? topic : void 0;
88234
+ if (opts.includeApi && !searching) {
88235
+ error("--include-api requires a docs search.");
88236
+ process.exitCode = 1;
88237
+ return;
88238
+ }
88203
88239
  if (searching) {
88204
88240
  if (opts.full || opts.section !== void 0 || opts.list || opts.search !== void 0 && topic !== void 0) {
88205
- error('Use docs --search "<words>" with optional --json.');
88241
+ error('Use docs --search "<words>" with optional --include-api and --json.');
88206
88242
  process.exitCode = 1;
88207
88243
  return;
88208
88244
  }
@@ -88213,7 +88249,7 @@ Examples:
88213
88249
  return;
88214
88250
  }
88215
88251
  try {
88216
- const { results, total, version: version2 } = await fetchDocsSearch(query, within);
88252
+ const { results, total, version: version2 } = await fetchDocsSearch(query, within, opts.includeApi);
88217
88253
  await warnIfLocalDocsOlder(version2);
88218
88254
  if (opts.json) {
88219
88255
  printJson({ query, ...within ? { topic: within } : {}, count: results.length, total, results });
@@ -88225,12 +88261,11 @@ Examples:
88225
88261
  }
88226
88262
  for (const result of results) {
88227
88263
  console.log(`${result.topic}${result.section ? ` \u203A ${result.section}` : ""} ${dim(result.heading ?? result.title)}`);
88228
- console.log(`
88229
- ${result.snippet}
88230
-
88231
- ${dim(result.open)}
88232
- `);
88264
+ console.log(dim(result.open));
88233
88265
  }
88266
+ if (results[0].snippet)
88267
+ console.log(`
88268
+ ${results[0].snippet}`);
88234
88269
  if (results.length < total) {
88235
88270
  console.log(dim(`Showing ${results.length} of ${total} matches. Add a word to narrow the search.`));
88236
88271
  }