cli-nano 1.3.0 → 1.3.1
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 +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -6
- package/package.json +1 -1
- package/src/index.ts +16 -6
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
[](https://codecov.io/gh/ghiscoding/cli-nano)
|
|
5
5
|
[](https://www.npmjs.com/package/cli-nano)
|
|
6
6
|
[](https://www.npmjs.com/package/cli-nano)
|
|
7
|
-
[](https://bundlejs.com/?q=cli-nano)
|
|
8
8
|
<a href="https://nodejs.org/en/about/previous-releases"><img src="https://img.shields.io/node/v/cli-nano.svg" alt="Node" /></a>
|
|
9
9
|
|
|
10
10
|
## cli-nano
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAc,MAAM,iBAAiB,CAAC;AAEtE,mBAAmB,iBAAiB,CAAC;AAOrC,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAc,MAAM,iBAAiB,CAAC;AAEtE,mBAAmB,iBAAiB,CAAC;AAOrC,wBAAgB,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAuVpE"}
|
package/dist/index.js
CHANGED
|
@@ -287,16 +287,26 @@ export function parseArgs(config) {
|
|
|
287
287
|
}
|
|
288
288
|
argIndex++;
|
|
289
289
|
}
|
|
290
|
-
// After all parsing,
|
|
291
|
-
//
|
|
290
|
+
// After all parsing, first ensure any `required` CLI options are present
|
|
291
|
+
// (required should error even for boolean flags). Then assign any
|
|
292
|
+
// explicit `default` values and finally apply yargs-parity boolean
|
|
293
|
+
// defaults for non-required boolean flags.
|
|
292
294
|
Object.entries(options).forEach(([key, opt]) => {
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
if (opt.required && result[key] === undefined) {
|
|
295
|
+
// If the option wasn't provided and is required, throw immediately.
|
|
296
|
+
if (result[key] === undefined && opt.required) {
|
|
297
297
|
const aliasStr = opt.alias ? `-${opt.alias}, ` : '';
|
|
298
298
|
throw new Error(`Missing required option: ${aliasStr}--${key}`);
|
|
299
299
|
}
|
|
300
|
+
// If the option wasn't provided, apply any explicit default.
|
|
301
|
+
if (result[key] === undefined) {
|
|
302
|
+
if (opt.default !== undefined) {
|
|
303
|
+
result[key] = opt.default;
|
|
304
|
+
}
|
|
305
|
+
else if (opt.type === 'boolean') {
|
|
306
|
+
// Parity with yargs: boolean flags default to false when not provided
|
|
307
|
+
result[key] = false;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
300
310
|
});
|
|
301
311
|
// Expose raw non-option positionals as `._` for convenience
|
|
302
312
|
if (result._ === undefined) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cli-nano",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Small command-line tool similar to `yargs` or `parseArgs` from Node.js to create a CLI accepting positional arguments, flags and options.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
package/src/index.ts
CHANGED
|
@@ -296,16 +296,26 @@ export function parseArgs<C extends Config>(config: C): ArgsResult<C> {
|
|
|
296
296
|
argIndex++;
|
|
297
297
|
}
|
|
298
298
|
|
|
299
|
-
// After all parsing,
|
|
300
|
-
//
|
|
299
|
+
// After all parsing, first ensure any `required` CLI options are present
|
|
300
|
+
// (required should error even for boolean flags). Then assign any
|
|
301
|
+
// explicit `default` values and finally apply yargs-parity boolean
|
|
302
|
+
// defaults for non-required boolean flags.
|
|
301
303
|
Object.entries(options).forEach(([key, opt]) => {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
if (opt.required && result[key] === undefined) {
|
|
304
|
+
// If the option wasn't provided and is required, throw immediately.
|
|
305
|
+
if (result[key] === undefined && opt.required) {
|
|
306
306
|
const aliasStr = opt.alias ? `-${opt.alias}, ` : '';
|
|
307
307
|
throw new Error(`Missing required option: ${aliasStr}--${key}`);
|
|
308
308
|
}
|
|
309
|
+
|
|
310
|
+
// If the option wasn't provided, apply any explicit default.
|
|
311
|
+
if (result[key] === undefined) {
|
|
312
|
+
if (opt.default !== undefined) {
|
|
313
|
+
result[key] = opt.default;
|
|
314
|
+
} else if (opt.type === 'boolean') {
|
|
315
|
+
// Parity with yargs: boolean flags default to false when not provided
|
|
316
|
+
result[key] = false;
|
|
317
|
+
}
|
|
318
|
+
}
|
|
309
319
|
});
|
|
310
320
|
|
|
311
321
|
// Expose raw non-option positionals as `._` for convenience
|