@kaynooo/cli-kit 0.17.0 → 0.19.0
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/README.md +1 -1
- package/package.json +1 -1
- package/src/cli.ts +10 -2
- package/src/limit.ts +1 -1
- package/src/shell.ts +7 -0
package/README.md
CHANGED
|
@@ -56,7 +56,7 @@ On a terminal, help has bold `Usage:`, `Commands:` and `Options:` headers, comma
|
|
|
56
56
|
- `--help` lists the commands under `Commands:`, then a heading per `group` a command names (`{ summary, group: 'Admin', run }`), then the level's `Options:` and the `Examples:` the CLI or a group's `examples` give (`['ft ci', ['ft ci HEAD~1', 'the commit before']]`, a note shown dimmed after `#`); a command's own examples go to `parse(args, usage, options, { examples })`, shown under its options.
|
|
57
57
|
- `replaces` on the CLI or in `parse`'s settings (`'sed -n N,Mp, grep -n chains'`) adds an `Instead of:` line under the usage. With `KIT_HELP=json` in the environment, `--help` prints `{synopsis, summary, replaces?, examples}` instead, the usage's first line split at its first `: `, which is how `cli list` reads every bin.
|
|
58
58
|
- `runHint(command, effect?)` words the hint of a refusal that a command resolves, ``run `ft take 12 --take-stale` to take it over``, so every CLI writes it alike: `fail(message, 1, runHint('ft take 12 --take-stale', 'take it over'))`. `printHint(hint)` prints the `hint:` line under a refusal a command prints itself (one issue of several refused).
|
|
59
|
-
- `limitOptions(fallback)` is the `--limit <n>` and `--full` flags of a listing, `limitOf(values, fallback)` the row count they ask for (Infinity with `--full`; with `json: true` in the values, Infinity unless `--limit` is given, so JSON is never cut on its own), and `capped(rows, limit)` the first rows plus the footer `N more, rerun with --full` when some are left out.
|
|
59
|
+
- `limitOptions(fallback)` is the `--limit <n>` (`-n`) and `--full` flags of a listing, `limitOf(values, fallback)` the row count they ask for (Infinity with `--full`; with `json: true` in the values, Infinity unless `--limit` is given, so JSON is never cut on its own), and `capped(rows, limit)` the first rows plus the footer `N more, rerun with --full` when some are left out.
|
|
60
60
|
- `jsonOption(holds?)` is the `--json` flag, worded `print JSON` or `print JSON: <holds>` alike in every CLI, and `printJson(value)` prints the value indented on stdout, bare, with no envelope. Under `--json` runMain and runCli print a thrown error as `{"error", "hint"?, "cause"?}` on stderr instead of the `error:` line, its exit code unchanged; `printJsonError(message, hint?, cause?)` prints one for a command reporting a failure itself.
|
|
61
61
|
- `stripAnsi(text)` removes colour and cursor codes, and `distance(a, b)` is the edit distance between two names.
|
|
62
62
|
- `table(rows, { cellWidth, header })` also flattens each cell's line breaks and cuts it to `cellWidth`, and with `header` prints the first row bold on a terminal; and `formatDuration(ms)` formats milliseconds like `formatSeconds` but with one decimal under a minute (`0.3s`).
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-kit",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"description": "What every @kaynooo CLI shares: argument parsing with --help, a command dispatcher with typo hints and shell completion, and output formatting.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
package/src/cli.ts
CHANGED
|
@@ -395,8 +395,16 @@ async function candidates(scope: Scope, defaultCommand: string | undefined, word
|
|
|
395
395
|
command = commands[aliases?.[word] ?? word]
|
|
396
396
|
}
|
|
397
397
|
|
|
398
|
-
if (listing)
|
|
399
|
-
|
|
398
|
+
if (listing) {
|
|
399
|
+
const own = await Promise.all(Object.entries(shown(commands)).map(async ([name, { summary }]) => `${name}\t${await resolveSummary(summary)}`))
|
|
400
|
+
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand]
|
|
401
|
+
// What the default command takes as its first positional is typed here too, `athome <project>`; a name a command already has is left out.
|
|
402
|
+
const values = fallback !== undefined && 'run' in fallback ? await leafCandidates(fallback.run, [word]) : []
|
|
403
|
+
|
|
404
|
+
const valueOf = (line: string) => line.slice(0, line.includes('\t') ? line.indexOf('\t') : undefined)
|
|
405
|
+
|
|
406
|
+
return [...own, ...values.filter(line => line !== FILES && !(valueOf(line) in commands))]
|
|
407
|
+
}
|
|
400
408
|
|
|
401
409
|
if (command === undefined) {
|
|
402
410
|
const fallback = defaultCommand === undefined ? undefined : commands[defaultCommand]
|
package/src/limit.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { badUsage, wholeNumber } from './args'
|
|
|
3
3
|
// The `--limit` and `--full` flags every listing words alike, `fallback` being the rows shown without either.
|
|
4
4
|
export function limitOptions(fallback: number) {
|
|
5
5
|
return {
|
|
6
|
-
limit: { type: 'string', description: `show at most this many rows, the rest counted (${fallback})` },
|
|
6
|
+
limit: { type: 'string', short: 'n', description: `show at most this many rows, the rest counted (${fallback})` },
|
|
7
7
|
full: { type: 'boolean', description: 'show every row' },
|
|
8
8
|
} as const
|
|
9
9
|
}
|
package/src/shell.ts
CHANGED
|
@@ -162,6 +162,13 @@ export function splitCommand(command: string): Piece[] {
|
|
|
162
162
|
continue
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
+
// A backquoted body is read whole, as its own separators split nothing of the command around it.
|
|
166
|
+
if (char === '`') {
|
|
167
|
+
i = closingBackquote(command, i)
|
|
168
|
+
|
|
169
|
+
continue
|
|
170
|
+
}
|
|
171
|
+
|
|
165
172
|
if (char === '#' && startsComment(command, i)) {
|
|
166
173
|
const newline = command.indexOf('\n', i)
|
|
167
174
|
const end = newline === -1 ? command.length : newline
|