argsbarg 1.0.1 → 1.1.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/CHANGELOG.md CHANGED
@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.1.0] - 2026-04-23
11
+
12
+
10
13
  ## [1.0.1] - 2026-04-22
11
14
 
12
15
  ### Changed
@@ -40,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
40
43
  - Migrate schemas: rename every `children` property to **`commands`**; move positional definitions to **`CliPositional`** objects on `positionals` and strip `positional` / `argMin` / `argMax` from flag definitions under `options` (flags only carry `name`, `description`, `kind`, and optional `shortName`).
41
44
  - Imports: use `CliPositional` where needed; replace `CliOptionDef` with `CliOption` or `CliPositional` as appropriate.
42
45
 
43
- [Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v1.0.1...HEAD
46
+ [Unreleased]: https://github.com/bdombro/bun-argsbarg/compare/v1.1.0...HEAD
47
+ [1.1.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.1.0
44
48
  [1.0.1]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.0.1
45
49
  [1.0.0]: https://github.com/bdombro/bun-argsbarg/releases/tag/v1.0.0
package/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  [![GitHub](https://img.shields.io/badge/GitHub-bdombro%2Fbun--argsbarg-181717?logo=github)](https://github.com/bdombro/bun-argsbarg)
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
- [![npm version](https://img.shields.io/npm/v/bun-argsbarg.svg)](https://www.npmjs.com/package/argsbarg)
6
+ [![npm version](https://img.shields.io/npm/v/argsbarg.svg)](https://www.npmjs.com/package/argsbarg)
7
7
  [![Bun](https://img.shields.io/badge/Bun-%23000000.svg?logo=bun&logoColor=white)](https://bun.sh)
8
8
 
9
9
  Build beautiful, well-behaved CLI apps with Bun — **no third-party runtime dependencies**.
package/index.d.ts ADDED
@@ -0,0 +1,141 @@
1
+ // Generated by dts-bundle-generator v9.5.1
2
+
3
+ /**
4
+ * Option kinds: presence (boolean flag), string (free-form text), or number (strict double).
5
+ */
6
+ export declare enum CliOptionKind {
7
+ /** Boolean flag: no value token (may be implicit `"1"` when set). */
8
+ Presence = "presence",
9
+ /** Free-form string value. */
10
+ String = "string",
11
+ /** Strict floating-point value (parsed at validation time). */
12
+ Number = "number"
13
+ }
14
+ /**
15
+ * When fallbackCommand is used for missing or unknown top-level tokens.
16
+ * Only the program root may set a non-default mode or a non-nil fallbackCommand.
17
+ */
18
+ export declare enum CliFallbackMode {
19
+ /**
20
+ * If argv has no first subcommand, route to `fallbackCommand`; if the first token is unknown, error.
21
+ */
22
+ MissingOnly = "missingOnly",
23
+ /**
24
+ * If argv has no first subcommand or the first token is not a known child, route to `fallbackCommand`.
25
+ */
26
+ MissingOrUnknown = "missingOrUnknown",
27
+ /**
28
+ * If the first token is present but not a known child, route to `fallbackCommand`.
29
+ * When the first subcommand token is missing (empty argv), do not use fallback (implicit root help).
30
+ */
31
+ UnknownOnly = "unknownOnly"
32
+ }
33
+ /**
34
+ * A named flag or value option (`--long`, `-short`), listed on `CliCommand.options`.
35
+ */
36
+ export interface CliOption {
37
+ /** Option name (e.g., "name", "verbose"). */
38
+ name: string;
39
+ /** Description shown in help. */
40
+ description: string;
41
+ /** Option kind: presence flag, string value, or number value. */
42
+ kind: CliOptionKind;
43
+ /** Short option character (e.g., 'n' for -n). */
44
+ shortName?: string;
45
+ }
46
+ /**
47
+ * An ordered positional argument slot, listed on `CliCommand.positionals`.
48
+ */
49
+ export interface CliPositional {
50
+ /** Positional name (used in help and error messages). */
51
+ name: string;
52
+ /** Description shown in help. */
53
+ description: string;
54
+ /** Value kind for each consumed token. */
55
+ kind: CliOptionKind;
56
+ /**
57
+ * Minimum number of values required (default 1).
58
+ * Use `0` for an optional slot when paired with `argMax: 1`, or a varargs tail with `argMax: 0`.
59
+ */
60
+ argMin?: number;
61
+ /**
62
+ * Maximum number of values (`1` = a single required or optional word; default 1). Use `0` for an
63
+ * unbounded varargs tail (must be the last slot in the command’s `positionals` list).
64
+ */
65
+ argMax?: number;
66
+ }
67
+ /**
68
+ * A command node: routing group (has commands) or leaf (has handler).
69
+ *
70
+ * The value passed to cliRun is the program root: name is the app/binary name,
71
+ * commands are top-level subcommands, options are global flags.
72
+ * The root must not set handler or declare positionals (validated at startup).
73
+ */
74
+ export interface CliCommand {
75
+ /** Program or command key (e.g., "myapp", "stat", "owner"). */
76
+ key: string;
77
+ /** Short description shown in help. */
78
+ description: string;
79
+ /** Additional notes shown in help (supports {app} placeholder). */
80
+ notes?: string;
81
+ /** Global or command-level flags/options. */
82
+ options?: CliOption[];
83
+ /** Positional argument definitions. */
84
+ positionals?: CliPositional[];
85
+ /** Nested subcommands (empty for leaf commands). */
86
+ commands?: CliCommand[];
87
+ /** Handler function for leaf commands. */
88
+ handler?: CliHandler;
89
+ /** Default top-level subcommand when argv omits a command or uses an unknown first token (root only). */
90
+ fallbackCommand?: string;
91
+ /** How fallbackCommand is applied (root only). */
92
+ fallbackMode?: CliFallbackMode;
93
+ }
94
+ /**
95
+ * Handler closure type for leaf commands.
96
+ * Supports both sync and async handlers.
97
+ */
98
+ export type CliHandler = (ctx: CliContext) => void | Promise<void>;
99
+ /**
100
+ * Error thrown when the static CliCommand tree violates ArgsBarg rules.
101
+ */
102
+ export declare class CliSchemaValidationError extends Error {
103
+ /** Creates a schema validation error with a human-readable rule violation. */
104
+ constructor(message: string);
105
+ }
106
+ /**
107
+ * Values passed to a leaf command handler after parsing: app name, routed path, args, and merged options.
108
+ */
109
+ export declare class CliContext {
110
+ readonly appName: string;
111
+ readonly commandPath: string[];
112
+ readonly args: string[];
113
+ readonly schema: CliCommand;
114
+ readonly opts: Record<string, string>;
115
+ /** Captures the merged program root, routed path, positional words, and option map for a leaf handler. */
116
+ constructor(appName: string, commandPath: string[], args: string[], opts: Record<string, string>, schema: CliCommand);
117
+ /** Returns whether a presence flag was set (including implicit "1" for boolean options). */
118
+ hasFlag(name: string): boolean;
119
+ /** Returns the string value for a string-valued option, if present. */
120
+ stringOpt(name: string): string | undefined;
121
+ /** Parses a stored string as a number; returns null if missing or not a strict double string. */
122
+ numberOpt(name: string): number | null;
123
+ /**
124
+ * Generic typed accessor: parses a stored string using the provided parse function.
125
+ * This is the TypeScript-native advantage over the Swift version.
126
+ */
127
+ typedOpt<T>(name: string, parse: (s: string) => T): T | null;
128
+ }
129
+ /**
130
+ * Validates the schema, parses argv, prints help or errors, runs completion or the leaf handler, then exits.
131
+ *
132
+ * @param root The root CliCommand.
133
+ * @param argv Override the default argv (process.argv.slice(2)).
134
+ */
135
+ export declare function cliRun(root: CliCommand, argv?: string[]): Promise<never>;
136
+ /**
137
+ * Prints a red error line and contextual help on stderr, then exits with status 1.
138
+ */
139
+ export declare function cliErrWithHelp(ctx: CliContext, msg: string): never;
140
+
141
+ export {};
package/justfile CHANGED
@@ -27,6 +27,10 @@ lint:
27
27
  test: check-types format lint
28
28
  bun test
29
29
 
30
+ # generate type declarations for the package
31
+ typegen:
32
+ bunx dts-bundle-generator --out-file index.d.ts src/index.ts
33
+
30
34
  # publish to github and npm
31
- release bump: test
35
+ release bump: test typegen
32
36
  bun scripts/release.ts {{bump}}
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "argsbarg",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "//just": "echo this app uses justfile for development tasks"
7
7
  },
8
8
  "main": "./src/index.ts",
9
9
  "module": "./src/index.ts",
10
- "types": "./src/index.ts",
10
+ "types": "./index.d.ts",
11
11
  "bin": {
12
12
  "argsbarg": "src/index.ts"
13
13
  },