@thi.ng/args
Advanced tools
Comparing version 0.4.2 to 0.5.0
@@ -115,3 +115,4 @@ import type { Fn, IDeref, IObjectOf } from "@thi.ng/api"; | ||
/** | ||
* If true (default), display argument default values. | ||
* If true (default), display argument default values. Nullish or false | ||
* default values will never be shown. | ||
* | ||
@@ -122,3 +123,4 @@ * @defaultValue true | ||
/** | ||
* Prefix content to show before list of options. | ||
* Prefix content to show before list of options. Can contain ANSI control | ||
* seqs and will be automatically word wrapped to given `lineWidth`. | ||
* | ||
@@ -129,3 +131,4 @@ * @default empty string | ||
/** | ||
* Suffix content to show after list of options. | ||
* Suffix content to show after list of options. Can contain ANSI control | ||
* seqs and will be automatically word wrapped to given `lineWidth`. | ||
* | ||
@@ -132,0 +135,0 @@ * @default empty string |
@@ -221,2 +221,14 @@ import type { Fn } from "@thi.ng/api"; | ||
}; | ||
/** | ||
* Syntax sugar for `tuple(coerceFloat, size, {...}, delim)`. | ||
* | ||
* @param size | ||
* @param spec | ||
* @param delim | ||
*/ | ||
export declare const vec: <S extends Partial<ArgSpec<Tuple<number>>>>(size: number, spec: S, delim?: string) => S & { | ||
coerce: Fn<string, Tuple<number>>; | ||
hint: string; | ||
group: string; | ||
}; | ||
//# sourceMappingURL=args.d.ts.map |
10
args.js
@@ -80,3 +80,3 @@ import { repeat } from "@thi.ng/strings"; | ||
export const json = (spec) => (Object.assign({ coerce: coerceJson, hint: "JSON", group: "main" }, spec)); | ||
const $desc = (opts, prefix) => `${prefix ? prefix + ": " : ""}${opts.map((x) => `'${x}'`).join(", ")}`; | ||
const $desc = (opts, prefix) => `${prefix ? prefix + ": " : ""}${opts.map((x) => `"${x}"`).join(", ")}`; | ||
/** | ||
@@ -147,1 +147,9 @@ * Returns full {@link ArgSpec} for an enum-like string value arg. The raw CLI | ||
export const size = (size, spec, delim = "x") => tuple(coerceInt, size, spec, delim); | ||
/** | ||
* Syntax sugar for `tuple(coerceFloat, size, {...}, delim)`. | ||
* | ||
* @param size | ||
* @param spec | ||
* @param delim | ||
*/ | ||
export const vec = (size, spec, delim = ",") => tuple(coerceFloat, size, spec, delim); |
@@ -6,2 +6,14 @@ # Change Log | ||
# [0.5.0](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.4.2...@thi.ng/args@0.5.0) (2021-03-28) | ||
### Features | ||
* **args:** add vec() arg type ([f05cb2a](https://github.com/thi-ng/umbrella/commit/f05cb2a6d0798ef0558775a81dba2d834308747c)) | ||
* **args:** wordwrap usage prefix/suffix, defaults ([325b558](https://github.com/thi-ng/umbrella/commit/325b558f74f8dbfaa2c7de72c6800cdbc8c54acd)) | ||
## [0.4.2](https://github.com/thi-ng/umbrella/compare/@thi.ng/args@0.4.1...@thi.ng/args@0.4.2) (2021-03-24) | ||
@@ -8,0 +20,0 @@ |
@@ -67,3 +67,3 @@ 'use strict'; | ||
const json = (spec) => (Object.assign({ coerce: coerceJson, hint: "JSON", group: "main" }, spec)); | ||
const $desc = (opts, prefix) => `${prefix ? prefix + ": " : ""}${opts.map((x) => `'${x}'`).join(", ")}`; | ||
const $desc = (opts, prefix) => `${prefix ? prefix + ": " : ""}${opts.map((x) => `"${x}"`).join(", ")}`; | ||
const oneOf = (opts, spec) => (Object.assign(Object.assign({ coerce: coerceOneOf(opts), hint: "ID", group: "main" }, spec), { desc: $desc(opts, spec.desc) })); | ||
@@ -74,2 +74,3 @@ const oneOfMulti = (opts, spec) => (Object.assign(Object.assign({ coerce: (xs) => xs.map(coerceOneOf(opts)), hint: $hint("ID", spec.delim), multi: true, group: "main" }, spec), { desc: $desc(opts, spec.desc) })); | ||
const size = (size, spec, delim = "x") => tuple(coerceInt, size, spec, delim); | ||
const vec = (size, spec, delim = ",") => tuple(coerceFloat, size, spec, delim); | ||
@@ -81,3 +82,2 @@ const usage = (specs, opts = {}) => { | ||
const indent = strings$1.repeat(" ", opts.paramWidth); | ||
const ansi = (x, col) => col != null ? `\x1b[${col}m${x}\x1b[0m` : x; | ||
const format = (ids) => ids.map((id) => { | ||
@@ -98,4 +98,6 @@ const spec = specs[id]; | ||
: ""; | ||
const defaults = opts.showDefaults && spec.default !== undefined | ||
? ansi(` (default: ${strings$1.stringify()(spec.defaultHint != undefined | ||
const defaults = opts.showDefaults && | ||
spec.default != null && | ||
spec.default !== false | ||
? ansi(` (default: ${strings$1.stringify(true)(spec.defaultHint != undefined | ||
? spec.defaultHint | ||
@@ -105,7 +107,3 @@ : spec.default)})`, theme.default) | ||
return (strings$1.padRight(opts.paramWidth)(params, strings$1.lengthAnsi(params)) + | ||
strings$1.wordWrapLines(prefix + (spec.desc || "") + defaults, { | ||
width: opts.lineWidth - opts.paramWidth, | ||
splitter: strings$1.SPLIT_ANSI, | ||
hard: true, | ||
}) | ||
wrap(prefix + (spec.desc || "") + defaults, opts.lineWidth - opts.paramWidth) | ||
.map((l, i) => (i > 0 ? indent + l : l)) | ||
@@ -119,7 +117,15 @@ .join("\n")); | ||
return [ | ||
opts.prefix, | ||
...wrap(opts.prefix, opts.lineWidth), | ||
...groups.map((ids) => format(ids).join("\n") + "\n"), | ||
opts.suffix, | ||
...wrap(opts.suffix, opts.lineWidth), | ||
].join("\n"); | ||
}; | ||
const ansi = (x, col) => col != null ? `\x1b[${col}m${x}\x1b[0m` : x; | ||
const wrap = (str, width) => str | ||
? strings$1.wordWrapLines(str, { | ||
width, | ||
splitter: strings$1.SPLIT_ANSI, | ||
hard: true, | ||
}) | ||
: []; | ||
@@ -268,1 +274,2 @@ const parse = (specs, argv, opts) => { | ||
exports.usage = usage; | ||
exports.vec = vec; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/strings"),require("@thi.ng/checks"),require("@thi.ng/errors")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/strings","@thi.ng/checks","@thi.ng/errors"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.args={}),e.thi.ng.strings,e.thi.ng.checks,e.thi.ng.errors)}(this,(function(e,t,s,i){"use strict";const r={default:95,hint:90,multi:90,param:96,required:33};class n{constructor(e){this.value=e}deref(){return this.value}}const a=e=>s.isNumericFloat(e)?parseFloat(e):i.illegalArgs(`not a numeric value: ${e}`),l=e=>e.map(a),o=e=>s.isHex(e)?parseInt(e,16):i.illegalArgs(`not a hex value: ${e}`),c=e=>e.map(o),u=e=>s.isNumericInt(e)?parseInt(e):i.illegalArgs(`not an integer: ${e}`),g=e=>e.map(u),p=e=>JSON.parse(e),h=e=>t=>e.includes(t)?t:i.illegalArgs(`invalid option: ${t}`),d=(e="=",t=!1)=>s=>s.reduce(((s,r)=>{const n=r.indexOf(e);return t&&n<1&&i.illegalArgs(`got '${r}', but expected a 'key${e}value' pair`),n>0?s[r.substr(0,n)]=r.substr(n+1):s[r]="true",s}),{}),f=(e,t,s=",")=>r=>{const a=r.split(s);return a.length!==t&&i.illegalArgs(`got '${r}', but expected a tuple of ${t} values`),new n(a.map(e))},m=(e,t)=>s=>Object.assign({coerce:e,hint:t,group:"main"},s),b=(e,t)=>s=>Object.assign({hint:$(t,s.delim),multi:!0,coerce:e,group:"main"},s),$=(e,t)=>e+(t?`[${t}..]`:""),O=m((e=>e),"STR"),j=b((e=>e),"STR"),v=m(a,"NUM"),x=m(o,"HEX"),A=m(u,"INT"),I=b(l,"NUM"),y=b(c,"HEX"),k=b(g,"INT"),w=(e,t)=>`${t?t+": ":""}${e.map((e=>`'${e}'`)).join(", ")}`,T=(e,s,i,r=",")=>Object.assign({coerce:f(e,s,r),hint:[...t.repeat("N",s)].join(r),group:"main"},i),N=(e,s={})=>{const i=!1!==(s=Object.assign({lineWidth:80,paramWidth:32,showDefaults:!0,prefix:"",suffix:"",groups:["flags","main"]},s)).color?Object.assign(Object.assign({},r),s.color):{},n=t.repeat(" ",s.paramWidth),a=(e,t)=>null!=t?`[${t}m${e}[0m`:e,l=Object.keys(e).sort(),o=s.groups?s.groups.map((t=>l.filter((s=>e[s].group===t)))):[l];return[s.prefix,...o.map((r=>(r=>r.map((r=>{const l=e[r],o=l.hint?a(" "+l.hint,i.hint):"",c=a(`--${t.kebab(r)}`,i.param),u=`${l.alias?`${a("-"+l.alias,i.param)}${o}, `:""}${c}${o}`,g=!1===l.optional&&void 0===l.default,p=[];g&&p.push("required"),l.multi&&p.push("multiple");const h=p.length?a(`[${p.join(", ")}] `,g?i.required:i.multi):"",d=s.showDefaults&&void 0!==l.default?a(` (default: ${t.stringify()(null!=l.defaultHint?l.defaultHint:l.default)})`,i.default):"";return t.padRight(s.paramWidth)(u,t.lengthAnsi(u))+t.wordWrapLines(h+(l.desc||"")+d,{width:s.lineWidth-s.paramWidth,splitter:t.SPLIT_ANSI,hard:!0}).map(((e,t)=>t>0?n+e:e)).join("\n")})))(r).join("\n")+"\n")),s.suffix].join("\n")},H=(e,t,s)=>{const r=S(e),n={};let a,l,o=s.start;for(;o<t.length;){const i=t[o];if(a){if(q(l,n,a,i))break;a=null,o++}else{if(s.help.includes(i))return void console.log(N(e,s.usageOpts));const t=W(e,r,n,i);if(a=t.id,l=t.spec,o+=~~(t.state<2),t.state)break}}return a&&i.illegalArgs(`missing value for: --${a}`),{result:E(e,n),index:o,rest:t.slice(o),done:o>=t.length}},S=e=>Object.entries(e).reduce(((e,[t,s])=>s.alias?(e[s.alias]=t,e):e),{}),W=(e,s,r,n)=>{if("-"===n[0]){let a;if("-"===n[1]){if("--"===n)return{state:1};a=t.camel(n.substr(2))}else a=s[n.substr(1)],!a&&i.illegalArgs(`unknown option: ${n}`);const l=e[a];return!l&&i.illegalArgs(a),l.flag&&(r[a]=!0,a=void 0,l.fn&&!l.fn("true"))?{state:1,spec:l}:{state:0,id:a,spec:l}}return{state:2}},q=(e,t,r,n)=>(/^-[a-z]/i.test(n)&&i.illegalArgs(`missing value for: --${r}`),e.multi?s.isArray(t[r])?t[r].push(n):t[r]=[n]:t[r]=n,e.fn&&!e.fn(n)),E=(e,t)=>{let s;for(let r in e)s=e[r],void 0===t[r]?void 0!==s.default?t[r]=s.default:!1===s.optional&&i.illegalArgs(`missing arg: --${r}`):s.coerce&&D(s,t,r);return t},D=(e,t,s)=>{try{e.multi&&e.delim&&(t[s]=t[s].reduce(((t,s)=>(t.push(...s.split(e.delim)),t)),[])),t[s]=e.coerce(t[s])}catch(e){throw new Error(`arg --${s}: ${e.message}`)}};e.DEFAULT_THEME=r,e.Tuple=n,e.coerceFloat=a,e.coerceFloats=l,e.coerceHexInt=o,e.coerceHexInts=c,e.coerceInt=u,e.coerceInts=g,e.coerceJson=p,e.coerceKV=d,e.coerceOneOf=h,e.coerceString=e=>e,e.coerceTuple=f,e.flag=e=>Object.assign({flag:!0,default:!1,group:"flags"},e),e.float=v,e.floats=I,e.hex=x,e.hexes=y,e.int=A,e.ints=k,e.json=e=>Object.assign({coerce:p,hint:"JSON",group:"main"},e),e.kvPairs=(e,t="=",s)=>Object.assign({coerce:d(t,s),hint:`key${t}val`,multi:!0,group:"main"},e),e.oneOf=(e,t)=>Object.assign(Object.assign({coerce:h(e),hint:"ID",group:"main"},t),{desc:w(e,t.desc)}),e.oneOfMulti=(e,t)=>Object.assign(Object.assign({coerce:t=>t.map(h(e)),hint:$("ID",t.delim),multi:!0,group:"main"},t),{desc:w(e,t.desc)}),e.parse=(e,t,s)=>{s=Object.assign({start:2,showUsage:!0,help:["--help","-h"]},s);try{return H(e,t,s)}catch(t){throw s.showUsage&&console.log(t.message+"\n\n"+N(e,s.usageOpts)),t}},e.size=(e,t,s="x")=>T(u,e,t,s),e.string=O,e.strings=j,e.tuple=T,e.usage=N,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@thi.ng/strings"),require("@thi.ng/checks"),require("@thi.ng/errors")):"function"==typeof define&&define.amd?define(["exports","@thi.ng/strings","@thi.ng/checks","@thi.ng/errors"],t):t(((e="undefined"!=typeof globalThis?globalThis:e||self).thi=e.thi||{},e.thi.ng=e.thi.ng||{},e.thi.ng.args={}),e.thi.ng.strings,e.thi.ng.checks,e.thi.ng.errors)}(this,(function(e,t,i,s){"use strict";const r={default:95,hint:90,multi:90,param:96,required:33};class n{constructor(e){this.value=e}deref(){return this.value}}const a=e=>i.isNumericFloat(e)?parseFloat(e):s.illegalArgs(`not a numeric value: ${e}`),l=e=>e.map(a),o=e=>i.isHex(e)?parseInt(e,16):s.illegalArgs(`not a hex value: ${e}`),c=e=>e.map(o),u=e=>i.isNumericInt(e)?parseInt(e):s.illegalArgs(`not an integer: ${e}`),g=e=>e.map(u),p=e=>JSON.parse(e),h=e=>t=>e.includes(t)?t:s.illegalArgs(`invalid option: ${t}`),d=(e="=",t=!1)=>i=>i.reduce(((i,r)=>{const n=r.indexOf(e);return t&&n<1&&s.illegalArgs(`got '${r}', but expected a 'key${e}value' pair`),n>0?i[r.substr(0,n)]=r.substr(n+1):i[r]="true",i}),{}),f=(e,t,i=",")=>r=>{const a=r.split(i);return a.length!==t&&s.illegalArgs(`got '${r}', but expected a tuple of ${t} values`),new n(a.map(e))},m=(e,t)=>i=>Object.assign({coerce:e,hint:t,group:"main"},i),b=(e,t)=>i=>Object.assign({hint:$(t,i.delim),multi:!0,coerce:e,group:"main"},i),$=(e,t)=>e+(t?`[${t}..]`:""),O=m((e=>e),"STR"),j=b((e=>e),"STR"),v=m(a,"NUM"),x=m(o,"HEX"),A=m(u,"INT"),I=b(l,"NUM"),y=b(c,"HEX"),k=b(g,"INT"),w=(e,t)=>`${t?t+": ":""}${e.map((e=>`"${e}"`)).join(", ")}`,T=(e,i,s,r=",")=>Object.assign({coerce:f(e,i,r),hint:[...t.repeat("N",i)].join(r),group:"main"},s),N=(e,i={})=>{const s=!1!==(i=Object.assign({lineWidth:80,paramWidth:32,showDefaults:!0,prefix:"",suffix:"",groups:["flags","main"]},i)).color?Object.assign(Object.assign({},r),i.color):{},n=t.repeat(" ",i.paramWidth),a=Object.keys(e).sort(),l=i.groups?i.groups.map((t=>a.filter((i=>e[i].group===t)))):[a];return[...H(i.prefix,i.lineWidth),...l.map((r=>(r=>r.map((r=>{const a=e[r],l=a.hint?W(" "+a.hint,s.hint):"",o=W(`--${t.kebab(r)}`,s.param),c=`${a.alias?`${W("-"+a.alias,s.param)}${l}, `:""}${o}${l}`,u=!1===a.optional&&void 0===a.default,g=[];u&&g.push("required"),a.multi&&g.push("multiple");const p=g.length?W(`[${g.join(", ")}] `,u?s.required:s.multi):"",h=i.showDefaults&&null!=a.default&&!1!==a.default?W(` (default: ${t.stringify(!0)(null!=a.defaultHint?a.defaultHint:a.default)})`,s.default):"";return t.padRight(i.paramWidth)(c,t.lengthAnsi(c))+H(p+(a.desc||"")+h,i.lineWidth-i.paramWidth).map(((e,t)=>t>0?n+e:e)).join("\n")})))(r).join("\n")+"\n")),...H(i.suffix,i.lineWidth)].join("\n")},W=(e,t)=>null!=t?`[${t}m${e}[0m`:e,H=(e,i)=>e?t.wordWrapLines(e,{width:i,splitter:t.SPLIT_ANSI,hard:!0}):[],S=(e,t,i)=>{const r=q(e),n={};let a,l,o=i.start;for(;o<t.length;){const s=t[o];if(a){if(D(l,n,a,s))break;a=null,o++}else{if(i.help.includes(s))return void console.log(N(e,i.usageOpts));const t=E(e,r,n,s);if(a=t.id,l=t.spec,o+=~~(t.state<2),t.state)break}}return a&&s.illegalArgs(`missing value for: --${a}`),{result:F(e,n),index:o,rest:t.slice(o),done:o>=t.length}},q=e=>Object.entries(e).reduce(((e,[t,i])=>i.alias?(e[i.alias]=t,e):e),{}),E=(e,i,r,n)=>{if("-"===n[0]){let a;if("-"===n[1]){if("--"===n)return{state:1};a=t.camel(n.substr(2))}else a=i[n.substr(1)],!a&&s.illegalArgs(`unknown option: ${n}`);const l=e[a];return!l&&s.illegalArgs(a),l.flag&&(r[a]=!0,a=void 0,l.fn&&!l.fn("true"))?{state:1,spec:l}:{state:0,id:a,spec:l}}return{state:2}},D=(e,t,r,n)=>(/^-[a-z]/i.test(n)&&s.illegalArgs(`missing value for: --${r}`),e.multi?i.isArray(t[r])?t[r].push(n):t[r]=[n]:t[r]=n,e.fn&&!e.fn(n)),F=(e,t)=>{let i;for(let r in e)i=e[r],void 0===t[r]?void 0!==i.default?t[r]=i.default:!1===i.optional&&s.illegalArgs(`missing arg: --${r}`):i.coerce&&M(i,t,r);return t},M=(e,t,i)=>{try{e.multi&&e.delim&&(t[i]=t[i].reduce(((t,i)=>(t.push(...i.split(e.delim)),t)),[])),t[i]=e.coerce(t[i])}catch(e){throw new Error(`arg --${i}: ${e.message}`)}};e.DEFAULT_THEME=r,e.Tuple=n,e.coerceFloat=a,e.coerceFloats=l,e.coerceHexInt=o,e.coerceHexInts=c,e.coerceInt=u,e.coerceInts=g,e.coerceJson=p,e.coerceKV=d,e.coerceOneOf=h,e.coerceString=e=>e,e.coerceTuple=f,e.flag=e=>Object.assign({flag:!0,default:!1,group:"flags"},e),e.float=v,e.floats=I,e.hex=x,e.hexes=y,e.int=A,e.ints=k,e.json=e=>Object.assign({coerce:p,hint:"JSON",group:"main"},e),e.kvPairs=(e,t="=",i)=>Object.assign({coerce:d(t,i),hint:`key${t}val`,multi:!0,group:"main"},e),e.oneOf=(e,t)=>Object.assign(Object.assign({coerce:h(e),hint:"ID",group:"main"},t),{desc:w(e,t.desc)}),e.oneOfMulti=(e,t)=>Object.assign(Object.assign({coerce:t=>t.map(h(e)),hint:$("ID",t.delim),multi:!0,group:"main"},t),{desc:w(e,t.desc)}),e.parse=(e,t,i)=>{i=Object.assign({start:2,showUsage:!0,help:["--help","-h"]},i);try{return S(e,t,i)}catch(t){throw i.showUsage&&console.log(t.message+"\n\n"+N(e,i.usageOpts)),t}},e.size=(e,t,i="x")=>T(u,e,t,i),e.string=O,e.strings=j,e.tuple=T,e.usage=N,e.vec=(e,t,i=",")=>T(a,e,t,i),Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@thi.ng/args", | ||
"version": "0.4.2", | ||
"version": "0.5.0", | ||
"description": "Declarative, functional & typechecked CLI argument/options parser, value coercions etc.", | ||
@@ -86,3 +86,3 @@ "module": "./index.js", | ||
}, | ||
"gitHead": "0db78c0f3d09e085dd790d7d677ce85126ce4750" | ||
"gitHead": "eb961d221997bb8585ba08eab5d0d8a7920c58dd" | ||
} |
@@ -64,3 +64,3 @@ <!-- This file is generated - DO NOT EDIT! --> | ||
Package sizes (gzipped, pre-treeshake): ESM: 2.17 KB / CJS: 2.29 KB / UMD: 2.25 KB | ||
Package sizes (gzipped, pre-treeshake): ESM: 2.21 KB / CJS: 2.34 KB / UMD: 2.29 KB | ||
@@ -90,2 +90,3 @@ ## Dependencies | ||
size?: Tuple<number>; | ||
pos?: Tuple<number>; | ||
xtra?: { a: number; b: string }; | ||
@@ -128,2 +129,5 @@ define?: KVDict; | ||
size: size(2, { hint: "WxH", desc: "Target size" }), | ||
// another version for tuples of floating point values | ||
// pos: tuple(coerceFloat, 2, { desc: "Lat/Lon" }, ","), | ||
pos: vec(2, { desc: "Lat/Lon" }), | ||
// JSON string arg | ||
@@ -171,2 +175,3 @@ xtra: json({ | ||
-D key=val, --define key=val [multiple] Define dict entry | ||
--pos N,N Lat/Lon | ||
--size WxH Target size | ||
@@ -173,0 +178,0 @@ -t ID, --type ID [required] Image type: 'png', 'jpg', 'gif', |
25
usage.js
@@ -8,3 +8,2 @@ import { kebab, lengthAnsi, padRight, repeat, SPLIT_ANSI, stringify, wordWrapLines, } from "@thi.ng/strings"; | ||
const indent = repeat(" ", opts.paramWidth); | ||
const ansi = (x, col) => col != null ? `\x1b[${col}m${x}\x1b[0m` : x; | ||
const format = (ids) => ids.map((id) => { | ||
@@ -25,4 +24,6 @@ const spec = specs[id]; | ||
: ""; | ||
const defaults = opts.showDefaults && spec.default !== undefined | ||
? ansi(` (default: ${stringify()(spec.defaultHint != undefined | ||
const defaults = opts.showDefaults && | ||
spec.default != null && | ||
spec.default !== false | ||
? ansi(` (default: ${stringify(true)(spec.defaultHint != undefined | ||
? spec.defaultHint | ||
@@ -32,7 +33,3 @@ : spec.default)})`, theme.default) | ||
return (padRight(opts.paramWidth)(params, lengthAnsi(params)) + | ||
wordWrapLines(prefix + (spec.desc || "") + defaults, { | ||
width: opts.lineWidth - opts.paramWidth, | ||
splitter: SPLIT_ANSI, | ||
hard: true, | ||
}) | ||
wrap(prefix + (spec.desc || "") + defaults, opts.lineWidth - opts.paramWidth) | ||
.map((l, i) => (i > 0 ? indent + l : l)) | ||
@@ -46,6 +43,14 @@ .join("\n")); | ||
return [ | ||
opts.prefix, | ||
...wrap(opts.prefix, opts.lineWidth), | ||
...groups.map((ids) => format(ids).join("\n") + "\n"), | ||
opts.suffix, | ||
...wrap(opts.suffix, opts.lineWidth), | ||
].join("\n"); | ||
}; | ||
const ansi = (x, col) => col != null ? `\x1b[${col}m${x}\x1b[0m` : x; | ||
const wrap = (str, width) => str | ||
? wordWrapLines(str, { | ||
width, | ||
splitter: SPLIT_ANSI, | ||
hard: true, | ||
}) | ||
: []; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
92837
1056
227