Skip to content

Commit e5451e1

Browse files
committed
1 parent 7b584d3 commit e5451e1

File tree

7 files changed

+169
-73
lines changed

7 files changed

+169
-73
lines changed

node_modules/jackspeak/LICENSE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ from liability.
1111
## Acceptance
1212

1313
In order to receive this license, you must agree to its
14-
rules. The rules of this license are both obligations
14+
rules. The rules of this license are both obligations
1515
under that agreement and conditions to your license.
1616
You must not do anything with this software that triggers
1717
a rule that you cannot or will not follow.
@@ -34,7 +34,7 @@ changes, also gets the text of this license or a link to
3434
If anyone notifies you in writing that you have not
3535
complied with [Notices](#notices), you can keep your
3636
license by taking all practical steps to comply within 30
37-
days after the notice. If you do not do so, your license
37+
days after the notice. If you do not do so, your license
3838
ends immediately.
3939

4040
## Patent
@@ -49,7 +49,7 @@ No contributor can revoke this license.
4949

5050
## No Liability
5151

52-
***As far as the law allows, this software comes as is,
52+
**_As far as the law allows, this software comes as is,
5353
without any warranty or condition, and no contributor
5454
will be liable to anyone for any damages related to this
55-
software or this license, under any kind of legal claim.***
55+
software or this license, under any kind of legal claim._**

node_modules/jackspeak/dist/commonjs/index.js

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,13 @@ class Jack {
365365
* an explicit CLI setting.
366366
*/
367367
parse(args = process.argv) {
368-
if (args === process.argv) {
369-
args = args.slice(process._eval !== undefined ? 1 : 2);
370-
}
368+
this.loadEnvDefaults();
369+
const p = this.parseRaw(args);
370+
this.applyDefaults(p);
371+
this.writeEnv(p);
372+
return p;
373+
}
374+
loadEnvDefaults() {
371375
if (this.#envPrefix) {
372376
for (const [field, my] of Object.entries(this.#configSet)) {
373377
const ek = toEnvKey(this.#envPrefix, field);
@@ -377,6 +381,25 @@ class Jack {
377381
}
378382
}
379383
}
384+
}
385+
applyDefaults(p) {
386+
for (const [field, c] of Object.entries(this.#configSet)) {
387+
if (c.default !== undefined && !(field in p.values)) {
388+
//@ts-ignore
389+
p.values[field] = c.default;
390+
}
391+
}
392+
}
393+
/**
394+
* Only parse the command line arguments passed in.
395+
* Does not strip off the `node script.js` bits, so it must be just the
396+
* arguments you wish to have parsed.
397+
* Does not read from or write to the environment, or set defaults.
398+
*/
399+
parseRaw(args) {
400+
if (args === process.argv) {
401+
args = args.slice(process._eval !== undefined ? 1 : 2);
402+
}
380403
const options = toParseArgsOptionsConfig(this.#configSet);
381404
const result = (0, parse_args_js_1.parseArgs)({
382405
args,
@@ -393,9 +416,10 @@ class Jack {
393416
for (const token of result.tokens) {
394417
if (token.kind === 'positional') {
395418
p.positionals.push(token.value);
396-
if (this.#options.stopAtPositional) {
419+
if (this.#options.stopAtPositional ||
420+
this.#options.stopAtPositionalTest?.(token.value)) {
397421
p.positionals.push(...args.slice(token.index + 1));
398-
return p;
422+
break;
399423
}
400424
}
401425
else if (token.kind === 'option') {
@@ -469,12 +493,6 @@ class Jack {
469493
}
470494
}
471495
}
472-
for (const [field, c] of Object.entries(this.#configSet)) {
473-
if (c.default !== undefined && !(field in p.values)) {
474-
//@ts-ignore
475-
p.values[field] = c.default;
476-
}
477-
}
478496
for (const [field, value] of Object.entries(p.values)) {
479497
const valid = this.#configSet[field]?.validate;
480498
const validOptions = this.#configSet[field]?.validOptions;
@@ -489,7 +507,6 @@ class Jack {
489507
throw new Error(`Invalid value provided for --${field}: ${JSON.stringify(value)}`, { cause });
490508
}
491509
}
492-
this.#writeEnv(p);
493510
return p;
494511
}
495512
/**
@@ -557,7 +574,7 @@ class Jack {
557574
}
558575
}
559576
}
560-
#writeEnv(p) {
577+
writeEnv(p) {
561578
if (!this.#env || !this.#envPrefix)
562579
return;
563580
for (const [field, value] of Object.entries(p.values)) {
@@ -912,6 +929,7 @@ class Jack {
912929
...(def.validate ? { validate: def.validate } : {}),
913930
...(def.validOptions ? { validOptions: def.validOptions } : {}),
914931
...(def.default !== undefined ? { default: def.default } : {}),
932+
...(def.hint ? { hint: def.hint } : {}),
915933
},
916934
]));
917935
}
@@ -925,22 +943,52 @@ class Jack {
925943
exports.Jack = Jack;
926944
// Unwrap and un-indent, so we can wrap description
927945
// strings however makes them look nice in the code.
928-
const normalize = (s, pre = false) => pre ?
929-
// prepend a ZWSP to each line so cliui doesn't strip it.
930-
s
931-
.split('\n')
932-
.map(l => `\u200b${l}`)
933-
.join('\n')
934-
: s
935-
// remove single line breaks, except for lists
936-
.replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`)
937-
// normalize mid-line whitespace
938-
.replace(/([^\n])[ \t]+([^\n])/g, '$1 $2')
939-
// two line breaks are enough
940-
.replace(/\n{3,}/g, '\n\n')
941-
// remove any spaces at the start of a line
942-
.replace(/\n[ \t]+/g, '\n')
943-
.trim();
946+
const normalize = (s, pre = false) => {
947+
if (pre)
948+
// prepend a ZWSP to each line so cliui doesn't strip it.
949+
return s
950+
.split('\n')
951+
.map(l => `\u200b${l}`)
952+
.join('\n');
953+
return s
954+
.split(/^\s*```\s*$/gm)
955+
.map((s, i) => {
956+
if (i % 2 === 1) {
957+
if (!s.trim()) {
958+
return `\`\`\`\n\`\`\`\n`;
959+
}
960+
// outdent the ``` blocks, but preserve whitespace otherwise.
961+
const split = s.split('\n');
962+
// throw out the \n at the start and end
963+
split.pop();
964+
split.shift();
965+
const si = split.reduce((shortest, l) => {
966+
/* c8 ignore next */
967+
const ind = l.match(/^\s*/)?.[0] ?? '';
968+
if (ind.length)
969+
return Math.min(ind.length, shortest);
970+
else
971+
return shortest;
972+
}, Infinity);
973+
/* c8 ignore next */
974+
const i = isFinite(si) ? si : 0;
975+
return ('\n```\n' +
976+
split.map(s => `\u200b${s.substring(i)}`).join('\n') +
977+
'\n```\n');
978+
}
979+
return (s
980+
// remove single line breaks, except for lists
981+
.replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`)
982+
// normalize mid-line whitespace
983+
.replace(/([^\n])[ \t]+([^\n])/g, '$1 $2')
984+
// two line breaks are enough
985+
.replace(/\n{3,}/g, '\n\n')
986+
// remove any spaces at the start of a line
987+
.replace(/\n[ \t]+/g, '\n')
988+
.trim());
989+
})
990+
.join('\n');
991+
};
944992
// normalize for markdown printing, remove leading spaces on lines
945993
const normalizeMarkdown = (s, pre = false) => {
946994
const n = normalize(s, pre).replace(/\\/g, '\\\\');

node_modules/jackspeak/dist/commonjs/parse-args.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
2525
Object.defineProperty(exports, "__esModule", { value: true });
2626
exports.parseArgs = void 0;
2727
const util = __importStar(require("util"));
28-
const pv = typeof process === 'object' &&
28+
const pv = (typeof process === 'object' &&
2929
!!process &&
30-
typeof process.version === 'string'
31-
? process.version
30+
typeof process.version === 'string') ?
31+
process.version
3232
: 'v0.0.0';
3333
const pvs = pv
3434
.replace(/^v/, '')

node_modules/jackspeak/dist/esm/index.js

Lines changed: 77 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -357,9 +357,13 @@ export class Jack {
357357
* an explicit CLI setting.
358358
*/
359359
parse(args = process.argv) {
360-
if (args === process.argv) {
361-
args = args.slice(process._eval !== undefined ? 1 : 2);
362-
}
360+
this.loadEnvDefaults();
361+
const p = this.parseRaw(args);
362+
this.applyDefaults(p);
363+
this.writeEnv(p);
364+
return p;
365+
}
366+
loadEnvDefaults() {
363367
if (this.#envPrefix) {
364368
for (const [field, my] of Object.entries(this.#configSet)) {
365369
const ek = toEnvKey(this.#envPrefix, field);
@@ -369,6 +373,25 @@ export class Jack {
369373
}
370374
}
371375
}
376+
}
377+
applyDefaults(p) {
378+
for (const [field, c] of Object.entries(this.#configSet)) {
379+
if (c.default !== undefined && !(field in p.values)) {
380+
//@ts-ignore
381+
p.values[field] = c.default;
382+
}
383+
}
384+
}
385+
/**
386+
* Only parse the command line arguments passed in.
387+
* Does not strip off the `node script.js` bits, so it must be just the
388+
* arguments you wish to have parsed.
389+
* Does not read from or write to the environment, or set defaults.
390+
*/
391+
parseRaw(args) {
392+
if (args === process.argv) {
393+
args = args.slice(process._eval !== undefined ? 1 : 2);
394+
}
372395
const options = toParseArgsOptionsConfig(this.#configSet);
373396
const result = parseArgs({
374397
args,
@@ -385,9 +408,10 @@ export class Jack {
385408
for (const token of result.tokens) {
386409
if (token.kind === 'positional') {
387410
p.positionals.push(token.value);
388-
if (this.#options.stopAtPositional) {
411+
if (this.#options.stopAtPositional ||
412+
this.#options.stopAtPositionalTest?.(token.value)) {
389413
p.positionals.push(...args.slice(token.index + 1));
390-
return p;
414+
break;
391415
}
392416
}
393417
else if (token.kind === 'option') {
@@ -461,12 +485,6 @@ export class Jack {
461485
}
462486
}
463487
}
464-
for (const [field, c] of Object.entries(this.#configSet)) {
465-
if (c.default !== undefined && !(field in p.values)) {
466-
//@ts-ignore
467-
p.values[field] = c.default;
468-
}
469-
}
470488
for (const [field, value] of Object.entries(p.values)) {
471489
const valid = this.#configSet[field]?.validate;
472490
const validOptions = this.#configSet[field]?.validOptions;
@@ -481,7 +499,6 @@ export class Jack {
481499
throw new Error(`Invalid value provided for --${field}: ${JSON.stringify(value)}`, { cause });
482500
}
483501
}
484-
this.#writeEnv(p);
485502
return p;
486503
}
487504
/**
@@ -549,7 +566,7 @@ export class Jack {
549566
}
550567
}
551568
}
552-
#writeEnv(p) {
569+
writeEnv(p) {
553570
if (!this.#env || !this.#envPrefix)
554571
return;
555572
for (const [field, value] of Object.entries(p.values)) {
@@ -904,6 +921,7 @@ export class Jack {
904921
...(def.validate ? { validate: def.validate } : {}),
905922
...(def.validOptions ? { validOptions: def.validOptions } : {}),
906923
...(def.default !== undefined ? { default: def.default } : {}),
924+
...(def.hint ? { hint: def.hint } : {}),
907925
},
908926
]));
909927
}
@@ -916,22 +934,52 @@ export class Jack {
916934
}
917935
// Unwrap and un-indent, so we can wrap description
918936
// strings however makes them look nice in the code.
919-
const normalize = (s, pre = false) => pre ?
920-
// prepend a ZWSP to each line so cliui doesn't strip it.
921-
s
922-
.split('\n')
923-
.map(l => `\u200b${l}`)
924-
.join('\n')
925-
: s
926-
// remove single line breaks, except for lists
927-
.replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`)
928-
// normalize mid-line whitespace
929-
.replace(/([^\n])[ \t]+([^\n])/g, '$1 $2')
930-
// two line breaks are enough
931-
.replace(/\n{3,}/g, '\n\n')
932-
// remove any spaces at the start of a line
933-
.replace(/\n[ \t]+/g, '\n')
934-
.trim();
937+
const normalize = (s, pre = false) => {
938+
if (pre)
939+
// prepend a ZWSP to each line so cliui doesn't strip it.
940+
return s
941+
.split('\n')
942+
.map(l => `\u200b${l}`)
943+
.join('\n');
944+
return s
945+
.split(/^\s*```\s*$/gm)
946+
.map((s, i) => {
947+
if (i % 2 === 1) {
948+
if (!s.trim()) {
949+
return `\`\`\`\n\`\`\`\n`;
950+
}
951+
// outdent the ``` blocks, but preserve whitespace otherwise.
952+
const split = s.split('\n');
953+
// throw out the \n at the start and end
954+
split.pop();
955+
split.shift();
956+
const si = split.reduce((shortest, l) => {
957+
/* c8 ignore next */
958+
const ind = l.match(/^\s*/)?.[0] ?? '';
959+
if (ind.length)
960+
return Math.min(ind.length, shortest);
961+
else
962+
return shortest;
963+
}, Infinity);
964+
/* c8 ignore next */
965+
const i = isFinite(si) ? si : 0;
966+
return ('\n```\n' +
967+
split.map(s => `\u200b${s.substring(i)}`).join('\n') +
968+
'\n```\n');
969+
}
970+
return (s
971+
// remove single line breaks, except for lists
972+
.replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`)
973+
// normalize mid-line whitespace
974+
.replace(/([^\n])[ \t]+([^\n])/g, '$1 $2')
975+
// two line breaks are enough
976+
.replace(/\n{3,}/g, '\n\n')
977+
// remove any spaces at the start of a line
978+
.replace(/\n[ \t]+/g, '\n')
979+
.trim());
980+
})
981+
.join('\n');
982+
};
935983
// normalize for markdown printing, remove leading spaces on lines
936984
const normalizeMarkdown = (s, pre = false) => {
937985
const n = normalize(s, pre).replace(/\\/g, '\\\\');

node_modules/jackspeak/dist/esm/parse-args.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as util from 'util';
2-
const pv = typeof process === 'object' &&
2+
const pv = (typeof process === 'object' &&
33
!!process &&
4-
typeof process.version === 'string'
5-
? process.version
4+
typeof process.version === 'string') ?
5+
process.version
66
: 'v0.0.0';
77
const pvs = pv
88
.replace(/^v/, '')

node_modules/jackspeak/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jackspeak",
3-
"version": "3.1.2",
3+
"version": "3.4.0",
44
"description": "A very strict and proper argument parser.",
55
"tshy": {
66
"main": true,
@@ -38,7 +38,7 @@
3838
"presnap": "npm run prepare",
3939
"test": "tap",
4040
"snap": "tap",
41-
"format": "prettier --write . --loglevel warn",
41+
"format": "prettier --write . --log-level warn",
4242
"typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts"
4343
},
4444
"license": "BlueOak-1.0.0",

0 commit comments

Comments
 (0)