cleye 1.0.1 → 1.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Hiroki Osame <hiroki.osame@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -170,7 +170,7 @@ _Cleye_'s flag parsing is powered by [`type-flag`](https://github.com/privatenum
170
170
  - Array & Custom types
171
171
  - Flag delimiters: `--flag value`, `--flag=value`, `--flag:value`, and `--flag.value`
172
172
  - Combined aliases: `-abcd 2` → `-a -b -c -d 2`
173
- - Early termination: Pass in `--` to end flag parsing
173
+ - [End of flags](https://unix.stackexchange.com/a/11382): Pass in `--` to end flag parsing
174
174
  - Unknown flags: Unexpected flags stored in `unknownFlags`
175
175
 
176
176
 
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ var M=Object.create;var y=Object.defineProperty,W=Object.defineProperties,Z=Obje
3
3
  `}}function ae(t){var n;let e=t.help||{};if("usage"in e)return e.usage?{id:"usage",type:"section",data:{title:"Usage:",body:Array.isArray(e.usage)?e.usage.join(`
4
4
  `):e.usage}}:void 0;if(t.name){let a=[],r=[j(t)];if(t.flags&&Object.keys(t.flags).length>0&&r.push("[flags...]"),t.parameters&&t.parameters.length>0&&r.push(t.parameters.join(" ")),r.length>1&&a.push(r.join(" ")),"commands"in t&&((n=t.commands)==null?void 0:n.length)&&a.push(`${t.name} <command>`),a.length>0)return{id:"usage",type:"section",data:{title:"Usage:",body:a.join(`
5
5
  `)}}}}function se(t){var a;if(!("commands"in t)||!((a=t.commands)==null?void 0:a.length))return;let e=t.commands.map(r=>[r.options.name,r.options.help?r.options.help.description:""]);return{id:"commands",type:"section",data:{title:"Commands:",body:{type:"table",data:{tableData:e,tableOptions:[{width:"content-width",paddingLeft:2,paddingRight:8}]}},indentBody:0}}}function ie(t){if(!(!t.flags||Object.keys(t.flags).length===0))return{id:"flags",type:"section",data:{title:"Flags:",body:I(t.flags),indentBody:0}}}function oe(t){let{help:e}=t;if(!e||!e.examples||e.examples.length===0)return;let{examples:n}=e;if(Array.isArray(n)&&(n=n.join(`
6
- `)),n)return{id:"examples",type:"section",data:{title:"Examples:",body:n}}}function me(t){if(!("alias"in t)||!t.alias)return;let{alias:e}=t,n=Array.isArray(e)?e.join(", "):e;return{id:"aliases",type:"section",data:{title:"Aliases:",body:n}}}var $=t=>[ne,re,ae,se,ie,oe,me].map(e=>e(t)).filter(e=>Boolean(e));var K=A(require("tty")),C=A(require("terminal-columns")),pe=K.default.WriteStream.prototype.hasColors(),b=class{text(e){return e}bold(e){return`${e}`}indentText({text:e,spaces:n}){return e.replace(/^/gm," ".repeat(n))}heading(e){return pe?this.bold(e):e.toLocaleUpperCase()}section({title:e,body:n,indentBody:a=2}){return`${(e?`${this.heading(e)}
6
+ `)),n)return{id:"examples",type:"section",data:{title:"Examples:",body:n}}}function me(t){if(!("alias"in t)||!t.alias)return;let{alias:e}=t,n=Array.isArray(e)?e.join(", "):e;return{id:"aliases",type:"section",data:{title:"Aliases:",body:n}}}var $=t=>[ne,re,ae,se,ie,oe,me].map(e=>e(t)).filter(e=>Boolean(e));var K=A(require("tty")),C=A(require("terminal-columns")),pe=K.default.WriteStream.prototype.hasColors(),b=class{text(e){return e}bold(e){return pe?`${e}`:e.toLocaleUpperCase()}indentText({text:e,spaces:n}){return e.replace(/^/gm," ".repeat(n))}heading(e){return this.bold(e)}section({title:e,body:n,indentBody:a=2}){return`${(e?`${this.heading(e)}
7
7
  `:"")+(n?this.indentText({text:this.render(n),spaces:a}):"")}
8
8
  `}table({tableData:e,tableOptions:n,tableBreakpoints:a}){return(0,C.default)(e.map(r=>r.map(s=>this.render(s))),a?(0,C.breakpoints)(a):n)}flagParameter(e){return e===Boolean?"":e===String?"<string>":e===Number?"<number>":Array.isArray(e)?this.flagParameter(e[0]):"<value>"}flagOperator(){return" "}flagName({flag:e,flagFormatted:n,aliasesEnabled:a,aliasFormatted:r}){let s="";if(r?s+=`${r}, `:a&&(s+=" "),s+=n,"placeholder"in e&&typeof e.placeholder=="string")s+=`${this.flagOperator()}${e.placeholder}`;else{let i=this.flagParameter("type"in e?e.type:e);i&&(s+=`${this.flagOperator()}${i}`)}return s}flagDefault(e){return JSON.stringify(e)}flagDescription({flag:e}){var a;let n="description"in e&&(a=e.description)!=null?a:"";if("default"in e){let{default:r}=e;typeof r=="function"&&(r=r()),r&&(n+=` (default: ${this.flagDefault(r)})`)}return n}render(e){if(typeof e=="string")return e;if(Array.isArray(e))return e.map(n=>this.render(n)).join(`
9
9
  `);if("type"in e&&this[e.type]){let n=this[e.type];if(typeof n=="function")return n.call(this,e.data)}throw new Error(`Invalid node type: ${JSON.stringify(e)}`)}};var h=/^[\w.-]+$/;var{stringify:m}=JSON,le=/[|\\{}()[\]^$+*?.]/;function de(t){let e=[],n,a;for(let r of t){if(a)throw new Error(`Invalid parameter: Spread parameter ${m(a)} must be last`);let s=r[0],i=r[r.length-1],p;if(s==="<"&&i===">"&&(p=!0,n))throw new Error(`Invalid parameter: Required parameter ${m(r)} cannot come after optional parameter ${m(n)}`);if(s==="["&&i==="]"&&(p=!1,n=r),p===void 0)throw new Error(`Invalid parameter: ${m(r)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let o=r.slice(1,-1),u=o.slice(-3)==="...";u&&(a=r,o=o.slice(0,-3));let g=o.match(le);if(g)throw new Error(`Invalid parameter: ${m(r)}. Invalid character found ${m(g[0])}`);e.push({name:o,required:p,spread:u})}return e}function ce(t){return t===void 0||t!==!1}function L(t,e,n,a){let r=c({},e.flags),s=e.version;s&&(r.version={type:Boolean,description:"Show version"});let{help:i}=e,p=ce(i);p&&!("help"in r)&&(r.help={type:Boolean,alias:"h",description:"Show help"});let o=(0,q.default)(r,a),u=()=>{console.log(e.version)};if(s&&o.flags.version===!0)return u(),process.exit(0);let g=new b,U=p&&(i==null?void 0:i.render)?i.render:l=>g.render(l),P=l=>{let x=$(O(c(c({},e),l?{help:l}:{}),{flags:r}));console.log(U(x,g))};if(p&&o.flags.help===!0)return P(),process.exit(0);if(e.parameters){let l=de(e.parameters),x=o._;for(let f=0;f<l.length;f+=1){let{name:N,required:J,spread:w}=l[f],v=w?o._.slice(f):o._[f];if(w&&(f=l.length),J&&(!v||w&&v.length===0))return console.error(`Error: Missing required parameter ${m(N)}
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ var R=Object.defineProperty,j=Object.defineProperties;var K=Object.getOwnPropert
3
3
  `}}function J(t){var n;let e=t.help||{};if("usage"in e)return e.usage?{id:"usage",type:"section",data:{title:"Usage:",body:Array.isArray(e.usage)?e.usage.join(`
4
4
  `):e.usage}}:void 0;if(t.name){let a=[],r=[E(t)];if(t.flags&&Object.keys(t.flags).length>0&&r.push("[flags...]"),t.parameters&&t.parameters.length>0&&r.push(t.parameters.join(" ")),r.length>1&&a.push(r.join(" ")),"commands"in t&&((n=t.commands)==null?void 0:n.length)&&a.push(`${t.name} <command>`),a.length>0)return{id:"usage",type:"section",data:{title:"Usage:",body:a.join(`
5
5
  `)}}}}function M(t){var a;if(!("commands"in t)||!((a=t.commands)==null?void 0:a.length))return;let e=t.commands.map(r=>[r.options.name,r.options.help?r.options.help.description:""]);return{id:"commands",type:"section",data:{title:"Commands:",body:{type:"table",data:{tableData:e,tableOptions:[{width:"content-width",paddingLeft:2,paddingRight:8}]}},indentBody:0}}}function W(t){if(!(!t.flags||Object.keys(t.flags).length===0))return{id:"flags",type:"section",data:{title:"Flags:",body:D(t.flags),indentBody:0}}}function Z(t){let{help:e}=t;if(!e||!e.examples||e.examples.length===0)return;let{examples:n}=e;if(Array.isArray(n)&&(n=n.join(`
6
- `)),n)return{id:"examples",type:"section",data:{title:"Examples:",body:n}}}function z(t){if(!("alias"in t)||!t.alias)return;let{alias:e}=t,n=Array.isArray(e)?e.join(", "):e;return{id:"aliases",type:"section",data:{title:"Aliases:",body:n}}}var v=t=>[_,U,J,M,W,Z,z].map(e=>e(t)).filter(e=>Boolean(e));import G from"tty";import Q,{breakpoints as X}from"terminal-columns";var Y=G.WriteStream.prototype.hasColors(),C=class{text(e){return e}bold(e){return`${e}`}indentText({text:e,spaces:n}){return e.replace(/^/gm," ".repeat(n))}heading(e){return Y?this.bold(e):e.toLocaleUpperCase()}section({title:e,body:n,indentBody:a=2}){return`${(e?`${this.heading(e)}
6
+ `)),n)return{id:"examples",type:"section",data:{title:"Examples:",body:n}}}function z(t){if(!("alias"in t)||!t.alias)return;let{alias:e}=t,n=Array.isArray(e)?e.join(", "):e;return{id:"aliases",type:"section",data:{title:"Aliases:",body:n}}}var v=t=>[_,U,J,M,W,Z,z].map(e=>e(t)).filter(e=>Boolean(e));import G from"tty";import Q,{breakpoints as X}from"terminal-columns";var Y=G.WriteStream.prototype.hasColors(),C=class{text(e){return e}bold(e){return Y?`${e}`:e.toLocaleUpperCase()}indentText({text:e,spaces:n}){return e.replace(/^/gm," ".repeat(n))}heading(e){return this.bold(e)}section({title:e,body:n,indentBody:a=2}){return`${(e?`${this.heading(e)}
7
7
  `:"")+(n?this.indentText({text:this.render(n),spaces:a}):"")}
8
8
  `}table({tableData:e,tableOptions:n,tableBreakpoints:a}){return Q(e.map(r=>r.map(s=>this.render(s))),a?X(a):n)}flagParameter(e){return e===Boolean?"":e===String?"<string>":e===Number?"<number>":Array.isArray(e)?this.flagParameter(e[0]):"<value>"}flagOperator(){return" "}flagName({flag:e,flagFormatted:n,aliasesEnabled:a,aliasFormatted:r}){let s="";if(r?s+=`${r}, `:a&&(s+=" "),s+=n,"placeholder"in e&&typeof e.placeholder=="string")s+=`${this.flagOperator()}${e.placeholder}`;else{let i=this.flagParameter("type"in e?e.type:e);i&&(s+=`${this.flagOperator()}${i}`)}return s}flagDefault(e){return JSON.stringify(e)}flagDescription({flag:e}){var a;let n="description"in e&&(a=e.description)!=null?a:"";if("default"in e){let{default:r}=e;typeof r=="function"&&(r=r()),r&&(n+=` (default: ${this.flagDefault(r)})`)}return n}render(e){if(typeof e=="string")return e;if(Array.isArray(e))return e.map(n=>this.render(n)).join(`
9
9
  `);if("type"in e&&this[e.type]){let n=this[e.type];if(typeof n=="function")return n.call(this,e.data)}throw new Error(`Invalid node type: ${JSON.stringify(e)}`)}};var h=/^[\w.-]+$/;var{stringify:m}=JSON,te=/[|\\{}()[\]^$+*?.]/;function ne(t){let e=[],n,a;for(let r of t){if(a)throw new Error(`Invalid parameter: Spread parameter ${m(a)} must be last`);let s=r[0],i=r[r.length-1],p;if(s==="<"&&i===">"&&(p=!0,n))throw new Error(`Invalid parameter: Required parameter ${m(r)} cannot come after optional parameter ${m(n)}`);if(s==="["&&i==="]"&&(p=!1,n=r),p===void 0)throw new Error(`Invalid parameter: ${m(r)}. Must be wrapped in <> (required parameter) or [] (optional parameter)`);let o=r.slice(1,-1),g=o.slice(-3)==="...";g&&(a=r,o=o.slice(0,-3));let y=o.match(te);if(y)throw new Error(`Invalid parameter: ${m(r)}. Invalid character found ${m(y[0])}`);e.push({name:o,required:p,spread:g})}return e}function re(t){return t===void 0||t!==!1}function S(t,e,n,a){let r=f({},e.flags),s=e.version;s&&(r.version={type:Boolean,description:"Show version"});let{help:i}=e,p=re(i);p&&!("help"in r)&&(r.help={type:Boolean,alias:"h",description:"Show help"});let o=ee(r,a),g=()=>{console.log(e.version)};if(s&&o.flags.version===!0)return g(),process.exit(0);let y=new C,B=p&&(i==null?void 0:i.render)?i.render:l=>y.render(l),b=l=>{let P=v(O(f(f({},e),l?{help:l}:{}),{flags:r}));console.log(B(P,y))};if(p&&o.flags.help===!0)return b(),process.exit(0);if(e.parameters){let l=ne(e.parameters),P=o._;for(let u=0;u<l.length;u+=1){let{name:$,required:I,spread:x}=l[u],w=x?o._.slice(u):o._[u];if(x&&(u=l.length),I&&(!w||x&&w.length===0))return console.error(`Error: Missing required parameter ${m($)}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cleye",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "The intuitive CLI development tool",
5
5
  "keywords": [
6
6
  "cli",
@@ -34,7 +34,8 @@
34
34
  "scripts": {
35
35
  "build": "tsup src/index.ts --dts --format esm,cjs --minify",
36
36
  "lint": "eslint .",
37
- "test": "CI=true jest"
37
+ "test": "CI=true jest",
38
+ "test:dts": "tsd"
38
39
  },
39
40
  "husky": {
40
41
  "hooks": {
@@ -47,8 +48,8 @@
47
48
  ]
48
49
  },
49
50
  "dependencies": {
50
- "terminal-columns": "^1.4.0",
51
- "type-flag": "^2.0.0"
51
+ "terminal-columns": "^1.4.1",
52
+ "type-flag": "^2.0.1"
52
53
  },
53
54
  "devDependencies": {
54
55
  "@pvtnbr/eslint-config": "^0.11.0",
@@ -61,6 +62,7 @@
61
62
  "husky": "^4.3.8",
62
63
  "jest": "^27.4.7",
63
64
  "lint-staged": "^12.1.2",
65
+ "tsd": "^0.19.1",
64
66
  "tsup": "^5.11.10",
65
67
  "typescript": "^4.5.4"
66
68
  },
@@ -69,5 +71,8 @@
69
71
  "rules": {
70
72
  "unicorn/no-process-exit": "off"
71
73
  }
74
+ },
75
+ "tsd": {
76
+ "directory": "tests"
72
77
  }
73
78
  }