Skip to content

Commit 9c8065e

Browse files
Merge branch 'main' into copilot/add-auto-completion-support
2 parents 986935b + e284bda commit 9c8065e

23 files changed

Lines changed: 785 additions & 779 deletions

docs/guide/02_commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const authenticatedDeploy = commandChained(
8787
long: "token",
8888
type: type("secret"),
8989
description: "API token",
90-
defaultIfNotSpecified: function () {
90+
fallbackValueIfAbsent: function () {
9191
const t = process.env.API_TOKEN;
9292
if (!t) throw new Error("API_TOKEN env var is required");
9393
return t;

docs/guide/03_options.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@ const output = optionSingleValue({
4444
short: "o",
4545
type: typePath(),
4646
description: "Output directory",
47-
defaultIfNotSpecified: () => "dist/",
47+
fallbackValueIfAbsent: () => "dist/",
4848
});
4949
// --output dist/ → "dist/"
5050
// --output=dist/ → "dist/"
5151
// -o dist/ → "dist/"
5252
// (absent) → "dist/"
5353
```
5454

55-
| Parameter | Type | Description |
56-
| ----------------------- | --------------------- | ---------------------------------------------------------------------------- |
57-
| `long` | `string` | Long option name |
58-
| `short` | `string?` | Short option name |
59-
| `type` | `Type<Value>` | Decoder for the value |
60-
| `description` | `string?` | Help text |
61-
| `hint` | `string?` | Short note in parentheses |
62-
| `defaultIfNotSpecified` | `() => Value` | Value when option is absent — **throw** to make it required |
63-
| `valueIfNothingInlined` | `() => Value?` | Value when option is present but has no inline value (e.g. `--output` alone) |
64-
| `aliases` | `{ longs?, shorts? }` | Additional names |
55+
| Parameter | Type | Description |
56+
| -------------------------- | --------------------- | ---------------------------------------------------------------------------- |
57+
| `long` | `string` | Long option name |
58+
| `short` | `string?` | Short option name |
59+
| `type` | `Type<Value>` | Decoder for the value |
60+
| `description` | `string?` | Help text |
61+
| `hint` | `string?` | Short note in parentheses |
62+
| `fallbackValueIfAbsent` | `() => Value` | Value when option is absent — **throw** to make it required |
63+
| `impliedValueIfNotInlined` | `() => Value?` | Value when option is present but has no inline value (e.g. `--output` alone) |
64+
| `aliases` | `{ longs?, shorts? }` | Additional names |
6565

6666
## `optionRepeatable` — collect multiple values
6767

docs/guide/06_run_as_cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const rootCmd = commandWithSubcommands(
6868
long: "db",
6969
type: typeUrl(),
7070
description: "Database URL",
71-
defaultIfNotSpecified: () => new URL("postgres://localhost/mydb"),
71+
fallbackValueIfAbsent: () => new URL("postgres://localhost/mydb"),
7272
}),
7373
},
7474
positionals: [],

src/lib/Command.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,11 @@ export function command<Context, Result>(
146146
const operationDecoder = operation.consumeAndMakeDecoder(readerArgs);
147147
const endPositional = readerArgs.consumePositional();
148148
if (endPositional !== undefined) {
149-
throw new TypoError(
150-
new TypoText(
151-
new TypoString(`Unexpected argument: `),
152-
new TypoString(`"${endPositional}"`, typoStyleQuote),
153-
),
154-
);
149+
const errorText = new TypoText();
150+
errorText.push(new TypoString(`Unexpected argument: `));
151+
errorText.push(new TypoString(`"${endPositional}"`, typoStyleQuote));
152+
errorText.push(new TypoString(`.`));
153+
throw new TypoError(errorText);
155154
}
156155
return {
157156
generateUsage: () => generateUsageLeaf(information, operation),
@@ -376,9 +375,7 @@ function generateUsageLeaf(
376375
): UsageCommand {
377376
const { positionals, options } = operation.generateUsage();
378377
return {
379-
segments: positionals.map((positional) => ({
380-
positional: positional.label,
381-
})),
378+
segments: positionals.map((p) => ({ positional: p.label })),
382379
information,
383380
positionals,
384381
subcommands: [],

0 commit comments

Comments
 (0)