@clerc/plugin-help 0.28.1 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +8 -8
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import{definePlugin as
|
|
2
|
-
`)};function
|
|
3
|
-
`),J=
|
|
4
|
-
`);
|
|
5
|
-
`)},
|
|
6
|
-
`),
|
|
1
|
+
import{definePlugin as M,Root as d,withBrackets as k,resolveCommandStrict as T,NoSuchCommandError as z,formatCommandName as y}from"@clerc/core";import G from"tty";const H=e=>Array.isArray(e)?e:[e],W=e=>e.replace(/([A-Z])/g,(t,n)=>`-${n.toLowerCase()}`),w=e=>e.length<=1?`-${e}`:`--${W(e)}`;var c={exports:{}};let P=G,q=!("NO_COLOR"in process.env||process.argv.includes("--no-color"))&&("FORCE_COLOR"in process.env||process.argv.includes("--color")||process.platform==="win32"||P.isatty(1)&&process.env.TERM!=="dumb"||"CI"in process.env),p=(e,t,n=e)=>o=>{let s=""+o,a=s.indexOf(t,e.length);return~a?e+_(s,t,n,a)+t:e+s+t},_=(e,t,n,o)=>{let s=e.substring(0,o)+n,a=e.substring(o+t.length),i=a.indexOf(t);return~i?s+_(a,t,n,i):s+a},D=(e=q)=>({isColorSupported:e,reset:e?t=>`\x1B[0m${t}\x1B[0m`:String,bold:e?p("\x1B[1m","\x1B[22m","\x1B[22m\x1B[1m"):String,dim:e?p("\x1B[2m","\x1B[22m","\x1B[22m\x1B[2m"):String,italic:e?p("\x1B[3m","\x1B[23m"):String,underline:e?p("\x1B[4m","\x1B[24m"):String,inverse:e?p("\x1B[7m","\x1B[27m"):String,hidden:e?p("\x1B[8m","\x1B[28m"):String,strikethrough:e?p("\x1B[9m","\x1B[29m"):String,black:e?p("\x1B[30m","\x1B[39m"):String,red:e?p("\x1B[31m","\x1B[39m"):String,green:e?p("\x1B[32m","\x1B[39m"):String,yellow:e?p("\x1B[33m","\x1B[39m"):String,blue:e?p("\x1B[34m","\x1B[39m"):String,magenta:e?p("\x1B[35m","\x1B[39m"):String,cyan:e?p("\x1B[36m","\x1B[39m"):String,white:e?p("\x1B[37m","\x1B[39m"):String,gray:e?p("\x1B[90m","\x1B[39m"):String,bgBlack:e?p("\x1B[40m","\x1B[49m"):String,bgRed:e?p("\x1B[41m","\x1B[49m"):String,bgGreen:e?p("\x1B[42m","\x1B[49m"):String,bgYellow:e?p("\x1B[43m","\x1B[49m"):String,bgBlue:e?p("\x1B[44m","\x1B[49m"):String,bgMagenta:e?p("\x1B[45m","\x1B[49m"):String,bgCyan:e?p("\x1B[46m","\x1B[49m"):String,bgWhite:e?p("\x1B[47m","\x1B[49m"):String});c.exports=D(),c.exports.createColors=D;var U=Function.prototype.toString,V=/\s*function(?:\s|\s*\/\*[^(?:*\/)]+\*\/\s*)*([^\s\(\/]+)/;function Y(e){if(typeof e!="function")return null;var t="";if(typeof Function.prototype.name=="undefined"&&typeof e.name=="undefined"){var n=U.call(e).match(V);n&&(t=n[1])}else t=e.name;return t}var j=Y,Z=function(e,t){t||(t={});var n=t.hsep===void 0?" ":t.hsep,o=t.align||[],s=t.stringLength||function(u){return String(u).length},a=N(e,function(u,m){return O(m,function(l,r){var h=B(l);(!u[r]||h>u[r])&&(u[r]=h)}),u},[]),i=x(e,function(u){return x(u,function(m,l){var r=String(m);if(o[l]==="."){var h=B(r),f=a[l]+(/\./.test(r)?1:2)-(s(r)-h);return r+Array(f).join(" ")}else return r})}),g=N(i,function(u,m){return O(m,function(l,r){var h=s(l);(!u[r]||h>u[r])&&(u[r]=h)}),u},[]);return x(i,function(u){return x(u,function(m,l){var r=g[l]-s(m)||0,h=Array(Math.max(r+1,1)).join(" ");return o[l]==="r"||o[l]==="."?h+m:o[l]==="c"?Array(Math.ceil(r/2+1)).join(" ")+m+Array(Math.floor(r/2+1)).join(" "):m+h}).join(n).replace(/\s+$/,"")}).join(`
|
|
2
|
+
`)};function B(e){var t=/\.[^.]*$/.exec(e);return t?t.index+1:e.length}function N(e,t,n){if(e.reduce)return e.reduce(t,n);for(var o=0,s=arguments.length>=3?n:e[o++];o<e.length;o++)t(s,e[o],o);return s}function O(e,t){if(e.forEach)return e.forEach(t);for(var n=0;n<e.length;n++)t.call(e,e[n],n)}function x(e,t){if(e.map)return e.map(t);for(var n=[],o=0;o<e.length;o++)n.push(t.call(e,e[o],o));return n}const C=(...e)=>Z(e),A=(...e)=>C(...e).toString().split(`
|
|
3
|
+
`),J=e=>Array.isArray(e)?`Array<${j(e[0])}>`:j(e),K=e=>{const t=[];for(const n of e){if(n.type==="block"||!n.type){const o=" ",s=n.body.map(i=>o+i);s.unshift("");const a=s.join(`
|
|
4
|
+
`);t.push(C([c.exports.bold(`${n.title}:`)],[a]).toString())}else if(n.type==="inline"){const o=n.items.map(a=>[c.exports.bold(`${a.title}:`),a.body]),s=C(...o);t.push(s.toString())}t.push("")}return t.join(`
|
|
5
|
+
`)},Q={en:{"help.name":"Name","help.version":"Version","help.subcommand":"Subcommand","help.commands":"Commands","help.flags":"Flags","help.description":"Description","help.usage":"Usage","help.examples":"Examples","help.notes":"Notes","help.noDescription":"(No description)","help.notes.1":"If no command is specified, show help for the CLI.","help.notes.2":"If a command is specified, show help for the command.","help.notes.3":"-h is an alias for --help.","help.examples.1":"Show help","help.examples.2":"Show help for a specific command","help.commandDescription":"Show help"},"zh-CN":{"help.name":"\u540D\u79F0","help.version":"\u7248\u672C","help.subcommand":"\u5B50\u547D\u4EE4","help.commands":"\u547D\u4EE4","help.flags":"\u6807\u5FD7","help.description":"\u63CF\u8FF0","help.usage":"\u4F7F\u7528","help.examples":"\u793A\u4F8B","help.notes":"\u5907\u6CE8","help.noDescription":"(\u65E0\u63CF\u8FF0)","help.notes.1":"\u5982\u679C\u6CA1\u6709\u6307\u5B9A\u5C55\u793A\u54EA\u4E2A\u547D\u4EE4\u7684\u5E2E\u52A9\u4FE1\u606F\uFF0C\u9ED8\u8BA4\u5C55\u793ACLI\u7684\u3002","help.notes.2":"\u5982\u679C\u6307\u5B9A\u4E86\u5219\u5C55\u793A\u8BE5\u547D\u4EE4\u5E2E\u52A9\u4FE1\u606F\u3002","help.notes.3":"-h \u662F --help \u7684\u4E00\u4E2A\u522B\u540D\u3002","help.examples.1":"\u5C55\u793A CLI \u7684\u5E2E\u52A9\u4FE1\u606F","help.examples.2":"\u5C55\u793A\u6307\u5B9A\u547D\u4EE4\u7684\u5E2E\u52A9\u4FE1\u606F","help.commandDescription":"\u5C55\u793A\u5E2E\u52A9\u4FE1\u606F"}},$=c.exports.yellow("-"),R=e=>{process.stdout.write(e)},F=(e,t,n)=>{const{t:o}=t.i18n,s=[{title:o("help.name"),body:c.exports.red(t._name)},{title:o("help.version"),body:c.exports.yellow(t._version)}];n&&s.push({title:o("help.subcommand"),body:c.exports.green(`${t._name} ${y(n.name)}`)}),e.push({type:"inline",items:s}),e.push({title:o("help.description"),body:[(n==null?void 0:n.description)||t._description]})},I=(e,t,n)=>{const o=t.map(([s,a])=>[s,$,a]);e.push({title:n("help.examples"),body:A(...o)})},v=(e,t,n,o)=>{const{cli:s}=t,{t:a}=s.i18n,i=[];F(i,s),i.push({title:a("help.usage"),body:[c.exports.magenta(`$ ${s._name} ${k("command",t.hasRootOrAlias)} [flags]`)]});const g=[...t.hasRoot?[s._commands[d]]:[],...Object.values(s._commands)].map(u=>{const m=[typeof u.name=="symbol"?"":u.name,...H(u.alias||[])].sort((l,r)=>l===d?-1:r===d?1:l.length-r.length).map(l=>l===""||typeof l=="symbol"?`${s._name}`:`${s._name} ${l}`).join(", ");return[c.exports.cyan(m),$,u.description]});return i.push({title:a("help.commands"),body:A(...g)}),n&&i.push({title:a("help.notes"),body:n}),o&&I(i,o,a),e(i)},E=(e,t,n)=>{var o;const{cli:s}=t,{t:a}=s.i18n,[i]=T(s._commands,n,a);if(!i)throw new z(y(n),a);const g=[];n===d?F(g,s):F(g,s,{...i,name:y(n)});const u=((o=i.parameters)==null?void 0:o.join(" "))||void 0,m=n===d?"":` ${y(n)}`,l=u?` ${u}`:"",r=i.flags?" [flags]":"";return g.push({title:a("help.usage"),body:[c.exports.magenta(`$ ${s._name}${m}${l}${r}`)]}),i.flags&&g.push({title:a("help.flags"),body:A(...Object.entries(i.flags).map(([h,f])=>{const b=[w(h)];f.alias&&b.push(w(f.alias));const S=[c.exports.blue(b.join(", "))];if(S.push($,f.description||a("help.noDescription")),f.type){const L=J(f.type);S.push(c.exports.gray(`(${L})`))}return S}))}),i.notes&&g.push({title:a("help.notes"),body:i.notes}),i.examples&&I(g,i.examples,a),e(g)},X=({command:e=!0,showHelpWhenNoCommand:t=!0,notes:n,examples:o,banner:s,renderer:a="cliffy"}={})=>M({setup:i=>{const{add:g,t:u}=i.i18n;g(Q);const m=a==="cliffy"?K:()=>"",l=r=>{s&&R(`${s}
|
|
6
|
+
`),R(r)};return e&&(i=i.command("help",u("help.commandDescription"),{parameters:["[command...]"],notes:[u("help.notes.1"),u("help.notes.2"),u("help.notes.3")],examples:[[`$ ${i._name} help`,u("help.examples.1")],[`$ ${i._name} help <command>`,u("help.examples.2")],[`$ ${i._name} <command> --help`,u("help.examples.2")]]}).on("help",r=>{r.parameters.command.length?l(E(m,r,r.parameters.command)):l(v(m,r,n,o))})),i.inspector((r,h)=>{const f=r.raw.mergedFlags.h||r.raw.mergedFlags.help;if(!r.hasRootOrAlias&&!r.raw._.length&&t&&!f){let b=`${u("core.noCommandGiven")}
|
|
7
7
|
|
|
8
|
-
`;
|
|
9
|
-
`,
|
|
8
|
+
`;b+=v(m,r,n,o),b+=`
|
|
9
|
+
`,l(b),process.exit(1)}else f?r.raw._.length?r.called!==d&&r.name===d?l(v(m,r,n,o)):l(E(m,r,r.raw._)):r.hasRootOrAlias?l(E(m,r,d)):l(v(m,r,n,o)):h()}),i}});export{X as helpPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-help",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.0",
|
|
4
4
|
"author": "Ray <nn_201312@163.com> (https://github.com/so1ve)",
|
|
5
5
|
"description": "Clerc plugin help",
|
|
6
6
|
"keywords": [
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"get-func-name": "^2.0.0",
|
|
56
56
|
"picocolors": "^1.0.0",
|
|
57
57
|
"text-table": "^0.2.0",
|
|
58
|
-
"@clerc/core": "0.
|
|
59
|
-
"@clerc/utils": "0.
|
|
58
|
+
"@clerc/core": "0.29.0",
|
|
59
|
+
"@clerc/utils": "0.29.0"
|
|
60
60
|
},
|
|
61
61
|
"scripts": {
|
|
62
62
|
"build": "puild --minify",
|