clap-ts 0.2.0 → 0.3.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/dist/parser.d.ts CHANGED
@@ -1,32 +1,53 @@
1
1
  /**
2
- * Argument parser - delegates core tokenizing to node:util parseArgs,
3
- * then layers on: env fallback, type coercion, count/append actions,
4
- * numArgs with defaultMissingValue, global args, kebab-to-camel mapping,
5
- * subcommand detection, and default values.
2
+ * Argument parser.
6
3
  *
7
- * node:util parseArgs handles:
8
- * --flag, --flag=value, --flag value, -f, -fvalue, -abc (combined booleans),
9
- * -- separator, positionals
4
+ * Tokenizes argv directly against the command's own arg definitions. This
5
+ * replaced node:util parseArgs, which re-validates its entire `options` object
6
+ * on every call (~170ns per option, regardless of argv length) and cannot
7
+ * express multi-value options, value terminators, or subcommand boundaries.
10
8
  *
11
- * We handle on top:
12
- * conflictsWith / requires (in validation.ts),
13
- * env variable fallback, action: 'append' (via multiple:true), action: 'count',
14
- * numArgs with defaultMissingValue, global args merge, valueParser enum validation
15
- * (in validation.ts), number type coercion, kebab-to-camel mapping,
16
- * required arg validation (in validation.ts), typo suggestions (in validation.ts),
17
- * valueDelimiter splitting, function valueParser, trailingVarArg, last,
18
- * allowHyphenValues, allowNegativeNumbers, inferLongArgs, defaultValueIf.
9
+ * Handled here: long/short/clustered flags, attached and `=` values, boolean
10
+ * negation, count and append actions, multi-token numArgs, optional values via
11
+ * defaultMissingValue, value delimiters, hyphen and negative-number values,
12
+ * positional assignment, trailing var args, `--` escape, subcommand
13
+ * boundaries, env fallback, conditional and static defaults, and
14
+ * kebab-to-camel key mapping.
15
+ *
16
+ * Constraint checks that need the whole picture (conflicts, requires, groups,
17
+ * possible values) live in validation.ts.
19
18
  */
20
- import type { ArgsDef, ParseResult, CommandDef } from './types.js';
21
- /** Get the raw argv slice (after the binary/script path). */
22
- export declare function getRawArgs(argv?: readonly string[]): string[];
19
+ import type { ArgDef, ArgsDef, ParseResult, CommandDef, PossibleValue } from './types.js';
23
20
  export declare class CliParseError extends Error {
24
21
  constructor(message: string);
25
22
  }
23
+ /** Convert kebab-case to camelCase: --config-path -> configPath */
24
+ export declare function kebabToCamel(s: string): string;
25
+ /**
26
+ * Get the raw argv slice (after the binary/script path). With `noBinaryName`
27
+ * the source is taken as-is, matching clap's Command::no_binary_name.
28
+ */
29
+ export declare function getRawArgs(argv?: readonly string[], noBinaryName?: boolean): string[];
30
+ /**
31
+ * The command's subcommands, building any lazy ones on first use and caching
32
+ * the result so the thunk runs at most once per command.
33
+ */
34
+ export declare function subCommandsOf(command: CommandDef<any>): Record<string, CommandDef<any>>;
35
+ /** Whether the command has any subcommand, without building the lazy ones. */
36
+ export declare function hasSubCommands(command: CommandDef<any>): boolean;
37
+ /**
38
+ * Normalize an arg's allowed values to PossibleValue records. Plain strings and
39
+ * PossibleValue objects can be mixed in the same list.
40
+ */
41
+ export declare function possibleValues(def: ArgDef): readonly PossibleValue[];
42
+ /** Whether a raw value matches this possible value, by name or alias. */
43
+ export declare function matchesPossibleValue(candidate: PossibleValue, value: string, ignoreCase: boolean): boolean;
44
+ export declare function coerceValue(value: string, def: ArgDef, argName: string): string | number | boolean;
26
45
  /**
27
46
  * Parse raw argument tokens against a command definition.
28
47
  *
29
- * Uses node:util parseArgs for core tokenizing, then layers on all clap-ts features.
48
+ * Stops at the first bare token matching a subcommand name or alias; the
49
+ * remaining tokens are returned as `subCommandArgs` for the caller to parse
50
+ * against that subcommand.
30
51
  */
31
52
  export declare function parseArgs(rawArgs: readonly string[], command: CommandDef): ParseResult;
32
53
  /**