UNPKG

@phala/phala-cli

Version:
2 lines 10.2 kB
var B=Object.defineProperty;var I=(e,r,c)=>r in e?B(e,r,{enumerable:!0,configurable:!0,writable:!0,value:c}):e[r]=c;var N=(e,r,c)=>(I(e,typeof r!="symbol"?r+"":r,c),c);import y from"chalk";function A(e,r){if(!e)return[""];if(e.length<=r)return[e];let c=[],a="",m=e.split(/(\s+)/).filter(u=>u.trim().length>0);for(let u of m){if(u.length>r){a&&(c.push(a),a="");for(let l=0;l<u.length;l+=r)c.push(u.slice(l,l+r));continue}a.length+u.length+1>r?(c.push(a),a=u):a=a?`${a} ${u}`:u}return a&&c.push(a),c}var _={error:(e,...r)=>{console.error(y.red("\u2717"),y.red(e),...r)},warn:(e,...r)=>{console.log(y.yellow("\u26A0"),y.yellow(e),...r)},info:(e,...r)=>{console.log(y.blue("\u2139"),y.blue(e),...r)},success:(e,...r)=>{console.log(y.green("\u2713"),y.green(e),...r)},debug:(e,...r)=>{process.env.DEBUG&&console.log(y.gray("\u{1F50D}"),y.gray(e),...r)},table:(e,r)=>{if(e.length===0){console.log(y.yellow("No data to display"));return}if(r)if(typeof r[0]=="string"){let c=r.map(a=>({key:a,header:a.charAt(0).toUpperCase()+a.slice(1)}));E(e,{columns:c,borderStyle:"rounded",headerStyle:a=>y.cyan.bold(a)})}else E(e,{columns:r,borderStyle:"rounded",headerStyle:c=>y.cyan.bold(c)});else E(e,{borderStyle:"rounded",headerStyle:c=>y.cyan.bold(c)})},keyValueTable:(e,r)=>{let a={...{keyHeader:"Property",valueHeader:"Value",borderStyle:"rounded",enableTextWrapping:!0,maxDepth:2,formatKeys:!0,keyFormatter:f=>{let T=["URL","ID","API","UI","URI","CPU","GPU","RAM","JSON","XML","HTML","HTTP","HTTPS","SSH","FTP","IP","TCP","UDP","DNS","SSL","TLS","SQL","VCPU","CVM","TEE","IO"],W={teepod:"TEEPod",dstack:"Dstack"},w;f.includes("_")?w=f.split("_").map($=>$.charAt(0).toUpperCase()+$.slice(1).toLowerCase()).join(" "):f.includes("-")?w=f.split("-").map($=>$.charAt(0).toUpperCase()+$.slice(1).toLowerCase()).join(" "):w=f.charAt(0).toUpperCase()+f.slice(1).replace(/([a-z])([A-Z])/g,"$1 $2");for(let $ of T){let L=new RegExp(`\\b${$.toLowerCase()}\\b`,"gi");w=w.replace(L,$)}for(let[$,L]of Object.entries(W)){let j=new RegExp(`\\b${$}\\b`,"gi");w=w.replace(j,L)}return w},valueFormatter:f=>String(f??"")},...r},{include:m,exclude:u,keyFormatter:l,valueFormatter:S,formatKeys:x,keyHeader:b,valueHeader:v,keyWidth:C,valueWidth:o,borderStyle:n,enableTextWrapping:i,maxDepth:s}=a,d=Object.keys(e);if(m&&(d=d.filter(f=>m.includes(f))),u&&(d=d.filter(f=>!u.includes(f))),d.length===0){console.log(y.yellow("No properties to display"));return}let t=d.map(f=>{let T=e[f],W;return T==null?W="":typeof T=="object"&&!Array.isArray(T)?W=z(T,0,s):Array.isArray(T)?T.length===0?W="[]":typeof T[0]=="object"?W=`[${T.length} items]`:W=`[${T.join(", ")}]`:W=String(T),S&&(W=S(T,f)),{key:x&&l?l(f):f,value:W}}),g=H(),p=C,k=o;p||(p=Math.max(b.length,...t.map(f=>f.key.length),10),p=Math.min(p,Math.floor(g/3))),k||(k=g-p-7);let h=D(n),R=`${h.topLeft}${h.horizontal.repeat(p+2)}${h.topT}${h.horizontal.repeat(k+2)}${h.topRight}`,U=`${h.vertical} ${y.bold(b.padEnd(p))} ${h.vertical} ${y.bold(v.padEnd(k))} ${h.vertical}`,O=`${h.leftT}${h.horizontal.repeat(p+2)}${h.cross}${h.horizontal.repeat(k+2)}${h.rightT}`;console.log(R),console.log(U),console.log(O),t.forEach((f,T)=>{let W=i?A(f.key,p):[f.key],w=i?A(f.value,k):[f.value],$=Math.max(W.length,w.length);for(let L=0;L<$;L++){let j=(W[L]||"").padEnd(p),P=(w[L]||"").padEnd(k);console.log(`${h.vertical} ${j} ${h.vertical} ${P} ${h.vertical}`)}T<t.length-1&&console.log(`${h.leftT}${h.horizontal.repeat(p+2)}${h.cross}${h.horizontal.repeat(k+2)}${h.rightT}`)});let V=`${h.bottomLeft}${h.horizontal.repeat(p+2)}${h.bottomT}${h.horizontal.repeat(k+2)}${h.bottomRight}`;console.log(V)},startSpinner:e=>(process.stdout.write(`${y.blue("\u27F3")} ${e}... `),{stop:(r=!0,c)=>{let a=r?y.green("\u2713"):y.red("\u2717"),m=c?`: ${c}`:"";console.log(`${a}${m}`)}}),break(){console.log("")}};function z(e,r,c){if(r>=c)return"[Nested Object]";if(e==null)return"";if(Array.isArray(e))return e.length===0?"[]":`[${e.length} items]`;let a=[];for(let[m,u]of Object.entries(e))u==null?a.push(`${m}: `):typeof u=="object"?a.push(`${m}: ${z(u,r+1,c)}`):a.push(`${m}: ${u}`);return a.join(", ")}function D(e="single"){return{single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524",topT:"\u252C",bottomT:"\u2534",cross:"\u253C"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551",leftT:"\u2560",rightT:"\u2563",topT:"\u2566",bottomT:"\u2569",cross:"\u256C"},rounded:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524",topT:"\u252C",bottomT:"\u2534",cross:"\u253C"}}[e]}function H(){return process.stdout.columns||80}function M(e,r,c={}){let a=H(),m=c.borderChars??3,l=(c.additionalBorderWidth??1)+r.length*m,S=a-l,x={},b=0,v=0;for(let n of r){let i=n.key;if(n.fixedWidth!==void 0){x[i]=n.fixedWidth,b+=n.fixedWidth;continue}let s=n.minWidth??n.header.length,d;n.getWidth?d=Math.max(s,n.header.length,...e.map(t=>n.getWidth(t))):n.getValue?d=Math.max(s,n.header.length,...e.map(t=>String(n.getValue(t)||"").length)):d=Math.max(s,n.header.length,...e.map(t=>String(t[n.key]||"").length)),x[i]=d,b+=d,v+=n.weight??1}let C=Math.max(0,S-b);if(C>0&&v>0)for(let n of r){let i=n.key;if(n.fixedWidth===void 0&&n.weight){let s=Math.floor(C*(n.weight/v));x[i]+=s}}let o=Object.values(x).reduce((n,i)=>n+i,0)+l;if(o>a){let n=S/(o-l),i={};for(let s of r){let d=s.key,t=s.minWidth??s.header.length;i[d]=Math.max(t,Math.floor(x[d]*n))}return i}return x}function G(e){return M(e,[{key:"name",header:"Name",minWidth:10},{key:"status",header:"Status",minWidth:6},{key:"appId",header:"App ID",minWidth:8,weight:1},{key:"appUrl",header:"App URL",minWidth:7,weight:2}],{borderChars:3,additionalBorderWidth:1})}function Z(e,r){let c=r.map((u,l)=>({key:`col_${l}`,header:u.header,minWidth:u.minWidth,weight:u.weight,getValue:u.accessor})),a=M(e,c,{borderChars:3,additionalBorderWidth:1}),m={};return r.forEach((u,l)=>{m[u.key]=a[`col_${l}`]}),m}function E(e,r={}){if(r.keyValueMode&&e.length===1){let o=e[0],n=[];r.columns||(r.columns=Object.keys(o).map(i=>({key:i,header:i.charAt(0).toUpperCase()+i.slice(1).replace(/([A-Z])/g," $1")})));for(let i of r.columns){let s=String(i.key),d;if(i.accessor)d=i.accessor(o);else if(typeof i.key=="string"&&i.key.includes(".")){let t=i.key.split("."),g=o;for(let p of t){if(g==null){d="";break}g=g[p]}d=g}else d=o[i.key];i.formatter&&(d=i.formatter(d)),n.push({key:i.header||s,value:d})}e=n,r.columns=[{key:"key",header:"Property",minWidth:15},{key:"value",header:"Value",minWidth:20}]}if(e.length===0){console.log(y.yellow("No data to display"));return}let a={...{includeHeaders:!0,border:!0,borderStyle:"single",headerStyle:o=>y.bold(o),cellStyle:o=>o,enableTextWrapping:!0},...r},m=a.columns;if(m)m=m.map(o=>({...o,enableTextWrapping:o.enableTextWrapping!==void 0?o.enableTextWrapping:a.enableTextWrapping}));else{let o=e[0];m=Object.keys(o).map(n=>({key:n,header:n.charAt(0).toUpperCase()+n.slice(1),enableTextWrapping:a.enableTextWrapping}))}let l={single:{topLeft:"\u250C",topRight:"\u2510",bottomLeft:"\u2514",bottomRight:"\u2518",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524",topT:"\u252C",bottomT:"\u2534",cross:"\u253C"},double:{topLeft:"\u2554",topRight:"\u2557",bottomLeft:"\u255A",bottomRight:"\u255D",horizontal:"\u2550",vertical:"\u2551",leftT:"\u2560",rightT:"\u2563",topT:"\u2566",bottomT:"\u2569",cross:"\u256C"},rounded:{topLeft:"\u256D",topRight:"\u256E",bottomLeft:"\u2570",bottomRight:"\u256F",horizontal:"\u2500",vertical:"\u2502",leftT:"\u251C",rightT:"\u2524",topT:"\u252C",bottomT:"\u2534",cross:"\u253C"}}[a.borderStyle],S=m.map(o=>({key:o.key,header:o.header||String(o.key),minWidth:o.minWidth||3,weight:o.weight,enableTextWrapping:o.enableTextWrapping,getValue:o.accessor?n=>o.accessor(n):n=>{if(typeof o.key=="string"&&o.key.includes(".")){let i=o.key.split("."),s=n;for(let d of i){if(s==null)return"";s=s[d]}return s??""}return n[o.key]??""}})),x=M(e,S),b=m.map((o,n)=>({...o,width:x[S[n].key]})),v=b.map(o=>o.header||String(o.key)),C=(o,n)=>{let i=b.map(t=>{let g;if(t.accessor)g=t.accessor(o);else if(typeof t.key=="string"&&t.key.includes(".")){let k=t.key.split("."),h=o;for(let R of k){if(h==null){g="";break}h=h[R]}g=h??""}else g=o[t.key]??"";let p=t.formatter?t.formatter(g):String(g||"");return t.enableTextWrapping?{lines:A(p,t.width),key:String(t.key)}:{lines:[p.length>t.width?p.substring(0,t.width-1)+"\u2026":p],key:String(t.key)}}),s=Math.max(...i.map(t=>t.lines.length)),d=[];for(let t=0;t<s;t++){let g=i.map((p,k)=>{let h=p.lines[t]||"";return a.cellStyle(h.padEnd(b[k].width),n,p.key)});d.push(g)}return d};if(a.border){let o=l.topLeft+b.map(i=>l.horizontal.repeat(i.width+2)).join(l.topT)+l.topRight;if(console.log(o),a.includeHeaders){let i=b.map((t,g)=>({lines:t.enableTextWrapping?A(v[g],t.width):[v[g]],width:t.width})),s=Math.max(...i.map(t=>t.lines.length));for(let t=0;t<s;t++){let g=l.vertical+i.map(p=>{let k=p.lines[t]||"";return" "+a.headerStyle(k.padEnd(p.width))+" "}).join(l.vertical)+l.vertical;console.log(g)}let d=l.leftT+b.map(t=>l.horizontal.repeat(t.width+2)).join(l.cross)+l.rightT;console.log(d)}e.forEach((i,s)=>{let d=C(i,s);if(d.forEach(t=>{console.log(l.vertical+t.map(g=>` ${g} `).join(l.vertical)+l.vertical)}),s<e.length-1&&d.length>1){let t=l.leftT+b.map(g=>l.horizontal.repeat(g.width+2)).join(l.cross)+l.rightT;console.log(t)}});let n=l.bottomLeft+b.map(i=>l.horizontal.repeat(i.width+2)).join(l.bottomT)+l.bottomRight;console.log(n)}else{if(a.includeHeaders){let o=b.map((s,d)=>({lines:s.enableTextWrapping?A(v[d],s.width):[v[d]],width:s.width})),n=Math.max(...o.map(s=>s.lines.length));for(let s=0;s<n;s++){let d=o.map(t=>{let g=t.lines[s]||"";return a.headerStyle(g.padEnd(t.width))}).join(" ");console.log(d)}let i=b.map(s=>"\u2500".repeat(s.width)).join(" ");console.log(i)}e.forEach((o,n)=>{let i=C(o,n);i.forEach(s=>{console.log(s.join(" "))}),n<e.length-1&&i.length>1&&console.log("")})}console.log(`Total: ${e.length} rows`)}export{N as a,_ as b,M as c,G as d,Z as e,E as f}; //# sourceMappingURL=chunk-A4IAJHG6.js.map