just-bash-util 0.1.4 → 0.1.5

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 CHANGED
@@ -64,11 +64,55 @@ await serve.invoke({ port: 8080, entry: "app.ts" }, ctx);
64
64
  - `omitInherited` to exclude parent options from specific subcommands
65
65
  - `--help` / `-h` auto-generated at every level
66
66
  - `--no-<flag>` negation, `-abc` combined short flags, `--key=value` syntax
67
- - `--` passthrough separator
67
+ - `--` end-of-options separator (remaining tokens become positional args and are available via `meta.passthrough`)
68
68
  - Environment variable fallbacks for options
69
69
  - Levenshtein-based "did you mean?" suggestions for typos
70
70
  - Automatic error handling — thrown errors in handlers are caught and returned as clean `ExecResult` with `exitCode: 1`
71
71
 
72
+ #### Options and flags
73
+
74
+ Option keys are written in camelCase and automatically converted to kebab-case for the CLI:
75
+
76
+ ```ts
77
+ options: {
78
+ allowEmpty: f(), // CLI: --allow-empty handler: args.allowEmpty
79
+ dryRun: f().alias("n"), // CLI: --dry-run / -n handler: args.dryRun
80
+ message: o.string().alias("m"), // CLI: --message / -m handler: args.message
81
+ }
82
+ ```
83
+
84
+ Short flags (single-dash, single-character) require `.alias()`. A single-character key like `b: f()` creates the long flag `--b`, **not** the short flag `-b`. To get `-b`, use a descriptive key with an alias:
85
+
86
+ ```ts
87
+ // ✗ b: f() → creates --b (long flag), not -b
88
+ // ✓ branch: f().alias("b") → creates --branch and -b
89
+ ```
90
+
91
+ #### Positional args
92
+
93
+ Args are required by default. Use `.optional()` for optional args, and `.variadic()` to collect remaining positionals into an array. Chain `.optional().variadic()` for zero-or-more:
94
+
95
+ ```ts
96
+ args: [
97
+ a.string().name("entry"), // required single arg
98
+ a.string().name("file").optional(), // optional single arg
99
+ a.string().name("files").variadic(), // required: one or more
100
+ a.string().name("paths").optional().variadic(), // optional: zero or more → string[]
101
+ ]
102
+ ```
103
+
104
+ #### The `--` separator
105
+
106
+ The `--` token signals end-of-options. Tokens after `--` are treated as positional arguments (not parsed as flags) and are also available in `meta.passthrough`:
107
+
108
+ ```ts
109
+ // mycli checkout -- README.md
110
+ handler: (args, ctx, meta) => {
111
+ args.target; // "README.md" (assigned to positional arg)
112
+ meta.passthrough; // ["README.md"] (raw tokens after --)
113
+ }
114
+ ```
115
+
72
116
  ### `just-bash-util/config` — Config file discovery
73
117
 
74
118
  Cosmiconfig-style config search that walks up the directory tree, trying conventional filenames at each level. Comments and trailing commas are supported out of the box.
@@ -142,6 +186,15 @@ parsePackageSpecifier("@vue/shared/dist"); // { name: "@vue/shared", subpath: ".
142
186
  parsePackageSpecifier("lodash/merge"); // { name: "lodash", subpath: "./merge" }
143
187
  ```
144
188
 
189
+ **`join` vs `resolve`** — `join` concatenates segments and normalizes; an absolute second argument is kept as-is (appended, not replacing). `resolve` processes right-to-left and stops at the first absolute path, like Node's `path.resolve` (but without prepending `cwd` when no absolute segment exists):
190
+
191
+ ```ts
192
+ join("/repo", "/file.txt"); // "/repo/file.txt" — concatenates with /
193
+ resolve("/repo", "/file.txt"); // "/file.txt" — absolute segment wins
194
+ resolve("/repo", "file.txt"); // "/repo/file.txt"
195
+ resolve("a", "b"); // "a/b" — stays relative (no cwd)
196
+ ```
197
+
145
198
  ## Peer dependencies
146
199
 
147
200
  Requires [`just-bash`](https://www.npmjs.com/package/just-bash) ^2.9.6 — provides the `CommandContext` and `ExecResult` types used throughout.
@@ -210,6 +210,7 @@ function parseArgs(options, argDefs, tokens, env) {
210
210
  if (token === "--") {
211
211
  i++;
212
212
  while (i < tokens.length) {
213
+ positionals.push(tokens[i]);
213
214
  passthrough.push(tokens[i]);
214
215
  i++;
215
216
  }
@@ -268,10 +269,14 @@ function parseArgs(options, argDefs, tokens, env) {
268
269
  const ch = chars[j];
269
270
  const entry = shortMap.get(ch);
270
271
  if (!entry) {
272
+ const suggestions = [];
273
+ if (longMap.has(ch)) {
274
+ suggestions.push(`--${ch}`);
275
+ }
271
276
  errors.push({
272
277
  type: "unknown_option",
273
278
  name: `-${ch}`,
274
- suggestions: []
279
+ suggestions
275
280
  });
276
281
  continue;
277
282
  }
@@ -8,7 +8,7 @@ import {
8
8
  generateHelp,
9
9
  o,
10
10
  parseArgs
11
- } from "../chunk-35QZZQ4A.js";
11
+ } from "../chunk-RNQNKFXA.js";
12
12
  export {
13
13
  Command,
14
14
  a,
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  generateHelp,
9
9
  o,
10
10
  parseArgs
11
- } from "./chunk-35QZZQ4A.js";
11
+ } from "./chunk-RNQNKFXA.js";
12
12
  import {
13
13
  findUp,
14
14
  loadConfig,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "just-bash-util",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "CLI command framework, config file discovery, and path utilities for just-bash",
5
5
  "type": "module",
6
6
  "license": "MIT",