Updated the project.

This commit is contained in:
Batuhan Berk Başoğlu 2024-06-03 15:44:25 -04:00
parent 5dfe9f128d
commit 7919556077
1550 changed files with 17063 additions and 40183 deletions

8
my-app/node_modules/jackspeak/LICENSE.md generated vendored Executable file → Normal file
View file

@ -11,7 +11,7 @@ from liability.
## Acceptance
In order to receive this license, you must agree to its
rules. The rules of this license are both obligations
rules. The rules of this license are both obligations
under that agreement and conditions to your license.
You must not do anything with this software that triggers
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
If anyone notifies you in writing that you have not
complied with [Notices](#notices), you can keep your
license by taking all practical steps to comply within 30
days after the notice. If you do not do so, your license
days after the notice. If you do not do so, your license
ends immediately.
## Patent
@ -49,7 +49,7 @@ No contributor can revoke this license.
## No Liability
***As far as the law allows, this software comes as is,
**_As far as the law allows, this software comes as is,
without any warranty or condition, and no contributor
will be liable to anyone for any damages related to this
software or this license, under any kind of legal claim.***
software or this license, under any kind of legal claim._**

5
my-app/node_modules/jackspeak/README.md generated vendored Executable file → Normal file
View file

@ -155,6 +155,9 @@ Options:
in the usage output, like `--option=<hint>`
- `validate` A function that returns false (or throws) if an
option value is invalid.
- `validOptions` An array of strings or numbers that define the
valid values that can be set. This is not allowed on `boolean`
(flag) options. May be used along with a `validate()` method.
- `default` A default value for the field. Note that this may be
overridden by an environment variable, if present.
@ -259,7 +262,7 @@ const j = jack({
TAP formatted test result data.
To parse TAP data from stdin, specify "-" as a filename.
`
`,
)
// flags don't take a value, they're boolean on or off, and can be

53
my-app/node_modules/jackspeak/dist/commonjs/index.d.ts generated vendored Executable file → Normal file
View file

@ -9,7 +9,7 @@ import { inspect, InspectOptions } from 'node:util';
* Defines the type of value that is valid, given a config definition's
* {@link ConfigType} and boolean multiple setting
*/
export type ValidValue<T extends ConfigType, M extends boolean> = [
export type ValidValue<T extends ConfigType = ConfigType, M extends boolean = boolean> = [
T,
M
] extends ['number', true] ? number[] : [T, M] extends ['string', true] ? string[] : [T, M] extends ['boolean', true] ? boolean[] : [T, M] extends ['number', false] ? number : [T, M] extends ['string', false] ? string : [T, M] extends ['boolean', false] ? boolean : [T, M] extends ['string', boolean] ? string | string[] : [T, M] extends ['boolean', boolean] ? boolean | boolean[] : [T, M] extends ['number', boolean] ? number | number[] : [T, M] extends [ConfigType, false] ? string | number | boolean : [T, M] extends [ConfigType, true] ? string[] | number[] | boolean[] : string | number | boolean | string[] | number[] | boolean[];
@ -17,23 +17,27 @@ export type ValidValue<T extends ConfigType, M extends boolean> = [
* The meta information for a config option definition, when the
* type and multiple values can be inferred by the method being used
*/
export type ConfigOptionMeta<T extends ConfigType, M extends boolean> = {
default?: ValidValue<T, M> | undefined;
export type ConfigOptionMeta<T extends ConfigType, M extends boolean = boolean, O extends undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[]) = undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[])> = {
default?: undefined | (ValidValue<T, M> & (O extends number[] | string[] ? M extends false ? O[number] : O[number][] : unknown));
validOptions?: O;
description?: string;
validate?: ((v: any) => v is ValidValue<T, M>) | ((v: any) => boolean);
validate?: ((v: unknown) => v is ValidValue<T, M>) | ((v: unknown) => boolean);
short?: string | undefined;
type?: T;
} & (T extends 'boolean' ? {} : {
hint?: string | undefined;
}) & (M extends false ? {} : {
multiple?: M | undefined;
delim?: string | undefined;
hint?: T extends 'boolean' ? never : string;
delim?: M extends true ? string : never;
} & (M extends false ? {
multiple?: false | undefined;
} : M extends true ? {
multiple: true;
} : {
multiple?: boolean;
});
/**
* A set of {@link ConfigOptionMeta} fields, referenced by their longOption
* string values.
*/
export type ConfigMetaSet<T extends ConfigType, M extends boolean> = {
export type ConfigMetaSet<T extends ConfigType, M extends boolean = boolean> = {
[longOption: string]: ConfigOptionMeta<T, M>;
};
/**
@ -60,13 +64,14 @@ export type MultiType<M extends boolean> = M extends true ? {
/**
* A config field definition, in its full representation.
*/
export type ConfigOptionBase<T extends ConfigType, M extends boolean> = {
export type ConfigOptionBase<T extends ConfigType, M extends boolean = boolean> = {
type: T;
short?: string | undefined;
default?: ValidValue<T, M> | undefined;
description?: string;
hint?: T extends 'boolean' ? undefined : string | undefined;
validate?: (v: any) => v is ValidValue<T, M>;
validate?: (v: unknown) => v is ValidValue<T, M>;
validOptions?: T extends 'boolean' ? undefined : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[];
} & MultiType<M>;
export declare const isConfigType: (t: string) => t is ConfigType;
export declare const isConfigOption: <T extends ConfigType, M extends boolean>(o: any, type: T, multi: M) => o is ConfigOptionBase<T, M>;
@ -75,13 +80,13 @@ export declare const isConfigOption: <T extends ConfigType, M extends boolean>(o
* string values.
*/
export type ConfigSet = {
[longOption: string]: ConfigOptionBase<ConfigType, boolean>;
[longOption: string]: ConfigOptionBase<ConfigType>;
};
/**
* The 'values' field returned by {@link Jack#parse}
*/
export type OptionsResults<T extends ConfigSet> = {
[k in keyof T]?: T[k] extends ConfigOptionBase<'string', false> ? string : T[k] extends ConfigOptionBase<'string', true> ? string[] : T[k] extends ConfigOptionBase<'number', false> ? number : T[k] extends ConfigOptionBase<'number', true> ? number[] : T[k] extends ConfigOptionBase<'boolean', false> ? boolean : T[k] extends ConfigOptionBase<'boolean', true> ? boolean[] : never;
[k in keyof T]?: T[k]['validOptions'] extends (readonly string[] | readonly number[]) ? T[k] extends ConfigOptionBase<'string' | 'number', false> ? T[k]['validOptions'][number] : T[k] extends ConfigOptionBase<'string' | 'number', true> ? T[k]['validOptions'][number][] : never : T[k] extends ConfigOptionBase<'string', false> ? string : T[k] extends ConfigOptionBase<'string', true> ? string[] : T[k] extends ConfigOptionBase<'number', false> ? number : T[k] extends ConfigOptionBase<'number', true> ? number[] : T[k] extends ConfigOptionBase<'boolean', false> ? boolean : T[k] extends ConfigOptionBase<'boolean', true> ? boolean[] : never;
};
/**
* The object retured by {@link Jack#parse}
@ -140,7 +145,7 @@ export type TextRow = Heading | Description;
export type UsageField = TextRow | {
type: 'config';
name: string;
value: ConfigOptionBase<ConfigType, boolean>;
value: ConfigOptionBase<ConfigType>;
};
/**
* Options provided to the {@link Jack} constructor
@ -211,11 +216,18 @@ export declare class Jack<C extends ConfigSet = {}> {
* an explicit CLI setting.
*/
parse(args?: string[]): Parsed<C>;
/**
* Only parse the command line arguments passed in.
* Does not strip off the `node script.js` bits, so it must be just the
* arguments you wish to have parsed.
* Does not read from or write to the environment, or set defaults.
*/
parseRaw(args: string[]): Parsed<C>;
/**
* Validate that any arbitrary object is a valid configuration `values`
* object. Useful when loading config files or other sources.
*/
validate(o: any): asserts o is Parsed<C>['values'];
validate(o: unknown): asserts o is Parsed<C>['values'];
/**
* Add a heading to the usage output banner
*/
@ -235,7 +247,7 @@ export declare class Jack<C extends ConfigSet = {}> {
/**
* Add one or more multiple number fields.
*/
numList<F extends ConfigMetaSet<'number', true>>(fields: F): Jack<C & ConfigSetFromMetaSet<'number', true, F>>;
numList<F extends ConfigMetaSet<'number'>>(fields: F): Jack<C & ConfigSetFromMetaSet<'number', true, F>>;
/**
* Add one or more string option fields.
*/
@ -243,7 +255,7 @@ export declare class Jack<C extends ConfigSet = {}> {
/**
* Add one or more multiple string option fields.
*/
optList<F extends ConfigMetaSet<'string', true>>(fields: F): Jack<C & ConfigSetFromMetaSet<'string', true, F>>;
optList<F extends ConfigMetaSet<'string'>>(fields: F): Jack<C & ConfigSetFromMetaSet<'string', true, F>>;
/**
* Add one or more flag fields.
*/
@ -251,7 +263,7 @@ export declare class Jack<C extends ConfigSet = {}> {
/**
* Add one or more multiple flag fields.
*/
flagList<F extends ConfigMetaSet<'boolean', true>>(fields: F): Jack<C & ConfigSetFromMetaSet<'boolean', true, F>>;
flagList<F extends ConfigMetaSet<'boolean'>>(fields: F): Jack<C & ConfigSetFromMetaSet<'boolean', true, F>>;
/**
* Generic field definition method. Similar to flag/flagList/number/etc,
* but you must specify the `type` (and optionally `multiple` and `delim`)
@ -272,7 +284,8 @@ export declare class Jack<C extends ConfigSet = {}> {
toJSON(): {
[k: string]: {
default?: string | number | boolean | string[] | number[] | boolean[] | undefined;
validate?: ((v: any) => v is string | number | boolean | string[] | number[] | boolean[]) | undefined;
validOptions?: readonly number[] | readonly string[] | undefined;
validate?: ((v: unknown) => v is string | number | boolean | string[] | number[] | boolean[]) | undefined;
description?: string | undefined;
short?: string | undefined;
delim?: string | undefined;

2
my-app/node_modules/jackspeak/dist/commonjs/index.d.ts.map generated vendored Executable file → Normal file

File diff suppressed because one or more lines are too long

324
my-app/node_modules/jackspeak/dist/commonjs/index.js generated vendored Executable file → Normal file
View file

@ -21,51 +21,41 @@ const toEnvKey = (pref, key) => {
.replace(/ /g, '_');
};
const toEnvVal = (value, delim = '\n') => {
const str = typeof value === 'string'
? value
: typeof value === 'boolean'
? value
? '1'
const str = typeof value === 'string' ? value
: typeof value === 'boolean' ?
value ? '1'
: '0'
: typeof value === 'number'
? String(value)
: Array.isArray(value)
? value
.map((v) => toEnvVal(v))
.join(delim)
: /* c8 ignore start */
undefined;
: typeof value === 'number' ? String(value)
: Array.isArray(value) ?
value.map((v) => toEnvVal(v)).join(delim)
: /* c8 ignore start */ undefined;
if (typeof str !== 'string') {
throw new Error(`could not serialize value to environment: ${JSON.stringify(value)}`);
}
/* c8 ignore stop */
return str;
};
const fromEnvVal = (env, type, multiple, delim = '\n') => (multiple
? env
? env.split(delim).map(v => fromEnvVal(v, type, false))
const fromEnvVal = (env, type, multiple, delim = '\n') => (multiple ?
env ? env.split(delim).map(v => fromEnvVal(v, type, false))
: []
: type === 'string'
? env
: type === 'boolean'
? env === '1'
: type === 'string' ? env
: type === 'boolean' ? env === '1'
: +env.trim());
const isConfigType = (t) => typeof t === 'string' &&
(t === 'string' || t === 'number' || t === 'boolean');
exports.isConfigType = isConfigType;
const undefOrType = (v, t) => v === undefined || typeof v === t;
const undefOrTypeArray = (v, t) => v === undefined || (Array.isArray(v) && v.every(x => typeof x === t));
const isValidOption = (v, vo) => Array.isArray(v) ? v.every(x => isValidOption(x, vo)) : vo.includes(v);
// print the value type, for error message reporting
const valueType = (v) => typeof v === 'string'
? 'string'
: typeof v === 'boolean'
? 'boolean'
: typeof v === 'number'
? 'number'
: Array.isArray(v)
? joinTypes([...new Set(v.map(v => valueType(v)))]) + '[]'
const valueType = (v) => typeof v === 'string' ? 'string'
: typeof v === 'boolean' ? 'boolean'
: typeof v === 'number' ? 'number'
: Array.isArray(v) ?
joinTypes([...new Set(v.map(v => valueType(v)))]) + '[]'
: `${v.type}${v.multiple ? '[]' : ''}`;
const joinTypes = (types) => types.length === 1 && typeof types[0] === 'string'
? types[0]
const joinTypes = (types) => types.length === 1 && typeof types[0] === 'string' ?
types[0]
: `(${types.join('|')})`;
const isValidValue = (v, type, multi) => {
if (multi) {
@ -85,80 +75,140 @@ const isConfigOption = (o, type, multi) => !!o &&
undefOrType(o.description, 'string') &&
undefOrType(o.hint, 'string') &&
undefOrType(o.validate, 'function') &&
(o.type === 'boolean' ?
o.validOptions === undefined
: undefOrTypeArray(o.validOptions, o.type)) &&
(o.default === undefined || isValidValue(o.default, type, multi)) &&
!!o.multiple === multi;
exports.isConfigOption = isConfigOption;
function num(o = {}) {
const { default: def, validate: val, ...rest } = o;
const { default: def, validate: val, validOptions, ...rest } = o;
if (def !== undefined && !isValidValue(def, 'number', false)) {
throw new TypeError('invalid default value');
throw new TypeError('invalid default value', {
cause: {
found: def,
wanted: 'number',
},
});
}
const validate = val
? val
if (!undefOrTypeArray(validOptions, 'number')) {
throw new TypeError('invalid validOptions', {
cause: {
found: validOptions,
wanted: 'number[]',
},
});
}
const validate = val ?
val
: undefined;
return {
...rest,
default: def,
validate,
validOptions,
type: 'number',
multiple: false,
};
}
function numList(o = {}) {
const { default: def, validate: val, ...rest } = o;
const { default: def, validate: val, validOptions, ...rest } = o;
if (def !== undefined && !isValidValue(def, 'number', true)) {
throw new TypeError('invalid default value');
throw new TypeError('invalid default value', {
cause: {
found: def,
wanted: 'number[]',
},
});
}
const validate = val
? val
if (!undefOrTypeArray(validOptions, 'number')) {
throw new TypeError('invalid validOptions', {
cause: {
found: validOptions,
wanted: 'number[]',
},
});
}
const validate = val ?
val
: undefined;
return {
...rest,
default: def,
validate,
validOptions,
type: 'number',
multiple: true,
};
}
function opt(o = {}) {
const { default: def, validate: val, ...rest } = o;
const { default: def, validate: val, validOptions, ...rest } = o;
if (def !== undefined && !isValidValue(def, 'string', false)) {
throw new TypeError('invalid default value');
throw new TypeError('invalid default value', {
cause: {
found: def,
wanted: 'string',
},
});
}
const validate = val
? val
if (!undefOrTypeArray(validOptions, 'string')) {
throw new TypeError('invalid validOptions', {
cause: {
found: validOptions,
wanted: 'string[]',
},
});
}
const validate = val ?
val
: undefined;
return {
...rest,
default: def,
validate,
validOptions,
type: 'string',
multiple: false,
};
}
function optList(o = {}) {
const { default: def, validate: val, ...rest } = o;
const { default: def, validate: val, validOptions, ...rest } = o;
if (def !== undefined && !isValidValue(def, 'string', true)) {
throw new TypeError('invalid default value');
throw new TypeError('invalid default value', {
cause: {
found: def,
wanted: 'string[]',
},
});
}
const validate = val
? val
if (!undefOrTypeArray(validOptions, 'string')) {
throw new TypeError('invalid validOptions', {
cause: {
found: validOptions,
wanted: 'string[]',
},
});
}
const validate = val ?
val
: undefined;
return {
...rest,
default: def,
validate,
validOptions,
type: 'string',
multiple: true,
};
}
function flag(o = {}) {
const { hint, default: def, validate: val, ...rest } = o;
delete rest.validOptions;
if (def !== undefined && !isValidValue(def, 'boolean', false)) {
throw new TypeError('invalid default value');
}
const validate = val
? val
const validate = val ?
val
: undefined;
if (hint !== undefined) {
throw new TypeError('cannot provide hint for flag');
@ -173,11 +223,12 @@ function flag(o = {}) {
}
function flagList(o = {}) {
const { hint, default: def, validate: val, ...rest } = o;
delete rest.validOptions;
if (def !== undefined && !isValidValue(def, 'boolean', true)) {
throw new TypeError('invalid default value');
}
const validate = val
? val
const validate = val ?
val
: undefined;
if (hint !== undefined) {
throw new TypeError('cannot provide hint for flag list');
@ -210,8 +261,8 @@ const toParseArgsOptionsConfig = (options) => {
c[longOption] = {
type: 'string',
multiple: false,
default: config.default === undefined
? undefined
default: config.default === undefined ?
undefined
: String(config.default),
};
}
@ -219,7 +270,7 @@ const toParseArgsOptionsConfig = (options) => {
const conf = config;
c[longOption] = {
type: conf.type,
multiple: conf.multiple,
multiple: !!conf.multiple,
default: conf.default,
};
}
@ -277,14 +328,25 @@ class Jack {
this.validate(values);
}
catch (er) {
throw Object.assign(er, source ? { source } : {});
const e = er;
if (source && e && typeof e === 'object') {
if (e.cause && typeof e.cause === 'object') {
Object.assign(e.cause, { path: source });
}
else {
e.cause = { path: source };
}
}
throw e;
}
for (const [field, value] of Object.entries(values)) {
const my = this.#configSet[field];
// already validated, just for TS's benefit
/* c8 ignore start */
if (!my) {
throw new Error('unexpected field in config set: ' + field);
throw new Error('unexpected field in config set: ' + field, {
cause: { found: field },
});
}
/* c8 ignore stop */
my.default = value;
@ -315,6 +377,23 @@ class Jack {
}
}
}
const p = this.parseRaw(args);
for (const [field, c] of Object.entries(this.#configSet)) {
if (c.default !== undefined && !(field in p.values)) {
//@ts-ignore
p.values[field] = c.default;
}
}
this.#writeEnv(p);
return p;
}
/**
* Only parse the command line arguments passed in.
* Does not strip off the `node script.js` bits, so it must be just the
* arguments you wish to have parsed.
* Does not read from or write to the environment, or set defaults.
*/
parseRaw(args) {
const options = toParseArgsOptionsConfig(this.#configSet);
const result = (0, parse_args_js_1.parseArgs)({
args,
@ -333,7 +412,7 @@ class Jack {
p.positionals.push(token.value);
if (this.#options.stopAtPositional) {
p.positionals.push(...args.slice(token.index + 1));
return p;
break;
}
}
else if (token.kind === 'option') {
@ -355,18 +434,27 @@ class Jack {
throw new Error(`Unknown option '${token.rawName}'. ` +
`To specify a positional argument starting with a '-', ` +
`place it at the end of the command after '--', as in ` +
`'-- ${token.rawName}'`);
`'-- ${token.rawName}'`, {
cause: {
found: token.rawName + (token.value ? `=${token.value}` : ''),
},
});
}
if (value === undefined) {
if (token.value === undefined) {
if (my.type !== 'boolean') {
throw new Error(`No value provided for ${token.rawName}, expected ${my.type}`);
throw new Error(`No value provided for ${token.rawName}, expected ${my.type}`, {
cause: {
name: token.rawName,
wanted: valueType(my),
},
});
}
value = true;
}
else {
if (my.type === 'boolean') {
throw new Error(`Flag ${token.rawName} does not take a value, received '${token.value}'`);
throw new Error(`Flag ${token.rawName} does not take a value, received '${token.value}'`, { cause: { found: token } });
}
if (my.type === 'string') {
value = token.value;
@ -375,7 +463,13 @@ class Jack {
value = +token.value;
if (value !== value) {
throw new Error(`Invalid value '${token.value}' provided for ` +
`'${token.rawName}' option, expected number`);
`'${token.rawName}' option, expected number`, {
cause: {
name: token.rawName,
found: token.value,
wanted: 'number',
},
});
}
}
}
@ -392,19 +486,20 @@ class Jack {
}
}
}
for (const [field, c] of Object.entries(this.#configSet)) {
if (c.default !== undefined && !(field in p.values)) {
//@ts-ignore
p.values[field] = c.default;
}
}
for (const [field, value] of Object.entries(p.values)) {
const valid = this.#configSet[field]?.validate;
const validOptions = this.#configSet[field]?.validOptions;
let cause;
if (validOptions && !isValidOption(value, validOptions)) {
cause = { name: field, found: value, validOptions: validOptions };
}
if (valid && !valid(value)) {
throw new Error(`Invalid value provided for --${field}: ${JSON.stringify(value)}`);
cause ??= { name: field, found: value };
}
if (cause) {
throw new Error(`Invalid value provided for --${field}: ${JSON.stringify(value)}`, { cause });
}
}
this.#writeEnv(p);
return p;
}
/**
@ -418,7 +513,7 @@ class Jack {
// recurse so we get the core config key we care about.
this.#noNoFields(yes, val, s);
if (this.#configSet[yes]?.type === 'boolean') {
throw new Error(`do not set '${s}', instead set '${yes}' as desired.`);
throw new Error(`do not set '${s}', instead set '${yes}' as desired.`, { cause: { found: s, wanted: yes } });
}
}
/**
@ -427,22 +522,48 @@ class Jack {
*/
validate(o) {
if (!o || typeof o !== 'object') {
throw new Error('Invalid config: not an object');
throw new Error('Invalid config: not an object', {
cause: { found: o },
});
}
const opts = o;
for (const field in o) {
this.#noNoFields(field, o[field]);
const value = opts[field];
/* c8 ignore next - for TS */
if (value === undefined)
continue;
this.#noNoFields(field, value);
const config = this.#configSet[field];
if (!config) {
throw new Error(`Unknown config option: ${field}`);
}
if (!isValidValue(o[field], config.type, !!config.multiple)) {
throw Object.assign(new Error(`Invalid value ${valueType(o[field])} for ${field}, expected ${valueType(config)}`), {
field,
value: o[field],
throw new Error(`Unknown config option: ${field}`, {
cause: { found: field },
});
}
if (config.validate && !config.validate(o[field])) {
throw new Error(`Invalid config value for ${field}: ${o[field]}`);
if (!isValidValue(value, config.type, !!config.multiple)) {
throw new Error(`Invalid value ${valueType(value)} for ${field}, expected ${valueType(config)}`, {
cause: {
name: field,
found: value,
wanted: valueType(config),
},
});
}
let cause;
if (config.validOptions &&
!isValidOption(value, config.validOptions)) {
cause = {
name: field,
found: value,
validOptions: config.validOptions,
};
}
if (config.validate && !config.validate(value)) {
cause ??= { name: field, found: value };
}
if (cause) {
throw new Error(`Invalid config value for ${field}: ${value}`, {
cause,
});
}
}
}
@ -753,21 +874,21 @@ class Jack {
const { value } = field;
const desc = value.description || '';
const mult = value.multiple ? 'Can be set multiple times' : '';
const dmDelim = mult && (desc.includes('\n') ? '\n\n' : '\n');
const text = normalize(desc + dmDelim + mult);
const opts = value.validOptions?.length ?
`Valid options:${value.validOptions.map(v => ` ${JSON.stringify(v)}`)}`
: '';
const dmDelim = desc.includes('\n') ? '\n\n' : '\n';
const extra = [opts, mult].join(dmDelim).trim();
const text = (normalize(desc) + dmDelim + extra).trim();
const hint = value.hint ||
(value.type === 'number'
? 'n'
: value.type === 'string'
? field.name
(value.type === 'number' ? 'n'
: value.type === 'string' ? field.name
: undefined);
const short = !value.short
? ''
: value.type === 'boolean'
? `-${value.short} `
const short = !value.short ? ''
: value.type === 'boolean' ? `-${value.short} `
: `-${value.short}<${hint}> `;
const left = value.type === 'boolean'
? `${short}--${field.name}`
const left = value.type === 'boolean' ?
`${short}--${field.name}`
: `${short}--${field.name}=<${hint}>`;
const row = { text, left, type: 'config' };
if (text.length > width - maxMax) {
@ -795,10 +916,11 @@ class Jack {
...(def.multiple ? { multiple: true } : {}),
...(def.delim ? { delim: def.delim } : {}),
...(def.short ? { short: def.short } : {}),
...(def.description
? { description: normalize(def.description) }
...(def.description ?
{ description: normalize(def.description) }
: {}),
...(def.validate ? { validate: def.validate } : {}),
...(def.validOptions ? { validOptions: def.validOptions } : {}),
...(def.default !== undefined ? { default: def.default } : {}),
},
]));
@ -813,12 +935,12 @@ class Jack {
exports.Jack = Jack;
// Unwrap and un-indent, so we can wrap description
// strings however makes them look nice in the code.
const normalize = (s, pre = false) => pre
? // prepend a ZWSP to each line so cliui doesn't strip it.
s
.split('\n')
.map(l => `\u200b${l}`)
.join('\n')
const normalize = (s, pre = false) => pre ?
// prepend a ZWSP to each line so cliui doesn't strip it.
s
.split('\n')
.map(l => `\u200b${l}`)
.join('\n')
: s
// remove single line breaks, except for lists
.replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`)
@ -832,8 +954,8 @@ const normalize = (s, pre = false) => pre
// normalize for markdown printing, remove leading spaces on lines
const normalizeMarkdown = (s, pre = false) => {
const n = normalize(s, pre).replace(/\\/g, '\\\\');
return pre
? `\`\`\`\n${n.replace(/\u200b/g, '')}\n\`\`\``
return pre ?
`\`\`\`\n${n.replace(/\u200b/g, '')}\n\`\`\``
: n.replace(/\n +/g, '\n').trim();
};
const normalizeOneLine = (s, pre = false) => {

2
my-app/node_modules/jackspeak/dist/commonjs/index.js.map generated vendored Executable file → Normal file

File diff suppressed because one or more lines are too long

4
my-app/node_modules/jackspeak/dist/commonjs/package.json generated vendored Executable file → Normal file
View file

@ -1 +1,3 @@
{"type":"commonjs"}
{
"type": "commonjs"
}

2
my-app/node_modules/jackspeak/dist/commonjs/parse-args-cjs.cjs.map generated vendored Executable file → Normal file
View file

@ -1 +1 @@
{"version":3,"file":"parse-args-cjs.cjs","sourceRoot":"","sources":["../../src/parse-args-cjs.cts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAE5B,MAAM,EAAE,GACN,OAAO,OAAO,KAAK,QAAQ;IAC3B,CAAC,CAAC,OAAO;IACT,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;IACjC,CAAC,CAAC,OAAO,CAAC,OAAO;IACjB,CAAC,CAAC,QAAQ,CAAA;AACd,MAAM,GAAG,GAAG,EAAE;KACX,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;KACjB,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAE5B,qBAAqB;AACrB,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;AAClC,oBAAoB;AAEpB,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,IAAI,CAAA;AAC5B,qBAAqB;AACrB,IACE,CAAC,EAAE;IACH,KAAK,GAAG,EAAE;IACV,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC;IAC5B,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC,EAC5B;IACA,oBAAoB;IACpB,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,SAAS,CAAA;CAC3C;AAEY,QAAA,SAAS,GAAG,EAAE,CAAA","sourcesContent":["import * as util from 'util'\n\nconst pv =\n typeof process === 'object' &&\n !!process &&\n typeof process.version === 'string'\n ? process.version\n : 'v0.0.0'\nconst pvs = pv\n .replace(/^v/, '')\n .split('.')\n .map(s => parseInt(s, 10))\n\n/* c8 ignore start */\nconst [major = 0, minor = 0] = pvs\n/* c8 ignore stop */\n\nlet { parseArgs: pa } = util\n/* c8 ignore start */\nif (\n !pa ||\n major < 16 ||\n (major === 18 && minor < 11) ||\n (major === 16 && minor < 19)\n) {\n /* c8 ignore stop */\n pa = require('@pkgjs/parseargs').parseArgs\n}\n\nexport const parseArgs = pa\n"]}
{"version":3,"file":"parse-args-cjs.cjs","sourceRoot":"","sources":["../../src/parse-args-cjs.cts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAE5B,MAAM,EAAE,GACN,CACE,OAAO,OAAO,KAAK,QAAQ;IAC3B,CAAC,CAAC,OAAO;IACT,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,CACpC,CAAC,CAAC;IACD,OAAO,CAAC,OAAO;IACjB,CAAC,CAAC,QAAQ,CAAA;AACZ,MAAM,GAAG,GAAG,EAAE;KACX,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;KACjB,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAE5B,qBAAqB;AACrB,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;AAClC,oBAAoB;AAEpB,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,IAAI,CAAA;AAC5B,qBAAqB;AACrB,IACE,CAAC,EAAE;IACH,KAAK,GAAG,EAAE;IACV,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC;IAC5B,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC,EAC5B,CAAC;IACD,oBAAoB;IACpB,EAAE,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC,SAAS,CAAA;AAC5C,CAAC;AAEY,QAAA,SAAS,GAAG,EAAE,CAAA","sourcesContent":["import * as util from 'util'\n\nconst pv =\n (\n typeof process === 'object' &&\n !!process &&\n typeof process.version === 'string'\n ) ?\n process.version\n : 'v0.0.0'\nconst pvs = pv\n .replace(/^v/, '')\n .split('.')\n .map(s => parseInt(s, 10))\n\n/* c8 ignore start */\nconst [major = 0, minor = 0] = pvs\n/* c8 ignore stop */\n\nlet { parseArgs: pa } = util\n/* c8 ignore start */\nif (\n !pa ||\n major < 16 ||\n (major === 18 && minor < 11) ||\n (major === 16 && minor < 19)\n) {\n /* c8 ignore stop */\n pa = require('@pkgjs/parseargs').parseArgs\n}\n\nexport const parseArgs = pa\n"]}

2
my-app/node_modules/jackspeak/dist/commonjs/parse-args-cjs.d.cts.map generated vendored Executable file → Normal file
View file

@ -1 +1 @@
{"version":3,"file":"parse-args-cjs.d.cts","sourceRoot":"","sources":["../../src/parse-args-cjs.cts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AA6B5B,eAAO,MAAM,SAAS,uBAAK,CAAA"}
{"version":3,"file":"parse-args-cjs.d.cts","sourceRoot":"","sources":["../../src/parse-args-cjs.cts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AA+B5B,eAAO,MAAM,SAAS,uBAAK,CAAA"}

0
my-app/node_modules/jackspeak/dist/commonjs/parse-args.d.ts generated vendored Executable file → Normal file
View file

View file

@ -1 +0,0 @@
{"version":3,"file":"parse-args.d.ts","sourceRoot":"","sources":["../../src/parse-args.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAkC5B,eAAO,MAAM,SAAS,uBAA2C,CAAA"}

6
my-app/node_modules/jackspeak/dist/commonjs/parse-args.js generated vendored Executable file → Normal file
View file

@ -25,10 +25,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseArgs = void 0;
const util = __importStar(require("util"));
const pv = typeof process === 'object' &&
const pv = (typeof process === 'object' &&
!!process &&
typeof process.version === 'string'
? process.version
typeof process.version === 'string') ?
process.version
: 'v0.0.0';
const pvs = pv
.replace(/^v/, '')

View file

@ -1 +0,0 @@
{"version":3,"file":"parse-args.js","sourceRoot":"","sources":["../../src/parse-args.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAA4B;AAE5B,MAAM,EAAE,GACN,OAAO,OAAO,KAAK,QAAQ;IAC3B,CAAC,CAAC,OAAO;IACT,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;IACjC,CAAC,CAAC,OAAO,CAAC,OAAO;IACjB,CAAC,CAAC,QAAQ,CAAA;AACd,MAAM,GAAG,GAAG,EAAE;KACX,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;KACjB,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAE5B,qBAAqB;AACrB,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;AAClC,oBAAoB;AAEpB,IAAI,EACF,SAAS,EAAE,EAAE,GACd,GAA8D,IAAI,CAAA;AAEnE,qBAAqB;AACrB,IACE,CAAC,EAAE;IACH,KAAK,GAAG,EAAE;IACV,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC;IAC5B,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC,EAC5B;IACA,oBAAoB;IACpB,iDAAiD;IACjD,YAAY;IACZ,EAAE,GAAG,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAA;CAClD;AAEY,QAAA,SAAS,GAAG,EAAwC,CAAA","sourcesContent":["import * as util from 'util'\n\nconst pv =\n typeof process === 'object' &&\n !!process &&\n typeof process.version === 'string'\n ? process.version\n : 'v0.0.0'\nconst pvs = pv\n .replace(/^v/, '')\n .split('.')\n .map(s => parseInt(s, 10))\n\n/* c8 ignore start */\nconst [major = 0, minor = 0] = pvs\n/* c8 ignore stop */\n\nlet {\n parseArgs: pa,\n}: typeof import('util') | typeof import('@pkgjs/parseargs') = util\n\n/* c8 ignore start */\nif (\n !pa ||\n major < 16 ||\n (major === 18 && minor < 11) ||\n (major === 16 && minor < 19)\n) {\n /* c8 ignore stop */\n // Ignore because we will clobber it for commonjs\n //@ts-ignore\n pa = (await import('@pkgjs/parseargs')).parseArgs\n}\n\nexport const parseArgs = pa as typeof import('util')['parseArgs']\n"]}

53
my-app/node_modules/jackspeak/dist/esm/index.d.ts generated vendored Executable file → Normal file
View file

@ -9,7 +9,7 @@ import { inspect, InspectOptions } from 'node:util';
* Defines the type of value that is valid, given a config definition's
* {@link ConfigType} and boolean multiple setting
*/
export type ValidValue<T extends ConfigType, M extends boolean> = [
export type ValidValue<T extends ConfigType = ConfigType, M extends boolean = boolean> = [
T,
M
] extends ['number', true] ? number[] : [T, M] extends ['string', true] ? string[] : [T, M] extends ['boolean', true] ? boolean[] : [T, M] extends ['number', false] ? number : [T, M] extends ['string', false] ? string : [T, M] extends ['boolean', false] ? boolean : [T, M] extends ['string', boolean] ? string | string[] : [T, M] extends ['boolean', boolean] ? boolean | boolean[] : [T, M] extends ['number', boolean] ? number | number[] : [T, M] extends [ConfigType, false] ? string | number | boolean : [T, M] extends [ConfigType, true] ? string[] | number[] | boolean[] : string | number | boolean | string[] | number[] | boolean[];
@ -17,23 +17,27 @@ export type ValidValue<T extends ConfigType, M extends boolean> = [
* The meta information for a config option definition, when the
* type and multiple values can be inferred by the method being used
*/
export type ConfigOptionMeta<T extends ConfigType, M extends boolean> = {
default?: ValidValue<T, M> | undefined;
export type ConfigOptionMeta<T extends ConfigType, M extends boolean = boolean, O extends undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[]) = undefined | (T extends 'boolean' ? never : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[])> = {
default?: undefined | (ValidValue<T, M> & (O extends number[] | string[] ? M extends false ? O[number] : O[number][] : unknown));
validOptions?: O;
description?: string;
validate?: ((v: any) => v is ValidValue<T, M>) | ((v: any) => boolean);
validate?: ((v: unknown) => v is ValidValue<T, M>) | ((v: unknown) => boolean);
short?: string | undefined;
type?: T;
} & (T extends 'boolean' ? {} : {
hint?: string | undefined;
}) & (M extends false ? {} : {
multiple?: M | undefined;
delim?: string | undefined;
hint?: T extends 'boolean' ? never : string;
delim?: M extends true ? string : never;
} & (M extends false ? {
multiple?: false | undefined;
} : M extends true ? {
multiple: true;
} : {
multiple?: boolean;
});
/**
* A set of {@link ConfigOptionMeta} fields, referenced by their longOption
* string values.
*/
export type ConfigMetaSet<T extends ConfigType, M extends boolean> = {
export type ConfigMetaSet<T extends ConfigType, M extends boolean = boolean> = {
[longOption: string]: ConfigOptionMeta<T, M>;
};
/**
@ -60,13 +64,14 @@ export type MultiType<M extends boolean> = M extends true ? {
/**
* A config field definition, in its full representation.
*/
export type ConfigOptionBase<T extends ConfigType, M extends boolean> = {
export type ConfigOptionBase<T extends ConfigType, M extends boolean = boolean> = {
type: T;
short?: string | undefined;
default?: ValidValue<T, M> | undefined;
description?: string;
hint?: T extends 'boolean' ? undefined : string | undefined;
validate?: (v: any) => v is ValidValue<T, M>;
validate?: (v: unknown) => v is ValidValue<T, M>;
validOptions?: T extends 'boolean' ? undefined : T extends 'string' ? readonly string[] : T extends 'number' ? readonly number[] : readonly number[] | readonly string[];
} & MultiType<M>;
export declare const isConfigType: (t: string) => t is ConfigType;
export declare const isConfigOption: <T extends ConfigType, M extends boolean>(o: any, type: T, multi: M) => o is ConfigOptionBase<T, M>;
@ -75,13 +80,13 @@ export declare const isConfigOption: <T extends ConfigType, M extends boolean>(o
* string values.
*/
export type ConfigSet = {
[longOption: string]: ConfigOptionBase<ConfigType, boolean>;
[longOption: string]: ConfigOptionBase<ConfigType>;
};
/**
* The 'values' field returned by {@link Jack#parse}
*/
export type OptionsResults<T extends ConfigSet> = {
[k in keyof T]?: T[k] extends ConfigOptionBase<'string', false> ? string : T[k] extends ConfigOptionBase<'string', true> ? string[] : T[k] extends ConfigOptionBase<'number', false> ? number : T[k] extends ConfigOptionBase<'number', true> ? number[] : T[k] extends ConfigOptionBase<'boolean', false> ? boolean : T[k] extends ConfigOptionBase<'boolean', true> ? boolean[] : never;
[k in keyof T]?: T[k]['validOptions'] extends (readonly string[] | readonly number[]) ? T[k] extends ConfigOptionBase<'string' | 'number', false> ? T[k]['validOptions'][number] : T[k] extends ConfigOptionBase<'string' | 'number', true> ? T[k]['validOptions'][number][] : never : T[k] extends ConfigOptionBase<'string', false> ? string : T[k] extends ConfigOptionBase<'string', true> ? string[] : T[k] extends ConfigOptionBase<'number', false> ? number : T[k] extends ConfigOptionBase<'number', true> ? number[] : T[k] extends ConfigOptionBase<'boolean', false> ? boolean : T[k] extends ConfigOptionBase<'boolean', true> ? boolean[] : never;
};
/**
* The object retured by {@link Jack#parse}
@ -140,7 +145,7 @@ export type TextRow = Heading | Description;
export type UsageField = TextRow | {
type: 'config';
name: string;
value: ConfigOptionBase<ConfigType, boolean>;
value: ConfigOptionBase<ConfigType>;
};
/**
* Options provided to the {@link Jack} constructor
@ -211,11 +216,18 @@ export declare class Jack<C extends ConfigSet = {}> {
* an explicit CLI setting.
*/
parse(args?: string[]): Parsed<C>;
/**
* Only parse the command line arguments passed in.
* Does not strip off the `node script.js` bits, so it must be just the
* arguments you wish to have parsed.
* Does not read from or write to the environment, or set defaults.
*/
parseRaw(args: string[]): Parsed<C>;
/**
* Validate that any arbitrary object is a valid configuration `values`
* object. Useful when loading config files or other sources.
*/
validate(o: any): asserts o is Parsed<C>['values'];
validate(o: unknown): asserts o is Parsed<C>['values'];
/**
* Add a heading to the usage output banner
*/
@ -235,7 +247,7 @@ export declare class Jack<C extends ConfigSet = {}> {
/**
* Add one or more multiple number fields.
*/
numList<F extends ConfigMetaSet<'number', true>>(fields: F): Jack<C & ConfigSetFromMetaSet<'number', true, F>>;
numList<F extends ConfigMetaSet<'number'>>(fields: F): Jack<C & ConfigSetFromMetaSet<'number', true, F>>;
/**
* Add one or more string option fields.
*/
@ -243,7 +255,7 @@ export declare class Jack<C extends ConfigSet = {}> {
/**
* Add one or more multiple string option fields.
*/
optList<F extends ConfigMetaSet<'string', true>>(fields: F): Jack<C & ConfigSetFromMetaSet<'string', true, F>>;
optList<F extends ConfigMetaSet<'string'>>(fields: F): Jack<C & ConfigSetFromMetaSet<'string', true, F>>;
/**
* Add one or more flag fields.
*/
@ -251,7 +263,7 @@ export declare class Jack<C extends ConfigSet = {}> {
/**
* Add one or more multiple flag fields.
*/
flagList<F extends ConfigMetaSet<'boolean', true>>(fields: F): Jack<C & ConfigSetFromMetaSet<'boolean', true, F>>;
flagList<F extends ConfigMetaSet<'boolean'>>(fields: F): Jack<C & ConfigSetFromMetaSet<'boolean', true, F>>;
/**
* Generic field definition method. Similar to flag/flagList/number/etc,
* but you must specify the `type` (and optionally `multiple` and `delim`)
@ -272,7 +284,8 @@ export declare class Jack<C extends ConfigSet = {}> {
toJSON(): {
[k: string]: {
default?: string | number | boolean | string[] | number[] | boolean[] | undefined;
validate?: ((v: any) => v is string | number | boolean | string[] | number[] | boolean[]) | undefined;
validOptions?: readonly number[] | readonly string[] | undefined;
validate?: ((v: unknown) => v is string | number | boolean | string[] | number[] | boolean[]) | undefined;
description?: string | undefined;
short?: string | undefined;
delim?: string | undefined;

2
my-app/node_modules/jackspeak/dist/esm/index.d.ts.map generated vendored Executable file → Normal file

File diff suppressed because one or more lines are too long

324
my-app/node_modules/jackspeak/dist/esm/index.js generated vendored Executable file → Normal file
View file

@ -15,50 +15,40 @@ const toEnvKey = (pref, key) => {
.replace(/ /g, '_');
};
const toEnvVal = (value, delim = '\n') => {
const str = typeof value === 'string'
? value
: typeof value === 'boolean'
? value
? '1'
const str = typeof value === 'string' ? value
: typeof value === 'boolean' ?
value ? '1'
: '0'
: typeof value === 'number'
? String(value)
: Array.isArray(value)
? value
.map((v) => toEnvVal(v))
.join(delim)
: /* c8 ignore start */
undefined;
: typeof value === 'number' ? String(value)
: Array.isArray(value) ?
value.map((v) => toEnvVal(v)).join(delim)
: /* c8 ignore start */ undefined;
if (typeof str !== 'string') {
throw new Error(`could not serialize value to environment: ${JSON.stringify(value)}`);
}
/* c8 ignore stop */
return str;
};
const fromEnvVal = (env, type, multiple, delim = '\n') => (multiple
? env
? env.split(delim).map(v => fromEnvVal(v, type, false))
const fromEnvVal = (env, type, multiple, delim = '\n') => (multiple ?
env ? env.split(delim).map(v => fromEnvVal(v, type, false))
: []
: type === 'string'
? env
: type === 'boolean'
? env === '1'
: type === 'string' ? env
: type === 'boolean' ? env === '1'
: +env.trim());
export const isConfigType = (t) => typeof t === 'string' &&
(t === 'string' || t === 'number' || t === 'boolean');
const undefOrType = (v, t) => v === undefined || typeof v === t;
const undefOrTypeArray = (v, t) => v === undefined || (Array.isArray(v) && v.every(x => typeof x === t));
const isValidOption = (v, vo) => Array.isArray(v) ? v.every(x => isValidOption(x, vo)) : vo.includes(v);
// print the value type, for error message reporting
const valueType = (v) => typeof v === 'string'
? 'string'
: typeof v === 'boolean'
? 'boolean'
: typeof v === 'number'
? 'number'
: Array.isArray(v)
? joinTypes([...new Set(v.map(v => valueType(v)))]) + '[]'
const valueType = (v) => typeof v === 'string' ? 'string'
: typeof v === 'boolean' ? 'boolean'
: typeof v === 'number' ? 'number'
: Array.isArray(v) ?
joinTypes([...new Set(v.map(v => valueType(v)))]) + '[]'
: `${v.type}${v.multiple ? '[]' : ''}`;
const joinTypes = (types) => types.length === 1 && typeof types[0] === 'string'
? types[0]
const joinTypes = (types) => types.length === 1 && typeof types[0] === 'string' ?
types[0]
: `(${types.join('|')})`;
const isValidValue = (v, type, multi) => {
if (multi) {
@ -78,79 +68,139 @@ export const isConfigOption = (o, type, multi) => !!o &&
undefOrType(o.description, 'string') &&
undefOrType(o.hint, 'string') &&
undefOrType(o.validate, 'function') &&
(o.type === 'boolean' ?
o.validOptions === undefined
: undefOrTypeArray(o.validOptions, o.type)) &&
(o.default === undefined || isValidValue(o.default, type, multi)) &&
!!o.multiple === multi;
function num(o = {}) {
const { default: def, validate: val, ...rest } = o;
const { default: def, validate: val, validOptions, ...rest } = o;
if (def !== undefined && !isValidValue(def, 'number', false)) {
throw new TypeError('invalid default value');
throw new TypeError('invalid default value', {
cause: {
found: def,
wanted: 'number',
},
});
}
const validate = val
? val
if (!undefOrTypeArray(validOptions, 'number')) {
throw new TypeError('invalid validOptions', {
cause: {
found: validOptions,
wanted: 'number[]',
},
});
}
const validate = val ?
val
: undefined;
return {
...rest,
default: def,
validate,
validOptions,
type: 'number',
multiple: false,
};
}
function numList(o = {}) {
const { default: def, validate: val, ...rest } = o;
const { default: def, validate: val, validOptions, ...rest } = o;
if (def !== undefined && !isValidValue(def, 'number', true)) {
throw new TypeError('invalid default value');
throw new TypeError('invalid default value', {
cause: {
found: def,
wanted: 'number[]',
},
});
}
const validate = val
? val
if (!undefOrTypeArray(validOptions, 'number')) {
throw new TypeError('invalid validOptions', {
cause: {
found: validOptions,
wanted: 'number[]',
},
});
}
const validate = val ?
val
: undefined;
return {
...rest,
default: def,
validate,
validOptions,
type: 'number',
multiple: true,
};
}
function opt(o = {}) {
const { default: def, validate: val, ...rest } = o;
const { default: def, validate: val, validOptions, ...rest } = o;
if (def !== undefined && !isValidValue(def, 'string', false)) {
throw new TypeError('invalid default value');
throw new TypeError('invalid default value', {
cause: {
found: def,
wanted: 'string',
},
});
}
const validate = val
? val
if (!undefOrTypeArray(validOptions, 'string')) {
throw new TypeError('invalid validOptions', {
cause: {
found: validOptions,
wanted: 'string[]',
},
});
}
const validate = val ?
val
: undefined;
return {
...rest,
default: def,
validate,
validOptions,
type: 'string',
multiple: false,
};
}
function optList(o = {}) {
const { default: def, validate: val, ...rest } = o;
const { default: def, validate: val, validOptions, ...rest } = o;
if (def !== undefined && !isValidValue(def, 'string', true)) {
throw new TypeError('invalid default value');
throw new TypeError('invalid default value', {
cause: {
found: def,
wanted: 'string[]',
},
});
}
const validate = val
? val
if (!undefOrTypeArray(validOptions, 'string')) {
throw new TypeError('invalid validOptions', {
cause: {
found: validOptions,
wanted: 'string[]',
},
});
}
const validate = val ?
val
: undefined;
return {
...rest,
default: def,
validate,
validOptions,
type: 'string',
multiple: true,
};
}
function flag(o = {}) {
const { hint, default: def, validate: val, ...rest } = o;
delete rest.validOptions;
if (def !== undefined && !isValidValue(def, 'boolean', false)) {
throw new TypeError('invalid default value');
}
const validate = val
? val
const validate = val ?
val
: undefined;
if (hint !== undefined) {
throw new TypeError('cannot provide hint for flag');
@ -165,11 +215,12 @@ function flag(o = {}) {
}
function flagList(o = {}) {
const { hint, default: def, validate: val, ...rest } = o;
delete rest.validOptions;
if (def !== undefined && !isValidValue(def, 'boolean', true)) {
throw new TypeError('invalid default value');
}
const validate = val
? val
const validate = val ?
val
: undefined;
if (hint !== undefined) {
throw new TypeError('cannot provide hint for flag list');
@ -202,8 +253,8 @@ const toParseArgsOptionsConfig = (options) => {
c[longOption] = {
type: 'string',
multiple: false,
default: config.default === undefined
? undefined
default: config.default === undefined ?
undefined
: String(config.default),
};
}
@ -211,7 +262,7 @@ const toParseArgsOptionsConfig = (options) => {
const conf = config;
c[longOption] = {
type: conf.type,
multiple: conf.multiple,
multiple: !!conf.multiple,
default: conf.default,
};
}
@ -269,14 +320,25 @@ export class Jack {
this.validate(values);
}
catch (er) {
throw Object.assign(er, source ? { source } : {});
const e = er;
if (source && e && typeof e === 'object') {
if (e.cause && typeof e.cause === 'object') {
Object.assign(e.cause, { path: source });
}
else {
e.cause = { path: source };
}
}
throw e;
}
for (const [field, value] of Object.entries(values)) {
const my = this.#configSet[field];
// already validated, just for TS's benefit
/* c8 ignore start */
if (!my) {
throw new Error('unexpected field in config set: ' + field);
throw new Error('unexpected field in config set: ' + field, {
cause: { found: field },
});
}
/* c8 ignore stop */
my.default = value;
@ -307,6 +369,23 @@ export class Jack {
}
}
}
const p = this.parseRaw(args);
for (const [field, c] of Object.entries(this.#configSet)) {
if (c.default !== undefined && !(field in p.values)) {
//@ts-ignore
p.values[field] = c.default;
}
}
this.#writeEnv(p);
return p;
}
/**
* Only parse the command line arguments passed in.
* Does not strip off the `node script.js` bits, so it must be just the
* arguments you wish to have parsed.
* Does not read from or write to the environment, or set defaults.
*/
parseRaw(args) {
const options = toParseArgsOptionsConfig(this.#configSet);
const result = parseArgs({
args,
@ -325,7 +404,7 @@ export class Jack {
p.positionals.push(token.value);
if (this.#options.stopAtPositional) {
p.positionals.push(...args.slice(token.index + 1));
return p;
break;
}
}
else if (token.kind === 'option') {
@ -347,18 +426,27 @@ export class Jack {
throw new Error(`Unknown option '${token.rawName}'. ` +
`To specify a positional argument starting with a '-', ` +
`place it at the end of the command after '--', as in ` +
`'-- ${token.rawName}'`);
`'-- ${token.rawName}'`, {
cause: {
found: token.rawName + (token.value ? `=${token.value}` : ''),
},
});
}
if (value === undefined) {
if (token.value === undefined) {
if (my.type !== 'boolean') {
throw new Error(`No value provided for ${token.rawName}, expected ${my.type}`);
throw new Error(`No value provided for ${token.rawName}, expected ${my.type}`, {
cause: {
name: token.rawName,
wanted: valueType(my),
},
});
}
value = true;
}
else {
if (my.type === 'boolean') {
throw new Error(`Flag ${token.rawName} does not take a value, received '${token.value}'`);
throw new Error(`Flag ${token.rawName} does not take a value, received '${token.value}'`, { cause: { found: token } });
}
if (my.type === 'string') {
value = token.value;
@ -367,7 +455,13 @@ export class Jack {
value = +token.value;
if (value !== value) {
throw new Error(`Invalid value '${token.value}' provided for ` +
`'${token.rawName}' option, expected number`);
`'${token.rawName}' option, expected number`, {
cause: {
name: token.rawName,
found: token.value,
wanted: 'number',
},
});
}
}
}
@ -384,19 +478,20 @@ export class Jack {
}
}
}
for (const [field, c] of Object.entries(this.#configSet)) {
if (c.default !== undefined && !(field in p.values)) {
//@ts-ignore
p.values[field] = c.default;
}
}
for (const [field, value] of Object.entries(p.values)) {
const valid = this.#configSet[field]?.validate;
const validOptions = this.#configSet[field]?.validOptions;
let cause;
if (validOptions && !isValidOption(value, validOptions)) {
cause = { name: field, found: value, validOptions: validOptions };
}
if (valid && !valid(value)) {
throw new Error(`Invalid value provided for --${field}: ${JSON.stringify(value)}`);
cause ??= { name: field, found: value };
}
if (cause) {
throw new Error(`Invalid value provided for --${field}: ${JSON.stringify(value)}`, { cause });
}
}
this.#writeEnv(p);
return p;
}
/**
@ -410,7 +505,7 @@ export class Jack {
// recurse so we get the core config key we care about.
this.#noNoFields(yes, val, s);
if (this.#configSet[yes]?.type === 'boolean') {
throw new Error(`do not set '${s}', instead set '${yes}' as desired.`);
throw new Error(`do not set '${s}', instead set '${yes}' as desired.`, { cause: { found: s, wanted: yes } });
}
}
/**
@ -419,22 +514,48 @@ export class Jack {
*/
validate(o) {
if (!o || typeof o !== 'object') {
throw new Error('Invalid config: not an object');
throw new Error('Invalid config: not an object', {
cause: { found: o },
});
}
const opts = o;
for (const field in o) {
this.#noNoFields(field, o[field]);
const value = opts[field];
/* c8 ignore next - for TS */
if (value === undefined)
continue;
this.#noNoFields(field, value);
const config = this.#configSet[field];
if (!config) {
throw new Error(`Unknown config option: ${field}`);
}
if (!isValidValue(o[field], config.type, !!config.multiple)) {
throw Object.assign(new Error(`Invalid value ${valueType(o[field])} for ${field}, expected ${valueType(config)}`), {
field,
value: o[field],
throw new Error(`Unknown config option: ${field}`, {
cause: { found: field },
});
}
if (config.validate && !config.validate(o[field])) {
throw new Error(`Invalid config value for ${field}: ${o[field]}`);
if (!isValidValue(value, config.type, !!config.multiple)) {
throw new Error(`Invalid value ${valueType(value)} for ${field}, expected ${valueType(config)}`, {
cause: {
name: field,
found: value,
wanted: valueType(config),
},
});
}
let cause;
if (config.validOptions &&
!isValidOption(value, config.validOptions)) {
cause = {
name: field,
found: value,
validOptions: config.validOptions,
};
}
if (config.validate && !config.validate(value)) {
cause ??= { name: field, found: value };
}
if (cause) {
throw new Error(`Invalid config value for ${field}: ${value}`, {
cause,
});
}
}
}
@ -745,21 +866,21 @@ export class Jack {
const { value } = field;
const desc = value.description || '';
const mult = value.multiple ? 'Can be set multiple times' : '';
const dmDelim = mult && (desc.includes('\n') ? '\n\n' : '\n');
const text = normalize(desc + dmDelim + mult);
const opts = value.validOptions?.length ?
`Valid options:${value.validOptions.map(v => ` ${JSON.stringify(v)}`)}`
: '';
const dmDelim = desc.includes('\n') ? '\n\n' : '\n';
const extra = [opts, mult].join(dmDelim).trim();
const text = (normalize(desc) + dmDelim + extra).trim();
const hint = value.hint ||
(value.type === 'number'
? 'n'
: value.type === 'string'
? field.name
(value.type === 'number' ? 'n'
: value.type === 'string' ? field.name
: undefined);
const short = !value.short
? ''
: value.type === 'boolean'
? `-${value.short} `
const short = !value.short ? ''
: value.type === 'boolean' ? `-${value.short} `
: `-${value.short}<${hint}> `;
const left = value.type === 'boolean'
? `${short}--${field.name}`
const left = value.type === 'boolean' ?
`${short}--${field.name}`
: `${short}--${field.name}=<${hint}>`;
const row = { text, left, type: 'config' };
if (text.length > width - maxMax) {
@ -787,10 +908,11 @@ export class Jack {
...(def.multiple ? { multiple: true } : {}),
...(def.delim ? { delim: def.delim } : {}),
...(def.short ? { short: def.short } : {}),
...(def.description
? { description: normalize(def.description) }
...(def.description ?
{ description: normalize(def.description) }
: {}),
...(def.validate ? { validate: def.validate } : {}),
...(def.validOptions ? { validOptions: def.validOptions } : {}),
...(def.default !== undefined ? { default: def.default } : {}),
},
]));
@ -804,12 +926,12 @@ export class Jack {
}
// Unwrap and un-indent, so we can wrap description
// strings however makes them look nice in the code.
const normalize = (s, pre = false) => pre
? // prepend a ZWSP to each line so cliui doesn't strip it.
s
.split('\n')
.map(l => `\u200b${l}`)
.join('\n')
const normalize = (s, pre = false) => pre ?
// prepend a ZWSP to each line so cliui doesn't strip it.
s
.split('\n')
.map(l => `\u200b${l}`)
.join('\n')
: s
// remove single line breaks, except for lists
.replace(/([^\n])\n[ \t]*([^\n])/g, (_, $1, $2) => !/^[-*]/.test($2) ? `${$1} ${$2}` : `${$1}\n${$2}`)
@ -823,8 +945,8 @@ const normalize = (s, pre = false) => pre
// normalize for markdown printing, remove leading spaces on lines
const normalizeMarkdown = (s, pre = false) => {
const n = normalize(s, pre).replace(/\\/g, '\\\\');
return pre
? `\`\`\`\n${n.replace(/\u200b/g, '')}\n\`\`\``
return pre ?
`\`\`\`\n${n.replace(/\u200b/g, '')}\n\`\`\``
: n.replace(/\n +/g, '\n').trim();
};
const normalizeOneLine = (s, pre = false) => {

2
my-app/node_modules/jackspeak/dist/esm/index.js.map generated vendored Executable file → Normal file

File diff suppressed because one or more lines are too long

4
my-app/node_modules/jackspeak/dist/esm/package.json generated vendored Executable file → Normal file
View file

@ -1 +1,3 @@
{"type":"module"}
{
"type": "module"
}

0
my-app/node_modules/jackspeak/dist/esm/parse-args.d.ts generated vendored Executable file → Normal file
View file

2
my-app/node_modules/jackspeak/dist/esm/parse-args.d.ts.map generated vendored Executable file → Normal file
View file

@ -1 +1 @@
{"version":3,"file":"parse-args.d.ts","sourceRoot":"","sources":["../../src/parse-args.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAkC5B,eAAO,MAAM,SAAS,uBAA2C,CAAA"}
{"version":3,"file":"parse-args.d.ts","sourceRoot":"","sources":["../../src/parse-args.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAoC5B,eAAO,MAAM,SAAS,uBAA6C,CAAA"}

10
my-app/node_modules/jackspeak/dist/esm/parse-args.js generated vendored Executable file → Normal file
View file

@ -1,8 +1,8 @@
import * as util from 'util';
const pv = typeof process === 'object' &&
const pv = (typeof process === 'object' &&
!!process &&
typeof process.version === 'string'
? process.version
typeof process.version === 'string') ?
process.version
: 'v0.0.0';
const pvs = pv
.replace(/^v/, '')
@ -12,15 +12,15 @@ const pvs = pv
const [major = 0, minor = 0] = pvs;
/* c8 ignore stop */
let { parseArgs: pa, } = util;
/* c8 ignore start */
/* c8 ignore start - version specific */
if (!pa ||
major < 16 ||
(major === 18 && minor < 11) ||
(major === 16 && minor < 19)) {
/* c8 ignore stop */
// Ignore because we will clobber it for commonjs
//@ts-ignore
pa = (await import('@pkgjs/parseargs')).parseArgs;
}
/* c8 ignore stop */
export const parseArgs = pa;
//# sourceMappingURL=parse-args.js.map

2
my-app/node_modules/jackspeak/dist/esm/parse-args.js.map generated vendored Executable file → Normal file
View file

@ -1 +1 @@
{"version":3,"file":"parse-args.js","sourceRoot":"","sources":["../../src/parse-args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,MAAM,EAAE,GACN,OAAO,OAAO,KAAK,QAAQ;IAC3B,CAAC,CAAC,OAAO;IACT,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ;IACjC,CAAC,CAAC,OAAO,CAAC,OAAO;IACjB,CAAC,CAAC,QAAQ,CAAA;AACd,MAAM,GAAG,GAAG,EAAE;KACX,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;KACjB,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAE5B,qBAAqB;AACrB,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;AAClC,oBAAoB;AAEpB,IAAI,EACF,SAAS,EAAE,EAAE,GACd,GAA8D,IAAI,CAAA;AAEnE,qBAAqB;AACrB,IACE,CAAC,EAAE;IACH,KAAK,GAAG,EAAE;IACV,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC;IAC5B,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC,EAC5B;IACA,oBAAoB;IACpB,iDAAiD;IACjD,YAAY;IACZ,EAAE,GAAG,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAA;CAClD;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,EAAwC,CAAA","sourcesContent":["import * as util from 'util'\n\nconst pv =\n typeof process === 'object' &&\n !!process &&\n typeof process.version === 'string'\n ? process.version\n : 'v0.0.0'\nconst pvs = pv\n .replace(/^v/, '')\n .split('.')\n .map(s => parseInt(s, 10))\n\n/* c8 ignore start */\nconst [major = 0, minor = 0] = pvs\n/* c8 ignore stop */\n\nlet {\n parseArgs: pa,\n}: typeof import('util') | typeof import('@pkgjs/parseargs') = util\n\n/* c8 ignore start */\nif (\n !pa ||\n major < 16 ||\n (major === 18 && minor < 11) ||\n (major === 16 && minor < 19)\n) {\n /* c8 ignore stop */\n // Ignore because we will clobber it for commonjs\n //@ts-ignore\n pa = (await import('@pkgjs/parseargs')).parseArgs\n}\n\nexport const parseArgs = pa as typeof import('util')['parseArgs']\n"]}
{"version":3,"file":"parse-args.js","sourceRoot":"","sources":["../../src/parse-args.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAE5B,MAAM,EAAE,GACN,CACE,OAAO,OAAO,KAAK,QAAQ;IAC3B,CAAC,CAAC,OAAO;IACT,OAAO,OAAO,CAAC,OAAO,KAAK,QAAQ,CACpC,CAAC,CAAC;IACD,OAAO,CAAC,OAAO;IACjB,CAAC,CAAC,QAAQ,CAAA;AACZ,MAAM,GAAG,GAAG,EAAE;KACX,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC;KACjB,KAAK,CAAC,GAAG,CAAC;KACV,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAA;AAE5B,qBAAqB;AACrB,MAAM,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,CAAC,GAAG,GAAG,CAAA;AAClC,oBAAoB;AAEpB,IAAI,EACF,SAAS,EAAE,EAAE,GACd,GAA8D,IAAI,CAAA;AAEnE,wCAAwC;AACxC,IACE,CAAC,EAAE;IACH,KAAK,GAAG,EAAE;IACV,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC;IAC5B,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,GAAG,EAAE,CAAC,EAC5B,CAAC;IACD,iDAAiD;IACjD,YAAY;IACZ,EAAE,GAAG,CAAC,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAA;AACnD,CAAC;AACD,oBAAoB;AAEpB,MAAM,CAAC,MAAM,SAAS,GAAG,EAA0C,CAAA","sourcesContent":["import * as util from 'util'\n\nconst pv =\n (\n typeof process === 'object' &&\n !!process &&\n typeof process.version === 'string'\n ) ?\n process.version\n : 'v0.0.0'\nconst pvs = pv\n .replace(/^v/, '')\n .split('.')\n .map(s => parseInt(s, 10))\n\n/* c8 ignore start */\nconst [major = 0, minor = 0] = pvs\n/* c8 ignore stop */\n\nlet {\n parseArgs: pa,\n}: typeof import('util') | typeof import('@pkgjs/parseargs') = util\n\n/* c8 ignore start - version specific */\nif (\n !pa ||\n major < 16 ||\n (major === 18 && minor < 11) ||\n (major === 16 && minor < 19)\n) {\n // Ignore because we will clobber it for commonjs\n //@ts-ignore\n pa = (await import('@pkgjs/parseargs')).parseArgs\n}\n/* c8 ignore stop */\n\nexport const parseArgs = pa as (typeof import('util'))['parseArgs']\n"]}

11
my-app/node_modules/jackspeak/package.json generated vendored Executable file → Normal file
View file

@ -1,6 +1,6 @@
{
"name": "jackspeak",
"version": "2.3.6",
"version": "3.2.0",
"description": "A very strict and proper argument parser.",
"tshy": {
"main": true,
@ -38,11 +38,12 @@
"presnap": "npm run prepare",
"test": "tap",
"snap": "tap",
"format": "prettier --write . --loglevel warn",
"format": "prettier --write . --log-level warn",
"typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts"
},
"license": "BlueOak-1.0.0",
"prettier": {
"experimentalTernaries": true,
"semi": false,
"printWidth": 75,
"tabWidth": 2,
@ -56,9 +57,9 @@
"devDependencies": {
"@types/node": "^20.7.0",
"@types/pkgjs__parseargs": "^0.10.1",
"prettier": "^2.8.6",
"tap": "^18.1.4",
"tshy": "^1.2.2",
"prettier": "^3.2.5",
"tap": "^18.8.0",
"tshy": "^1.14.0",
"typedoc": "^0.25.1",
"typescript": "^5.2.2"
},