icore 1.0.10 → 1.0.12

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/dist/options.d.ts CHANGED
@@ -35,9 +35,12 @@ export type StringOption<TChoices extends readonly string[] = readonly string[]>
35
35
  /**
36
36
  * Declarative boolean flag contract.
37
37
  *
38
- * Boolean options accept flag form and explicit `true` / `false` values.
38
+ * Boolean options accept flag form and explicit `true` / `false` values unless
39
+ * flag syntax is enforced.
39
40
  */
40
- export type BooleanOption = OptionBase<'boolean', boolean>;
41
+ export type BooleanOption = OptionBase<'boolean', boolean> & {
42
+ syntax?: 'flag';
43
+ };
41
44
  /**
42
45
  * Declarative number option contract.
43
46
  *
package/dist/options.js CHANGED
@@ -71,7 +71,7 @@ function parseOptionValue(name, definition, value) {
71
71
  return parseStringOption(name, definition, value);
72
72
  }
73
73
  if (definition.type === 'boolean') {
74
- return parseBooleanOption(name, value);
74
+ return parseBooleanOption(name, definition, value);
75
75
  }
76
76
  return parseNumberOption(name, definition, value);
77
77
  }
@@ -103,7 +103,13 @@ function parseStringOption(name, definition, value) {
103
103
  assertChoice(name, definition.choices, value);
104
104
  return value;
105
105
  }
106
- function parseBooleanOption(name, value) {
106
+ function parseBooleanOption(name, definition, value) {
107
+ if (definition.syntax === 'flag') {
108
+ if (value === true) {
109
+ return true;
110
+ }
111
+ throw new Error(`Expected '--${name}' as boolean flag`);
112
+ }
107
113
  if (value === true || value === 'true') {
108
114
  return true;
109
115
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "icore",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Declarative command line interface mechanics for Node.js",
5
5
  "keywords": [
6
6
  "command-line",
package/readme.md CHANGED
@@ -10,7 +10,7 @@ Small dependency-free command line interface mechanics for [Node.js®](https://n
10
10
  Supports a practical GNU-style option syntax:
11
11
 
12
12
  - long options: `--name value`, `--name=value`;
13
- - boolean flags: `--flag`, `--flag=true`, `--flag=false`, `--no-flag`;
13
+ - boolean flags: `--flag`, `--flag=true`, `--flag=false`, `--no-flag` by default;
14
14
  - short aliases: `-f`, `-n value`;
15
15
  - option terminator: `--`.
16
16
 
@@ -74,8 +74,8 @@ Result:
74
74
  }
75
75
  ```
76
76
 
77
- When an option schema is provided, boolean options are parsed as flag-only
78
- options without consuming the following positional argument:
77
+ When an option schema is provided, boolean options are parsed as flags without
78
+ consuming the following positional argument:
79
79
 
80
80
  ```ts
81
81
  const argv = parseArgv([
@@ -455,6 +455,21 @@ Invalid explicit values are rejected:
455
455
  `--uppercase false` keeps `--uppercase` as `true` and leaves `false` as a positional
456
456
  argument.
457
457
 
458
+ Use `syntax: 'flag'` when a boolean option should accept only flag form:
459
+
460
+ ```ts
461
+ const schema = {
462
+ uppercase: {
463
+ type: 'boolean',
464
+ default: false,
465
+ syntax: 'flag'
466
+ }
467
+ } as const;
468
+ ```
469
+
470
+ With `syntax: 'flag'`, `--uppercase` is accepted, while `--uppercase=true`,
471
+ `--uppercase=false`, and `--no-uppercase` are rejected.
472
+
458
473
  ### `type: 'number'`
459
474
 
460
475
  ```ts
@@ -552,8 +567,9 @@ Attached short values such as `-nvalue` and grouped short booleans such as
552
567
  compatibility.
553
568
 
554
569
  Negated syntax such as `--no-cache` is interpreted as `cache: false` when
555
- `cache` is a known boolean option. Unknown negated options and negation for
556
- string or number options are rejected.
570
+ `cache` is a known boolean option without `syntax: 'flag'`. Unknown negated
571
+ options, negation for string or number options, and negation for flag-only
572
+ boolean options are rejected.
557
573
 
558
574
  ## Error Messages
559
575