@visulima/vis 1.0.0-alpha.44 → 1.0.0-alpha.45

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.
Files changed (105) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/bin.js +1 -1
  3. package/dist/binx.js +1 -1
  4. package/dist/packem_chunks/bloom-status.js +1 -1
  5. package/dist/packem_chunks/bloom-sync.js +1 -1
  6. package/dist/packem_chunks/catalog.js +63 -62
  7. package/dist/packem_chunks/cli-exec.js +1 -1
  8. package/dist/packem_chunks/cli-main.js +172 -973
  9. package/dist/packem_chunks/detect.js +1 -1
  10. package/dist/packem_chunks/fix.js +1 -1
  11. package/dist/packem_chunks/handler.js +1 -1
  12. package/dist/packem_chunks/handler10.js +1 -1
  13. package/dist/packem_chunks/handler11.js +1 -1
  14. package/dist/packem_chunks/handler12.js +2 -2
  15. package/dist/packem_chunks/handler13.js +1 -1
  16. package/dist/packem_chunks/handler14.js +1 -1
  17. package/dist/packem_chunks/handler15.js +1 -1
  18. package/dist/packem_chunks/handler16.js +1 -1
  19. package/dist/packem_chunks/handler17.js +1 -1
  20. package/dist/packem_chunks/handler18.js +1 -1
  21. package/dist/packem_chunks/handler19.js +1 -1
  22. package/dist/packem_chunks/handler21.js +1 -1
  23. package/dist/packem_chunks/handler24.js +1 -1
  24. package/dist/packem_chunks/handler27.js +1 -1
  25. package/dist/packem_chunks/handler28.js +1 -1
  26. package/dist/packem_chunks/handler29.js +1 -1
  27. package/dist/packem_chunks/handler3.js +1 -1
  28. package/dist/packem_chunks/handler30.js +1 -1
  29. package/dist/packem_chunks/handler4.js +1 -1
  30. package/dist/packem_chunks/handler5.js +3 -3
  31. package/dist/packem_chunks/handler50.js +4 -4
  32. package/dist/packem_chunks/handler51.js +3 -3
  33. package/dist/packem_chunks/handler57.js +4 -4
  34. package/dist/packem_chunks/handler58.js +1 -1
  35. package/dist/packem_chunks/handler59.js +1 -1
  36. package/dist/packem_chunks/handler6.js +6 -6
  37. package/dist/packem_chunks/handler60.js +1 -1
  38. package/dist/packem_chunks/handler61.js +1 -1
  39. package/dist/packem_chunks/handler62.js +2 -2
  40. package/dist/packem_chunks/handler63.js +4 -4
  41. package/dist/packem_chunks/handler65.js +2 -2
  42. package/dist/packem_chunks/handler66.js +13 -13
  43. package/dist/packem_chunks/handler67.js +5 -5
  44. package/dist/packem_chunks/handler68.js +16 -16
  45. package/dist/packem_chunks/handler69.js +5 -5
  46. package/dist/packem_chunks/handler7.js +1 -1
  47. package/dist/packem_chunks/handler71.js +1 -1
  48. package/dist/packem_chunks/handler72.js +2 -2
  49. package/dist/packem_chunks/handler73.js +13 -13
  50. package/dist/packem_chunks/handler74.js +3 -3
  51. package/dist/packem_chunks/handler75.js +3 -3
  52. package/dist/packem_chunks/handler76.js +5 -5
  53. package/dist/packem_chunks/handler9.js +1 -1
  54. package/dist/packem_chunks/heal-accept.js +1 -1
  55. package/dist/packem_chunks/heal.js +1 -1
  56. package/dist/packem_chunks/help-command.js +1 -1
  57. package/dist/packem_chunks/index2.js +802 -7
  58. package/dist/packem_chunks/index3.js +7 -135
  59. package/dist/packem_chunks/index4.js +134 -73
  60. package/dist/packem_chunks/index5.js +74 -0
  61. package/dist/packem_chunks/keys-refresh.js +1 -1
  62. package/dist/packem_chunks/lean.js +1 -1
  63. package/dist/packem_chunks/list.js +1 -1
  64. package/dist/packem_chunks/loader.js +1 -1
  65. package/dist/packem_chunks/print-config.js +1 -1
  66. package/dist/packem_chunks/registry.js +2 -2
  67. package/dist/packem_chunks/shell-runner.js +1 -1
  68. package/dist/packem_chunks/sync.js +1 -1
  69. package/dist/packem_chunks/sync2.js +1 -1
  70. package/dist/packem_chunks/tripwire.js +2 -2
  71. package/dist/packem_chunks/ts-loader.js +1 -1
  72. package/dist/packem_chunks/verify-lockfile.js +1 -1
  73. package/dist/packem_chunks/version-resolver.js +2 -2
  74. package/dist/packem_shared/{Table-CcVkyULl-DLWu6XHL.js → Table-BGIHvenQ-D2oJtNQj.js} +1 -1
  75. package/dist/packem_shared/affected-shas-CCxG4tvm.js +1 -0
  76. package/dist/packem_shared/{ai-analysis-CO6S0afy.js → ai-analysis-rC48NLfB.js} +4 -4
  77. package/dist/packem_shared/{ai-fix-CI0Vvqld.js → ai-fix-D_ijV3Rn.js} +3 -3
  78. package/dist/packem_shared/bin-CPMo34SM.js +1 -0
  79. package/dist/packem_shared/{command-runtime-BE-vKsGH.js → command-runtime-3FTGuUsK.js} +1 -1
  80. package/dist/packem_shared/{env-C2ZCnfP_.js → env-Ct3hMEYB.js} +1 -1
  81. package/dist/packem_shared/{failure-log-jFfZRJK9.js → failure-log-Dy2G-rKi.js} +1 -1
  82. package/dist/packem_shared/{index-CQjzW7m8.js → index-Cntyu-w8.js} +1 -1
  83. package/dist/packem_shared/{index-D7EZ612R.js → index-XAb0QGqA.js} +1 -1
  84. package/dist/packem_shared/{lifecycle-Dyb47wbD.js → lifecycle-CHcFuWf_.js} +1 -1
  85. package/dist/packem_shared/{osv-bloom-BsQ-aFiM.js → osv-bloom-DVMlkcAO.js} +2 -2
  86. package/dist/packem_shared/{packument-DquNPIq9.js → packument-C-A3Uhhx.js} +1 -1
  87. package/dist/packem_shared/pm-runner-CQcraCcu.js +1 -0
  88. package/dist/packem_shared/{provenance-DIq8KyBV.js → provenance-R2csDSNg.js} +1 -1
  89. package/dist/packem_shared/{registry-keys-C8K11ets.js → registry-keys-CMnS_Qt_.js} +1 -1
  90. package/dist/packem_shared/{resolve-explicit-Dr4kIybR.js → resolve-explicit-C4oQMyoB.js} +1 -1
  91. package/dist/packem_shared/resolve-runtime-QRaQucfL.js +1 -0
  92. package/dist/packem_shared/{s1ngularity-CtMmtXJo.js → s1ngularity-BCDt28u0.js} +1 -1
  93. package/dist/packem_shared/scan-progress-YRpDs90j.js +2 -0
  94. package/dist/packem_shared/{signatures-CE8OAK-i.js → signatures-B3srzCEv.js} +1 -1
  95. package/dist/packem_shared/use-measured-height-DHi0xOPO.js +1 -0
  96. package/dist/packem_shared/{vis-update-app-Cpme_3Du.js → vis-update-app-B3I14Vfy.js} +1 -1
  97. package/index.js +52 -52
  98. package/package.json +11 -11
  99. package/dist/packem_shared/affected-shas-CwRY5aoc.js +0 -1
  100. package/dist/packem_shared/bin-P6Q5tKrP.js +0 -1
  101. package/dist/packem_shared/pm-runner-D4jM58Oz.js +0 -1
  102. package/dist/packem_shared/resolve-runtime-Tx0bvg0h.js +0 -1
  103. package/dist/packem_shared/scan-progress-D4yywI6P.js +0 -2
  104. package/dist/packem_shared/use-measured-height-XK9YSwtv.js +0 -1
  105. package/dist/packem_shared/window-ops-DDePlWLV.js +0 -2
@@ -1,7 +1,802 @@
1
- import{y as U,m as I,I as K,v as b}from"../packem_shared/index-CE6MsgcV.js";import{E as Q}from"../packem_shared/public-api-WqUCiyIe.js";import{u as X}from"./ts-loader.js";import{p as Z}from"./cli-main.js";import{k as N,j as A,l as x}from"../packem_shared/env-C2ZCnfP_.js";const ee=(e,t)=>typeof e!="string"||e===""?"":e[0].toLowerCase()+e.slice(1),k=(e,t)=>typeof e!="string"||e===""?"":(t?.locale?e[0].toLocaleUpperCase(t.locale):e[0].toUpperCase())+e.slice(1),te=(e,t)=>`${e}::${t?.joiner??""}::${t?.locale??""}::${t?.knownAcronyms?.join(",")??""}::${t?.normalize?"true":"false"}`,$=(e,t)=>{const{length:r}=e;if(r===0)return"";if(r===1)return e[0];const n=[];let i="",o="";for(let s=0;s<r;s++){const l=e[s];if(N.test(l)){i?(n.push(i+o+l),i="",o=""):(n.length>0&&n.push(t),i=l);continue}i?(o&&(o+=t),o+=l):(n.length>0&&n.push(t),n.push(l))}return n.join("")},ne=/(?<![a-zß])SS(?![a-z])/g,re=e=>e.replaceAll(ne,"ß"),ie=(e,t)=>{if(typeof e!="string"||!e)return"";let r=!0;return $(A(e,{handleAnsi:t?.handleAnsi,handleEmoji:t?.handleEmoji,knownAcronyms:t?.knownAcronyms,locale:t?.locale,normalize:t?.normalize,separators:void 0,stripAnsi:t?.stripAnsi,stripEmoji:t?.stripEmoji}).map(i=>{const o=i,s=o.toLowerCase();return r?(r=!1,ee(s)):k(s,t)}),"")},oe=new x(1e3),S=(e,t)=>{if(typeof e!="string")return"";const r=t?.cache??!1,n=t?.cacheStore??oe;let i;if(r&&(i=te(e,t)),r&&i&&n.has(i))return n.get(i);const o=A(e,{handleAnsi:t?.handleAnsi,handleEmoji:t?.handleEmoji,knownAcronyms:t?.knownAcronyms,locale:t?.locale,normalize:t?.normalize,separators:void 0,stripAnsi:t?.stripAnsi,stripEmoji:t?.stripEmoji}).map(l=>{if(t?.handleAnsi&&N.test(l))return l;if(t?.toUpperCase)return t.locale?l.toLocaleUpperCase(t.locale):l.toUpperCase();const a=t?.locale?.startsWith("de")?re(l):l;return t?.locale?a.toLocaleLowerCase(t.locale):a.toLowerCase()}),s=$(o,t?.joiner??"-");return r&&i&&n.set(i,s),s},se=new x(1e3),le=(e,t)=>S(e,{cacheStore:se,...t,joiner:"_",toUpperCase:!0}),ae=(e,t)=>typeof e!="string"||!e?"":$(A(e,{handleAnsi:t?.handleAnsi,handleEmoji:t?.handleEmoji,knownAcronyms:t?.knownAcronyms,locale:t?.locale,normalize:t?.normalize,separators:void 0,stripAnsi:t?.stripAnsi,stripEmoji:t?.stripEmoji}).map(n=>k(n.toLowerCase(),{locale:t?.locale})),""),ce=new x(1e3),fe=(e,t)=>S(e,{cacheStore:ce,...t,joiner:"_"}),ue=(e,t)=>typeof e!="string"?"":$(A(e,{handleAnsi:t?.handleAnsi,handleEmoji:t?.handleEmoji,knownAcronyms:t?.knownAcronyms,locale:t?.locale,normalize:t?.normalize,separators:void 0,stripAnsi:t?.stripAnsi,stripEmoji:t?.stripEmoji}).map(n=>k(n,{locale:t?.locale})),"-"),m=e=>e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):JSON.stringify(e),T={camel_case:e=>ie(m(e)),kebab_case:e=>S(m(e)),lower_case:e=>m(e).toLowerCase(),pascal_case:e=>ae(m(e)),path_join:(e,...t)=>{const r=[m(e),...t.map(n=>m(n))];return I(...r)},path_relative:(e,t)=>U(m(t),m(e)),snake_case:e=>fe(m(e)),upper_case:e=>m(e).toUpperCase(),upper_kebab_case:e=>ue(m(e)),upper_snake_case:e=>le(m(e))},z=(e,t,r=[])=>{const n=T[e];if(!n)throw new Error(`Unknown filter "${e}". Known filters: ${Object.keys(T).sort().join(", ")}.`);return n(t,...r)},R=e=>{const t=[];let r=0,n=0,i,o=-1;for(const s of e){if(o+=1,i){s===i&&(i=void 0);continue}if(s==='"'||s==="'"){i=s;continue}s==="("?r+=1:s===")"?r-=1:s===","&&r===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t},pe=e=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1)},me=/\[([^\]]+)\]/g,de=e=>{const t=e.trim(),r=t.indexOf("(");if(r===-1)return{args:[],name:t};if(!t.endsWith(")"))throw new Error(`Filter call "${e}" missing closing ")"`);const n=t.slice(0,r).trim(),i=t.slice(r+1,-1).trim();return i===""?{args:[],name:n}:{args:R(i).map(o=>{const s=o.trim();return pe(s)??s}),name:n}},he=e=>{const t=e.split("|").map(n=>n.trim()),r=t[0]??"";if(!r)throw new Error(`Empty variable name in expression "${e}"`);return{filters:t.slice(1).map(n=>de(n)),name:r}},ye=e=>e==null?"":typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):JSON.stringify(e),ge=(e,t)=>{const r=e.replaceAll(me,(n,i)=>{const{filters:o,name:s}=he(i);if(!Object.hasOwn(t,s))throw new Error(`Variable "${s}" used in filename "${e}" but not defined`);let l=t[s];for(const a of o)l=z(a.name,l,a.args);return ye(l)});return P(r)},P=e=>e.split("/").map(t=>t.endsWith(".tera")||t.endsWith(".twig")?t.slice(0,-5):t).join("/"),we=e=>e.endsWith(".raw")?e.slice(0,-4):e,be=e=>{const t=e.split("/");return(t.at(-1)??"").startsWith("_")?!0:t.slice(0,-1).includes("partials")},Ee=(e,t)=>{if(!e.startsWith(`---
2
- `)&&!e.startsWith(`---\r
3
- `))return{body:e};const r=e.indexOf(`
4
- ---`,3);if(r===-1)return{body:e};let n=r+1+3;e[n]==="\r"&&(n+=1),e[n]===`
5
- `&&(n+=1);const i=e.startsWith(`---\r
6
- `)?5:4,o=e.slice(i,r).replaceAll("\r","");let s;try{s=t(o)}catch(l){const a=l instanceof Error?l.message:String(l);throw new Error(`Failed to parse frontmatter YAML: ${a}`,{cause:l})}if(s==null)return{body:e.slice(n)};if(typeof s!="object"||Array.isArray(s))throw new TypeError(`Frontmatter must be a YAML mapping, got ${Array.isArray(s)?"array":typeof s}`);return{body:e.slice(n),frontmatter:s}},ve=/\{\{-?(.+?)-?\}\}|\{%-?(.+?)-?%\}/gs,q=e=>{const t=[];let r=0,n=1;const i=o=>{for(const s of o)s===`
7
- `&&(n+=1)};for(const o of e.matchAll(ve)){const s=o.index??0;if(s>r){const c=e.slice(r,s);t.push({line:n,type:"text",value:c}),i(c)}const l=n,a=o[0];a.startsWith("{{")?t.push({line:l,type:"expr",value:(o[1]??"").trim()}):t.push({line:l,type:"stmt",value:(o[2]??"").trim()}),i(a),r=s+a.length}if(r<e.length){const o=e.slice(r);t.push({line:n,type:"text",value:o})}return t},Ae=new Set(["block","endblock","endfilter","endmacro","extends","filter","import","macro","set"]),F=(e,t)=>{let r=0;const n=(o,s)=>{throw new Error(`${t}:${o}: ${s}`)},i=o=>{const s=[];for(;r<e.length;){const l=e[r];if(l.type==="text"){s.push({type:"text",value:l.value}),r+=1;continue}if(l.type==="expr"){s.push({expression:l.value,line:l.line,type:"expr"}),r+=1;continue}const a=l.value.split(/\s+/)[0]??"";if(o.includes(a))return s;if(Ae.has(a)&&n(l.line,`Tera feature "{% ${a} %}" is not supported. Supported: if/else/endif, for/endfor, include. Rewrite the template to avoid macros, set, extends, block, and import.`),a==="if"){r+=1;const c=l.value.slice(2).trim(),p=i(["else","endif"]);let f;r<e.length&&e[r].type==="stmt"&&e[r].value.split(/\s+/)[0]==="else"&&(r+=1,f=i(["endif"])),(r>=e.length||e[r].type!=="stmt"||e[r].value.split(/\s+/)[0]!=="endif")&&n(l.line,"Unterminated {% if %} — missing {% endif %}"),r+=1,s.push({alternate:f,condition:c,consequent:p,line:l.line,type:"if"});continue}if(a==="for"){r+=1;const c=l.value.slice(3).trim(),p=c.indexOf(" in ");p===-1&&n(l.line,"Malformed {% for %} — expected `for <name> in <collection>`");const f=c.slice(0,p).trim(),d=c.slice(p+4).trim();(!f||!d)&&n(l.line,"Malformed {% for %} — missing binding or collection");const u=i(["endfor"]);(r>=e.length||e[r].type!=="stmt"||e[r].value.split(/\s+/)[0]!=="endfor")&&n(l.line,"Unterminated {% for %} — missing {% endfor %}"),r+=1,s.push({binding:f,body:u,collection:d,line:l.line,type:"for"});continue}if(a==="include"){r+=1;const c=l.value.slice(7).trim(),p=G(c);p===void 0&&n(l.line,"Malformed {% include %} — expected a quoted partial name"),s.push({line:l.line,name:p,type:"include"});continue}n(l.line,`Unknown tag "{% ${a} %}". Supported: if, for, include.`)}return s};return i([])},G=e=>{if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.slice(1,-1)},$e=e=>e==null?"":typeof e=="boolean"||typeof e=="number"?String(e):typeof e=="string"?e:JSON.stringify(e),je=e=>e==null||e===!1||e===0||e===""?!1:Array.isArray(e)?e.length>0:!0,B=(e,t,r,n,i=!0)=>{const o=e.split(".");if(i&&o.length>0&&!Object.hasOwn(t,o[0]))throw new Error(`${n}:${r}: Variable "${e}" is not defined`);let s=t;for(const l of o){if(s==null)return;if(typeof s!="object")throw new TypeError(`${n}:${r}: Cannot read "${l}" on non-object value`);s=s[l]}return s},xe=e=>{const t=[];let r=0,n=0,i;for(let o=0;o<e.length;o+=1){const s=e[o];if(i){s===i&&(i=void 0);continue}if(s==='"'||s==="'"){i=s;continue}s==="("?r+=1:s===")"?r-=1:s==="|"&&r===0&&(t.push(e.slice(n,o)),n=o+1)}return t.push(e.slice(n)),t},ke=e=>{const t=e.trim(),r=t.indexOf("(");if(r===-1)return{args:[],name:t};if(!t.endsWith(")"))throw new Error(`Filter call "${e}" missing closing ")"`);const n=t.slice(0,r).trim(),i=t.slice(r+1,-1).trim();return i?{args:R(i).map(o=>o.trim()),name:n}:{args:[],name:n}},v=(e,t,r,n,i=!0)=>{const o=e.trim();if(o==="true")return!0;if(o==="false")return!1;if(o==="null"||o==="none")return null;const s=G(o);return s!==void 0?s:/^-?\d+(?:\.\d+)?$/.test(o)?Number(o):B(o,t,r,n,i)},D=(e,t,r,n,i=!0)=>{const o=xe(e),s=o[0].trim();let l=v(s,t,r,n,i);for(let a=1;a<o.length;a+=1){const c=o[a].trim(),{args:p,name:f}=ke(c),d=p.map(u=>v(u,t,r,n,i));try{l=z(f,l,d)}catch(u){const y=u instanceof Error?u.message:String(u);throw new Error(`${n}:${r}: ${y}`,{cause:u})}}return l},Y=(e,t)=>{let r,n=0;for(let i=0;i<=e.length-t.length;i+=1){const o=e[i];if(r){o===r&&(r=void 0);continue}if(o==='"'||o==="'"){r=o;continue}if(o==="("){n+=1;continue}if(o===")"){n-=1;continue}if(n===0&&e.slice(i,i+t.length)===t)return i}return-1},_=(e,t)=>{const r=[];let n=0,i=0;for(;i<=e.length-t.length;){const o=Y(e.slice(i),t);if(o===-1)break;r.push(e.slice(n,i+o)),i+=o+t.length,n=i}return r.push(e.slice(n)),r},g=(e,t,r,n)=>{const i=e.trim();if(i==="")return!1;if(i.startsWith("(")&&i.endsWith(")")&&Se(i)===i.length-1)return g(i.slice(1,-1),t,r,n);const o=_(i," or ");if(o.length>1)return o.some(l=>g(l,t,r,n));const s=_(i," and ");if(s.length>1)return s.every(l=>g(l,t,r,n));if(i.startsWith("not "))return!g(i.slice(4),t,r,n);for(const l of["==","!="]){const a=Y(i,l);if(a!==-1){const c=v(i.slice(0,a),t,n,r,!1),p=v(i.slice(a+l.length),t,n,r,!1),f=c===p;return l==="=="?f:!f}}return je(D(i,t,n,r,!1))},Se=e=>{if(e[0]!=="(")return-1;let t=0,r,n=-1;for(const i of e){if(n+=1,r){i===r&&(r=void 0);continue}if(i==='"'||i==="'"){r=i;continue}if(i==="(")t+=1;else if(i===")"&&(t-=1,t===0))return n}return-1},E=(e,t)=>{let r="";for(const n of e){if(n.type==="text"){r+=n.value;continue}if(n.type==="expr"){r+=$e(D(n.expression,t.scope,n.line,t.filename));continue}if(n.type==="if"){const i=g(n.condition,t.scope,t.filename,n.line)?n.consequent:n.alternate??[];r+=E(i,t);continue}if(n.type==="for"){const i=B(n.collection,t.scope,n.line,t.filename,!1);if(i==null)continue;if(!Array.isArray(i))throw new TypeError(`${t.filename}:${n.line}: {% for %} expected an array, got ${typeof i}`);for(const o of i){const s={...t.scope,[n.binding]:o};r+=E(n.body,{...t,scope:s})}continue}if(n.type==="include"){const i=t.partials?.get(n.name);if(!i)throw new Error(`${t.filename}:${n.line}: Partial "${n.name}" not found. Available: ${[...t.partials?.keys()??[]].join(", ")||"(none)"}`);const o=t.includeStack??new Set;if(o.has(n.name)){const s=[...o,n.name].join(" → ");throw new Error(`${t.filename}:${n.line}: Circular partial include detected: ${s}`)}o.add(n.name);try{r+=E(i,{...t,filename:`<partial:${n.name}>`,includeStack:o})}finally{o.delete(n.name)}}}return r},Ce=(e,t)=>F(q(e),t),j=(e,t)=>E(F(q(e),t.filename),t),L="template.yml",Oe=".raw",We=new Set([".cjs",".css",".env",".gitattributes",".gitignore",".graphql",".html",".ini",".js",".json",".json5",".jsonc",".jsx",".lock",".md",".mdx",".mjs",".prettierrc",".raw",".rs",".scss",".sh",".sql",".svg",".tera",".toml",".ts",".tsx",".twig",".txt",".vue",".xml",".yaml",".yml"]),Te=new Set(["Brewfile","CHANGELOG","CODEOWNERS","CONTRIBUTING","COPYING","Dockerfile","Gemfile","LICENCE","LICENSE","Makefile","NOTICE","Procfile","Rakefile","README","VERSION"]),_e=e=>{const t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\")),r=t===-1?e:e.slice(t+1),n=r.lastIndexOf(".");return n===-1||n===0?"":r.slice(n).toLowerCase()},J=e=>{const t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t===-1?e:e.slice(t+1)},Le=e=>{const t=_e(e);if(t!=="")return We.has(t);const r=J(e);return Te.has(r)},Me=e=>{const t={default:e.default,internal:e.internal,order:e.order,prompt:e.prompt,required:e.required};switch(e.type){case"array":return{...t,type:"array"};case"boolean":return{...t,default:typeof t.default=="boolean"?t.default:void 0,type:"boolean"};case"enum":return{...t,multiple:e.multiple,type:"enum",values:e.values??[]};case"number":return{...t,type:"number"};case"string":return{...t,type:"string"};default:throw new Error(`Unsupported variable type "${String(e.type)}"`)}},Ue=e=>e.replaceAll("\\","/").replace(/^\.\//,"").replaceAll(/\/+/g,"/"),Ie=(e,t,r)=>{const n=t.split("/").filter(Boolean);if(n.length===0)throw new Error("Empty destination path for value");let i=e;for(let o=0;o<n.length-1;o+=1){const s=n[o],l=i[s];if(l===void 0){const a={};i[s]=a,i=a}else if(typeof l=="object"&&!Buffer.isBuffer(l))i=l;else throw new TypeError(`Path conflict: "${n.slice(0,o+1).join("/")}" is both a file and a directory`)}i[n.at(-1)]=r},M=(e,t,r)=>{if(typeof e!="string")return Ne(e);const n=e.includes("{{")||e.includes("{%")?j(e,{filename:`${r}#frontmatter`,scope:t}):e;return g(n,t,`${r}#frontmatter`,1)},Ne=e=>e==null||e===!1||e===0||e===""?!1:Array.isArray(e)?e.length>0:typeof e=="string"?e!=="false"&&e!=="0":!0,Be=(e,t)=>{const r=I(e,L),n=X(r);if(!n||typeof n!="object")throw new Error(`${r}: must contain a YAML mapping`);const i={};if(n.variables)for(const[a,c]of Object.entries(n.variables))i[a]=Me(c);const o=new Map,s=[];for(const a of K(e,{includeDirs:!1,includeSymlinks:!1})){if(a.path===r)continue;const c=U(e,a.path).replaceAll("\\","/");if(c===L)continue;if(be(c)){const f=b(a.path),d=Ce(f,c);for(const u of ze(c))o.has(u)&&o.get(u)!==d&&Z.warn(`partial name "${u}" is declared by multiple files — last one wins. Use distinct names or fully-qualified includes.`),o.set(u,d);continue}if(c.endsWith(Oe)){const f=b(a.path);s.push({binary:null,isRaw:!0,rawText:f,relativePath:c});continue}if(Le(c)){const f=b(a.path);s.push({binary:null,isRaw:!1,rawText:f,relativePath:c});continue}const p=b(a.path,{buffer:!0});s.push({binary:p,isRaw:!1,rawText:null,relativePath:c})}const l=a=>{const c={...a.builtins,...a.options},p={},f={};for(const u of s){const y=u.relativePath;let w,C,O=!1;if(u.binary)w=u.binary;else if(u.isRaw)w=u.rawText??"";else{const V=u.rawText??"",h=Ee(V,H=>Q(H));if(h.frontmatter){if(h.frontmatter.skip!==void 0&&M(h.frontmatter.skip,c,y)||h.frontmatter.if!==void 0&&!M(h.frontmatter.if,c,y))continue;typeof h.frontmatter.to=="string"&&(C=j(h.frontmatter.to,{filename:`${y}#frontmatter.to`,partials:o,scope:c})),h.frontmatter.force===!0&&(O=!0)}w=j(h.body,{filename:y,partials:o,scope:c})}const W=Ue(C??ge(we(y),c));Ie(p,W,w),O&&(f[W]={force:!0})}const d={files:p};return Object.keys(f).length>0&&(d.filesMeta=f),d};return{about:{description:n.description??`Moon-format template at ${e}`,name:n.title??t},destination:n.destination,options:i,produce:l}},ze=e=>{const t=P(e),r=J(t),n=new Set([r,t]);if(r.startsWith("_")){n.add(r.replace(/^_+/,""));const i=t.slice(0,t.length-r.length);n.add(`${i}${r.replace(/^_+/,"")}`)}return[...n]};export{Be as loadMoonTemplate};
1
+ import{createRequire as u}from"node:module";const h=u(import.meta.url),p=typeof globalThis<"u"&&typeof globalThis.process<"u"?globalThis.process:process,_=t=>{if(typeof p<"u"&&p.versions&&p.versions.node){const[i,e]=p.versions.node.split(".").map(Number);if(i>22||i===22&&e>=3||i===20&&e>=16)return p.getBuiltinModule(t)}return h(t)},$=_("node:assert");function f(t,i){return`#compdef ${t}
2
+ compdef _${t} ${t}
3
+
4
+ # zsh completion for ${t} -*- shell-script -*-
5
+
6
+ __${t}_debug() {
7
+ local file="$BASH_COMP_DEBUG_FILE"
8
+ if [[ -n \${file} ]]; then
9
+ echo "$*" >> "\${file}"
10
+ fi
11
+ }
12
+
13
+ _${t}() {
14
+ local shellCompDirectiveError=${n.ShellCompDirectiveError}
15
+ local shellCompDirectiveNoSpace=${n.ShellCompDirectiveNoSpace}
16
+ local shellCompDirectiveNoFileComp=${n.ShellCompDirectiveNoFileComp}
17
+ local shellCompDirectiveFilterFileExt=${n.ShellCompDirectiveFilterFileExt}
18
+ local shellCompDirectiveFilterDirs=${n.ShellCompDirectiveFilterDirs}
19
+ local shellCompDirectiveKeepOrder=${n.ShellCompDirectiveKeepOrder}
20
+
21
+ local lastParam lastChar flagPrefix requestComp out directive comp lastComp noSpace keepOrder
22
+ local -a completions
23
+
24
+ __${t}_debug "\\n========= starting completion logic =========="
25
+ __${t}_debug "CURRENT: \${CURRENT}, words[*]: \${words[*]}"
26
+
27
+ # The user could have moved the cursor backwards on the command-line.
28
+ # We need to trigger completion from the $CURRENT location, so we need
29
+ # to truncate the command-line ($words) up to the $CURRENT location.
30
+ # (We cannot use $CURSOR as its value does not work when a command is an alias.)
31
+ words=( "\${=words[1,CURRENT]}" )
32
+ __${t}_debug "Truncated words[*]: \${words[*]},"
33
+
34
+ lastParam=\${words[-1]}
35
+ lastChar=\${lastParam[-1]}
36
+ __${t}_debug "lastParam: \${lastParam}, lastChar: \${lastChar}"
37
+
38
+ # For zsh, when completing a flag with an = (e.g., ${t} -n=<TAB>)
39
+ # completions must be prefixed with the flag
40
+ setopt local_options BASH_REMATCH
41
+ if [[ "\${lastParam}" =~ '-.*=' ]]; then
42
+ # We are dealing with a flag with an =
43
+ flagPrefix="-P \${BASH_REMATCH}"
44
+ fi
45
+
46
+ # Prepare the command to obtain completions, ensuring arguments are quoted for eval
47
+ local -a args_to_quote=("\${(@)words[2,-1]}")
48
+ if [ "\${lastChar}" = "" ]; then
49
+ # If the last parameter is complete (there is a space following it)
50
+ # We add an extra empty parameter so we can indicate this to the go completion code.
51
+ __${t}_debug "Adding extra empty parameter"
52
+ args_to_quote+=("")
53
+ fi
54
+
55
+ # Use Zsh's (q) flag to quote each argument safely for eval
56
+ local quoted_args=("\${(@q)args_to_quote}")
57
+
58
+ # Join the main command and the quoted arguments into a single string for eval
59
+ requestComp="${i} complete -- \${quoted_args[*]}"
60
+
61
+ __${t}_debug "About to call: eval \${requestComp}"
62
+
63
+ # Use eval to handle any environment variables and such
64
+ out=$(eval \${requestComp} 2>/dev/null)
65
+ __${t}_debug "completion output: \${out}"
66
+
67
+ # Extract the directive integer following a : from the last line
68
+ local lastLine
69
+ while IFS='
70
+ ' read -r line; do
71
+ lastLine=\${line}
72
+ done < <(printf "%s
73
+ " "\${out[@]}")
74
+ __${t}_debug "last line: \${lastLine}"
75
+
76
+ if [ "\${lastLine[1]}" = : ]; then
77
+ directive=\${lastLine[2,-1]}
78
+ # Remove the directive including the : and the newline
79
+ local suffix
80
+ (( suffix=\${#lastLine}+2))
81
+ out=\${out[1,-$suffix]}
82
+ else
83
+ # There is no directive specified. Leave $out as is.
84
+ __${t}_debug "No directive found. Setting to default"
85
+ directive=0
86
+ fi
87
+
88
+ __${t}_debug "directive: \${directive}"
89
+ __${t}_debug "completions: \${out}"
90
+ __${t}_debug "flagPrefix: \${flagPrefix}"
91
+
92
+ if [ $((directive & shellCompDirectiveError)) -ne 0 ]; then
93
+ __${t}_debug "Completion received error. Ignoring completions."
94
+ return
95
+ fi
96
+
97
+ local activeHelpMarker="%"
98
+ local endIndex=\${#activeHelpMarker}
99
+ local startIndex=$((\${#activeHelpMarker}+1))
100
+ local hasActiveHelp=0
101
+ while IFS='
102
+ ' read -r comp; do
103
+ # Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
104
+ if [ "\${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
105
+ __${t}_debug "ActiveHelp found: $comp"
106
+ comp="\${comp[$startIndex,-1]}"
107
+ if [ -n "$comp" ]; then
108
+ compadd -x "\${comp}"
109
+ __${t}_debug "ActiveHelp will need delimiter"
110
+ hasActiveHelp=1
111
+ fi
112
+ continue
113
+ fi
114
+
115
+ if [ -n "$comp" ]; then
116
+ # If requested, completions are returned with a description.
117
+ # The description is preceded by a TAB character.
118
+ # For zsh's _describe, we need to use a : instead of a TAB.
119
+ # We first need to escape any : as part of the completion itself.
120
+ comp=\${comp//:/\\:}
121
+
122
+ local tab="$(printf '\\t')"
123
+ comp=\${comp//$tab/:}
124
+
125
+ __${t}_debug "Adding completion: \${comp}"
126
+ completions+=\${comp}
127
+ lastComp=$comp
128
+ fi
129
+ done < <(printf "%s
130
+ " "\${out[@]}")
131
+
132
+ # Add a delimiter after the activeHelp statements, but only if:
133
+ # - there are completions following the activeHelp statements, or
134
+ # - file completion will be performed (so there will be choices after the activeHelp)
135
+ if [ $hasActiveHelp -eq 1 ]; then
136
+ if [ \${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
137
+ __${t}_debug "Adding activeHelp delimiter"
138
+ compadd -x "--"
139
+ hasActiveHelp=0
140
+ fi
141
+ fi
142
+
143
+ if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
144
+ __${t}_debug "Activating nospace."
145
+ noSpace="-S ''"
146
+ fi
147
+
148
+ if [ $((directive & shellCompDirectiveKeepOrder)) -ne 0 ]; then
149
+ __${t}_debug "Activating keep order."
150
+ keepOrder="-V"
151
+ fi
152
+
153
+ if [ $((directive & shellCompDirectiveFilterFileExt)) -ne 0 ]; then
154
+ # File extension filtering
155
+ local filteringCmd
156
+ filteringCmd='_files'
157
+ for filter in \${completions[@]}; do
158
+ if [ \${filter[1]} != '*' ]; then
159
+ # zsh requires a glob pattern to do file filtering
160
+ filter="\\*.$filter"
161
+ fi
162
+ filteringCmd+=" -g $filter"
163
+ done
164
+ filteringCmd+=" \${flagPrefix}"
165
+
166
+ __${t}_debug "File filtering command: $filteringCmd"
167
+ _arguments '*:filename:'"$filteringCmd"
168
+ elif [ $((directive & shellCompDirectiveFilterDirs)) -ne 0 ]; then
169
+ # File completion for directories only
170
+ local subdir
171
+ subdir="\${completions[1]}"
172
+ if [ -n "$subdir" ]; then
173
+ __${t}_debug "Listing directories in $subdir"
174
+ pushd "\${subdir}" >/dev/null 2>&1
175
+ else
176
+ __${t}_debug "Listing directories in ."
177
+ fi
178
+
179
+ local result
180
+ _arguments '*:dirname:_files -/'" \${flagPrefix}"
181
+ result=$?
182
+ if [ -n "$subdir" ]; then
183
+ popd >/dev/null 2>&1
184
+ fi
185
+ return $result
186
+ else
187
+ __${t}_debug "Calling _describe"
188
+ if eval _describe $keepOrder "completions" completions -Q \${flagPrefix} \${noSpace}; then
189
+ __${t}_debug "_describe found some completions"
190
+
191
+ # Return the success of having called _describe
192
+ return 0
193
+ else
194
+ __${t}_debug "_describe did not find completions."
195
+ __${t}_debug "Checking if we should do file completion."
196
+ if [ $((directive & shellCompDirectiveNoFileComp)) -ne 0 ]; then
197
+ __${t}_debug "deactivating file completion"
198
+
199
+ # Return 0 to indicate completion is finished and prevent zsh from
200
+ # trying other completion algorithms (which could cause hanging).
201
+ # We use NoFileComp directive to explicitly disable file completion.
202
+ return 0
203
+ else
204
+ # Perform file completion
205
+ __${t}_debug "Activating file completion"
206
+
207
+ # We must return the result of this command, so it must be the
208
+ # last command, or else we must store its result to return it.
209
+ _arguments '*:filename:_files'" \${flagPrefix}"
210
+ fi
211
+ fi
212
+ fi
213
+ }
214
+
215
+ # don't run the completion function when being sourced or eval-ed
216
+ if [ "\${funcstack[1]}" = "_${t}" ]; then
217
+ _${t}
218
+ fi
219
+ `}function g(t,i){let e=t.replace(/[-:]/g,"_");return`# bash completion for ${t}
220
+
221
+ # Define shell completion directives
222
+ readonly ShellCompDirectiveError=${n.ShellCompDirectiveError}
223
+ readonly ShellCompDirectiveNoSpace=${n.ShellCompDirectiveNoSpace}
224
+ readonly ShellCompDirectiveNoFileComp=${n.ShellCompDirectiveNoFileComp}
225
+ readonly ShellCompDirectiveFilterFileExt=${n.ShellCompDirectiveFilterFileExt}
226
+ readonly ShellCompDirectiveFilterDirs=${n.ShellCompDirectiveFilterDirs}
227
+ readonly ShellCompDirectiveKeepOrder=${n.ShellCompDirectiveKeepOrder}
228
+
229
+ # Function to debug completion
230
+ __${e}_debug() {
231
+ if [[ -n \${BASH_COMP_DEBUG_FILE:-} ]]; then
232
+ echo "$*" >> "\${BASH_COMP_DEBUG_FILE}"
233
+ fi
234
+ }
235
+
236
+ # Function to handle completions
237
+ __${e}_complete() {
238
+ local cur prev words cword
239
+ _get_comp_words_by_ref -n "=:" cur prev words cword
240
+
241
+ local requestComp out directive
242
+
243
+ # Build the command to get completions
244
+ requestComp="${i} complete -- \${words[@]:1}"
245
+
246
+ # Add an empty parameter if the last parameter is complete
247
+ if [[ -z "$cur" ]]; then
248
+ requestComp="$requestComp ''"
249
+ fi
250
+
251
+ # Get completions from the program
252
+ out=$(eval "$requestComp" 2>/dev/null)
253
+
254
+ # Extract directive if present
255
+ directive=0
256
+ if [[ "$out" == *:* ]]; then
257
+ directive=\${out##*:}
258
+ out=\${out%:*}
259
+ fi
260
+
261
+ # Process completions based on directive
262
+ if [[ $((directive & $ShellCompDirectiveError)) -ne 0 ]]; then
263
+ # Error, no completion
264
+ return
265
+ fi
266
+
267
+ # Apply directives
268
+ if [[ $((directive & $ShellCompDirectiveNoSpace)) -ne 0 ]]; then
269
+ compopt -o nospace
270
+ fi
271
+ if [[ $((directive & $ShellCompDirectiveKeepOrder)) -ne 0 ]]; then
272
+ compopt -o nosort
273
+ fi
274
+ if [[ $((directive & $ShellCompDirectiveNoFileComp)) -ne 0 ]]; then
275
+ compopt +o default
276
+ fi
277
+
278
+ # Handle file extension filtering
279
+ if [[ $((directive & $ShellCompDirectiveFilterFileExt)) -ne 0 ]]; then
280
+ local filter=""
281
+ for ext in $out; do
282
+ filter="$filter|$ext"
283
+ done
284
+ filter="\\.($filter)"
285
+ compopt -o filenames
286
+ COMPREPLY=( $(compgen -f -X "!$filter" -- "$cur") )
287
+ return
288
+ fi
289
+
290
+ # Handle directory filtering
291
+ if [[ $((directive & $ShellCompDirectiveFilterDirs)) -ne 0 ]]; then
292
+ compopt -o dirnames
293
+ COMPREPLY=( $(compgen -d -- "$cur") )
294
+ return
295
+ fi
296
+
297
+ # Process completions
298
+ local IFS=$'\\n'
299
+ local tab=$(printf '\\t')
300
+
301
+ # Parse completions with descriptions
302
+ local completions=()
303
+ while read -r comp; do
304
+ if [[ "$comp" == *$tab* ]]; then
305
+ # Split completion and description
306
+ local value=\${comp%%$tab*}
307
+ local desc=\${comp#*$tab}
308
+ completions+=("$value")
309
+ else
310
+ completions+=("$comp")
311
+ fi
312
+ done <<< "$out"
313
+
314
+ # Return completions
315
+ COMPREPLY=( $(compgen -W "\${completions[*]}" -- "$cur") )
316
+ }
317
+
318
+ # Register completion function
319
+ complete -F __${e}_complete ${t}
320
+ `}function v(t,i){let e=t.replace(/[-:]/g,"_"),o=n.ShellCompDirectiveError,l=n.ShellCompDirectiveNoSpace,r=n.ShellCompDirectiveNoFileComp,s=n.ShellCompDirectiveFilterFileExt,a=n.ShellCompDirectiveFilterDirs;return`# fish completion for ${t} -*- shell-script -*-
321
+
322
+ function __${e}_debug
323
+ set -l file "$BASH_COMP_DEBUG_FILE"
324
+ if test -n "$file"
325
+ echo "$argv" >> $file
326
+ end
327
+ end
328
+
329
+ function __${e}_perform_completion
330
+ __${e}_debug "Starting __${e}_perform_completion"
331
+
332
+ # Extract all args except the last one
333
+ set -l args (commandline -opc)
334
+ # Extract the last arg and escape it in case it is a space or wildcard
335
+ set -l lastArg (string escape -- (commandline -ct))
336
+
337
+ __${e}_debug "args: $args"
338
+ __${e}_debug "last arg: $lastArg"
339
+
340
+ # Build the completion request command
341
+ set -l requestComp "${i} complete -- (string join ' ' -- (string escape -- $args[2..-1])) $lastArg"
342
+
343
+ __${e}_debug "Calling $requestComp"
344
+ set -l results (eval $requestComp 2> /dev/null)
345
+
346
+ # Some programs may output extra empty lines after the directive.
347
+ # Let's ignore them or else it will break completion.
348
+ # Ref: https://github.com/spf13/cobra/issues/1279
349
+ for line in $results[-1..1]
350
+ if test (string trim -- $line) = ""
351
+ # Found an empty line, remove it
352
+ set results $results[1..-2]
353
+ else
354
+ # Found non-empty line, we have our proper output
355
+ break
356
+ end
357
+ end
358
+
359
+ set -l comps $results[1..-2]
360
+ set -l directiveLine $results[-1]
361
+
362
+ # For Fish, when completing a flag with an = (e.g., <program> -n=<TAB>)
363
+ # completions must be prefixed with the flag
364
+ set -l flagPrefix (string match -r -- '-.*=' "$lastArg")
365
+
366
+ __${e}_debug "Comps: $comps"
367
+ __${e}_debug "DirectiveLine: $directiveLine"
368
+ __${e}_debug "flagPrefix: $flagPrefix"
369
+
370
+ for comp in $comps
371
+ printf "%s%s\\n" "$flagPrefix" "$comp"
372
+ end
373
+
374
+ printf "%s\\n" "$directiveLine"
375
+ end
376
+
377
+ # This function limits calls to __${e}_perform_completion, by caching the result
378
+ function __${e}_perform_completion_once
379
+ __${e}_debug "Starting __${e}_perform_completion_once"
380
+
381
+ if test -n "$__${e}_perform_completion_once_result"
382
+ __${e}_debug "Seems like a valid result already exists, skipping __${e}_perform_completion"
383
+ return 0
384
+ end
385
+
386
+ set --global __${e}_perform_completion_once_result (__${e}_perform_completion)
387
+ if test -z "$__${e}_perform_completion_once_result"
388
+ __${e}_debug "No completions, probably due to a failure"
389
+ return 1
390
+ end
391
+
392
+ __${e}_debug "Performed completions and set __${e}_perform_completion_once_result"
393
+ return 0
394
+ end
395
+
396
+ # This function is used to clear the cached result after completions are run
397
+ function __${e}_clear_perform_completion_once_result
398
+ __${e}_debug ""
399
+ __${e}_debug "========= clearing previously set __${e}_perform_completion_once_result variable =========="
400
+ set --erase __${e}_perform_completion_once_result
401
+ __${e}_debug "Successfully erased the variable __${e}_perform_completion_once_result"
402
+ end
403
+
404
+ function __${e}_requires_order_preservation
405
+ __${e}_debug ""
406
+ __${e}_debug "========= checking if order preservation is required =========="
407
+
408
+ __${e}_perform_completion_once
409
+ if test -z "$__${e}_perform_completion_once_result"
410
+ __${e}_debug "Error determining if order preservation is required"
411
+ return 1
412
+ end
413
+
414
+ set -l directive (string sub --start 2 $__${e}_perform_completion_once_result[-1])
415
+ __${e}_debug "Directive is: $directive"
416
+
417
+ set -l shellCompDirectiveKeepOrder ${n.ShellCompDirectiveKeepOrder}
418
+ set -l keeporder (math (math --scale 0 $directive / $shellCompDirectiveKeepOrder) % 2)
419
+ __${e}_debug "Keeporder is: $keeporder"
420
+
421
+ if test $keeporder -ne 0
422
+ __${e}_debug "This does require order preservation"
423
+ return 0
424
+ end
425
+
426
+ __${e}_debug "This doesn't require order preservation"
427
+ return 1
428
+ end
429
+
430
+ # This function does two things:
431
+ # - Obtain the completions and store them in the global __${e}_comp_results
432
+ # - Return false if file completion should be performed
433
+ function __${e}_prepare_completions
434
+ __${e}_debug ""
435
+ __${e}_debug "========= starting completion logic =========="
436
+
437
+ # Start fresh
438
+ set --erase __${e}_comp_results
439
+
440
+ __${e}_perform_completion_once
441
+ __${e}_debug "Completion results: $__${e}_perform_completion_once_result"
442
+
443
+ if test -z "$__${e}_perform_completion_once_result"
444
+ __${e}_debug "No completion, probably due to a failure"
445
+ # Might as well do file completion, in case it helps
446
+ return 1
447
+ end
448
+
449
+ set -l directive (string sub --start 2 $__${e}_perform_completion_once_result[-1])
450
+ set --global __${e}_comp_results $__${e}_perform_completion_once_result[1..-2]
451
+
452
+ __${e}_debug "Completions are: $__${e}_comp_results"
453
+ __${e}_debug "Directive is: $directive"
454
+
455
+ set -l shellCompDirectiveError ${o}
456
+ set -l shellCompDirectiveNoSpace ${l}
457
+ set -l shellCompDirectiveNoFileComp ${r}
458
+ set -l shellCompDirectiveFilterFileExt ${s}
459
+ set -l shellCompDirectiveFilterDirs ${a}
460
+
461
+ if test -z "$directive"
462
+ set directive 0
463
+ end
464
+
465
+ set -l compErr (math (math --scale 0 $directive / $shellCompDirectiveError) % 2)
466
+ if test $compErr -eq 1
467
+ __${e}_debug "Received error directive: aborting."
468
+ # Might as well do file completion, in case it helps
469
+ return 1
470
+ end
471
+
472
+ set -l filefilter (math (math --scale 0 $directive / $shellCompDirectiveFilterFileExt) % 2)
473
+ set -l dirfilter (math (math --scale 0 $directive / $shellCompDirectiveFilterDirs) % 2)
474
+ if test $filefilter -eq 1; or test $dirfilter -eq 1
475
+ __${e}_debug "File extension filtering or directory filtering not supported"
476
+ # Do full file completion instead
477
+ return 1
478
+ end
479
+
480
+ set -l nospace (math (math --scale 0 $directive / $shellCompDirectiveNoSpace) % 2)
481
+ set -l nofiles (math (math --scale 0 $directive / $shellCompDirectiveNoFileComp) % 2)
482
+
483
+ __${e}_debug "nospace: $nospace, nofiles: $nofiles"
484
+
485
+ # If we want to prevent a space, or if file completion is NOT disabled,
486
+ # we need to count the number of valid completions.
487
+ # To do so, we will filter on prefix as the completions we have received
488
+ # may not already be filtered so as to allow fish to match on different
489
+ # criteria than the prefix.
490
+ if test $nospace -ne 0; or test $nofiles -eq 0
491
+ set -l prefix (commandline -t | string escape --style=regex)
492
+ __${e}_debug "prefix: $prefix"
493
+
494
+ set -l completions (string match -r -- "^$prefix.*" $__${e}_comp_results)
495
+ set --global __${e}_comp_results $completions
496
+ __${e}_debug "Filtered completions are: $__${e}_comp_results"
497
+
498
+ # Important not to quote the variable for count to work
499
+ set -l numComps (count $__${e}_comp_results)
500
+ __${e}_debug "numComps: $numComps"
501
+
502
+ if test $numComps -eq 1; and test $nospace -ne 0
503
+ # We must first split on \\t to get rid of the descriptions to be
504
+ # able to check what the actual completion will be.
505
+ # We don't need descriptions anyway since there is only a single
506
+ # real completion which the shell will expand immediately.
507
+ set -l split (string split --max 1 "\\t" $__${e}_comp_results[1])
508
+
509
+ # Fish won't add a space if the completion ends with any
510
+ # of the following characters: @=/:.,
511
+ set -l lastChar (string sub -s -1 -- $split)
512
+ if not string match -r -q "[@=/:.,]" -- "$lastChar"
513
+ # In other cases, to support the "nospace" directive we trick the shell
514
+ # by outputting an extra, longer completion.
515
+ __${e}_debug "Adding second completion to perform nospace directive"
516
+ set --global __${e}_comp_results $split[1] $split[1].
517
+ __${e}_debug "Completions are now: $__${e}_comp_results"
518
+ end
519
+ end
520
+
521
+ if test $numComps -eq 0; and test $nofiles -eq 0
522
+ # To be consistent with bash and zsh, we only trigger file
523
+ # completion when there are no other completions
524
+ __${e}_debug "Requesting file completion"
525
+ return 1
526
+ end
527
+ end
528
+
529
+ return 0
530
+ end
531
+
532
+ # Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
533
+ # so we can properly delete any completions provided by another script.
534
+ # Only do this if the program can be found, or else fish may print some errors; besides,
535
+ # the existing completions will only be loaded if the program can be found.
536
+ if type -q "${t}"
537
+ # The space after the program name is essential to trigger completion for the program
538
+ # and not completion of the program name itself.
539
+ # Also, we use '> /dev/null 2>&1' since '&>' is not supported in older versions of fish.
540
+ complete --do-complete "${t} " > /dev/null 2>&1
541
+ end
542
+
543
+ # Remove any pre-existing completions for the program since we will be handling all of them.
544
+ complete -c ${t} -e
545
+
546
+ # This will get called after the two calls below and clear the cached result
547
+ complete -c ${t} -n '__${e}_clear_perform_completion_once_result'
548
+ # The call to __${e}_prepare_completions will setup __${e}_comp_results
549
+ # which provides the program's completion choices.
550
+ # If this doesn't require order preservation, we don't use the -k flag
551
+ complete -c ${t} -n 'not __${e}_requires_order_preservation && __${e}_prepare_completions' -f -a '$__${e}_comp_results'
552
+ # Otherwise we use the -k flag
553
+ complete -k -c ${t} -n '__${e}_requires_order_preservation && __${e}_prepare_completions' -f -a '$__${e}_comp_results'
554
+ `}function C(t,i){let e=t.replace(/[-:]/g,"_");return`# powershell completion for ${t} -*- shell-script -*-
555
+
556
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
557
+ function __${t}_debug {
558
+ if ($env:BASH_COMP_DEBUG_FILE) {
559
+ "$args" | Out-File -Append -FilePath "$env:BASH_COMP_DEBUG_FILE"
560
+ }
561
+ }
562
+
563
+ filter __${t}_escapeStringWithSpecialChars {
564
+ $_ -replace '\\s|#|@|\\$|;|,|''|\\{|\\}|\\(|\\)|"|\\||<|>|&','\`$&'
565
+ }
566
+
567
+ [scriptblock]$__${e}CompleterBlock = {
568
+ param(
569
+ $WordToComplete,
570
+ $CommandAst,
571
+ $CursorPosition
572
+ )
573
+
574
+ # Get the current command line and convert into a string
575
+ $Command = $CommandAst.CommandElements
576
+ $Command = "$Command"
577
+
578
+ __${t}_debug ""
579
+ __${t}_debug "========= starting completion logic =========="
580
+ __${t}_debug "WordToComplete: $WordToComplete Command: $Command CursorPosition: $CursorPosition"
581
+
582
+ # The user could have moved the cursor backwards on the command-line.
583
+ # We need to trigger completion from the $CursorPosition location, so we need
584
+ # to truncate the command-line ($Command) up to the $CursorPosition location.
585
+ # Make sure the $Command is longer then the $CursorPosition before we truncate.
586
+ # This happens because the $Command does not include the last space.
587
+ if ($Command.Length -gt $CursorPosition) {
588
+ $Command = $Command.Substring(0, $CursorPosition)
589
+ }
590
+ __${t}_debug "Truncated command: $Command"
591
+
592
+ $ShellCompDirectiveError=${n.ShellCompDirectiveError}
593
+ $ShellCompDirectiveNoSpace=${n.ShellCompDirectiveNoSpace}
594
+ $ShellCompDirectiveNoFileComp=${n.ShellCompDirectiveNoFileComp}
595
+ $ShellCompDirectiveFilterFileExt=${n.ShellCompDirectiveFilterFileExt}
596
+ $ShellCompDirectiveFilterDirs=${n.ShellCompDirectiveFilterDirs}
597
+ $ShellCompDirectiveKeepOrder=${n.ShellCompDirectiveKeepOrder}
598
+
599
+ # Prepare the command to request completions for the program.
600
+ # Split the command at the first space to separate the program and arguments.
601
+ $Program, $Arguments = $Command.Split(" ", 2)
602
+
603
+ $QuotedArgs = ($Arguments -split ' ' | ForEach-Object { "'" + ($_ -replace "'", "''") + "'" }) -join ' '
604
+ __${t}_debug "QuotedArgs: $QuotedArgs"
605
+
606
+ $RequestComp = "& ${i} complete '--' $QuotedArgs"
607
+ __${t}_debug "RequestComp: $RequestComp"
608
+
609
+ # we cannot use $WordToComplete because it
610
+ # has the wrong values if the cursor was moved
611
+ # so use the last argument
612
+ if ($WordToComplete -ne "" ) {
613
+ $WordToComplete = $Arguments.Split(" ")[-1]
614
+ }
615
+ __${t}_debug "New WordToComplete: $WordToComplete"
616
+
617
+
618
+ # Check for flag with equal sign
619
+ $IsEqualFlag = ($WordToComplete -Like "--*=*" )
620
+ if ( $IsEqualFlag ) {
621
+ __${t}_debug "Completing equal sign flag"
622
+ # Remove the flag part
623
+ $Flag, $WordToComplete = $WordToComplete.Split("=", 2)
624
+ }
625
+
626
+ if ( $WordToComplete -eq "" -And ( -Not $IsEqualFlag )) {
627
+ # If the last parameter is complete (there is a space following it)
628
+ # We add an extra empty parameter so we can indicate this to the go method.
629
+ __${t}_debug "Adding extra empty parameter"
630
+ # PowerShell 7.2+ changed the way how the arguments are passed to executables,
631
+ # so for pre-7.2 or when Legacy argument passing is enabled we need to use
632
+ if ($PSVersionTable.PsVersion -lt [version]'7.2.0' -or
633
+ ($PSVersionTable.PsVersion -lt [version]'7.3.0' -and -not [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -or
634
+ (($PSVersionTable.PsVersion -ge [version]'7.3.0' -or [ExperimentalFeature]::IsEnabled("PSNativeCommandArgumentPassing")) -and
635
+ $PSNativeCommandArgumentPassing -eq 'Legacy')) {
636
+ $RequestComp="$RequestComp" + ' \`"\`"'
637
+ } else {
638
+ $RequestComp = "$RequestComp" + ' ""'
639
+ }
640
+ }
641
+
642
+ __${t}_debug "Calling $RequestComp"
643
+ # First disable ActiveHelp which is not supported for Powershell
644
+ $env:ActiveHelp = 0
645
+
646
+ # call the command store the output in $out and redirect stderr and stdout to null
647
+ # $Out is an array contains each line per element
648
+ Invoke-Expression -OutVariable out "$RequestComp" 2>&1 | Out-Null
649
+
650
+ # get directive from last line
651
+ [int]$Directive = $Out[-1].TrimStart(':')
652
+ if ($Directive -eq "") {
653
+ # There is no directive specified
654
+ $Directive = 0
655
+ }
656
+ __${t}_debug "The completion directive is: $Directive"
657
+
658
+ # remove directive (last element) from out
659
+ $Out = $Out | Where-Object { $_ -ne $Out[-1] }
660
+ __${t}_debug "The completions are: $Out"
661
+
662
+ if (($Directive -band $ShellCompDirectiveError) -ne 0 ) {
663
+ # Error code. No completion.
664
+ __${t}_debug "Received error from custom completion go code"
665
+ return
666
+ }
667
+
668
+ $Longest = 0
669
+ [Array]$Values = $Out | ForEach-Object {
670
+ # Split the output in name and description
671
+ $Name, $Description = $_.Split("\`t", 2)
672
+ __${t}_debug "Name: $Name Description: $Description"
673
+
674
+ # Look for the longest completion so that we can format things nicely
675
+ if ($Longest -lt $Name.Length) {
676
+ $Longest = $Name.Length
677
+ }
678
+
679
+ # Set the description to a one space string if there is none set.
680
+ # This is needed because the CompletionResult does not accept an empty string as argument
681
+ if (-Not $Description) {
682
+ $Description = " "
683
+ }
684
+ @{ Name = "$Name"; Description = "$Description" }
685
+ }
686
+
687
+
688
+ $Space = " "
689
+ if (($Directive -band $ShellCompDirectiveNoSpace) -ne 0 ) {
690
+ # remove the space here
691
+ __${t}_debug "ShellCompDirectiveNoSpace is called"
692
+ $Space = ""
693
+ }
694
+
695
+ if ((($Directive -band $ShellCompDirectiveFilterFileExt) -ne 0 ) -or
696
+ (($Directive -band $ShellCompDirectiveFilterDirs) -ne 0 )) {
697
+ __${t}_debug "ShellCompDirectiveFilterFileExt ShellCompDirectiveFilterDirs are not supported"
698
+
699
+ # return here to prevent the completion of the extensions
700
+ return
701
+ }
702
+
703
+ $Values = $Values | Where-Object {
704
+ # filter the result
705
+ $_.Name -like "$WordToComplete*"
706
+
707
+ # Join the flag back if we have an equal sign flag
708
+ if ( $IsEqualFlag ) {
709
+ __${t}_debug "Join the equal sign flag back to the completion value"
710
+ $_.Name = $Flag + "=" + $_.Name
711
+ }
712
+ }
713
+
714
+ # we sort the values in ascending order by name if keep order isn't passed
715
+ if (($Directive -band $ShellCompDirectiveKeepOrder) -eq 0 ) {
716
+ $Values = $Values | Sort-Object -Property Name
717
+ }
718
+
719
+ if (($Directive -band $ShellCompDirectiveNoFileComp) -ne 0 ) {
720
+ __${t}_debug "ShellCompDirectiveNoFileComp is called"
721
+
722
+ if ($Values.Length -eq 0) {
723
+ # Just print an empty string here so the
724
+ # shell does not start to complete paths.
725
+ # We cannot use CompletionResult here because
726
+ # it does not accept an empty string as argument.
727
+ ""
728
+ return
729
+ }
730
+ }
731
+
732
+ # Get the current mode
733
+ $Mode = (Get-PSReadLineKeyHandler | Where-Object { $_.Key -eq "Tab" }).Function
734
+ __${t}_debug "Mode: $Mode"
735
+
736
+ $Values | ForEach-Object {
737
+
738
+ # store temporary because switch will overwrite $_
739
+ $comp = $_
740
+
741
+ # PowerShell supports three different completion modes
742
+ # - TabCompleteNext (default windows style - on each key press the next option is displayed)
743
+ # - Complete (works like bash)
744
+ # - MenuComplete (works like zsh)
745
+ # You set the mode with Set-PSReadLineKeyHandler -Key Tab -Function <mode>
746
+
747
+ # CompletionResult Arguments:
748
+ # 1) CompletionText text to be used as the auto completion result
749
+ # 2) ListItemText text to be displayed in the suggestion list
750
+ # 3) ResultType type of completion result
751
+ # 4) ToolTip text for the tooltip with details about the object
752
+
753
+ switch ($Mode) {
754
+
755
+ # bash like
756
+ "Complete" {
757
+
758
+ if ($Values.Length -eq 1) {
759
+ __${t}_debug "Only one completion left"
760
+
761
+ # insert space after value
762
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
763
+
764
+ } else {
765
+ # Add the proper number of spaces to align the descriptions
766
+ while($comp.Name.Length -lt $Longest) {
767
+ $comp.Name = $comp.Name + " "
768
+ }
769
+
770
+ # Check for empty description and only add parentheses if needed
771
+ if ($($comp.Description) -eq " " ) {
772
+ $Description = ""
773
+ } else {
774
+ $Description = " ($($comp.Description))"
775
+ }
776
+
777
+ [System.Management.Automation.CompletionResult]::new("$($comp.Name)$Description", "$($comp.Name)$Description", 'ParameterValue', "$($comp.Description)")
778
+ }
779
+ }
780
+
781
+ # zsh like
782
+ "MenuComplete" {
783
+ # insert space after value
784
+ # MenuComplete will automatically show the ToolTip of
785
+ # the highlighted value at the bottom of the suggestions.
786
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars) + $Space, "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
787
+ }
788
+
789
+ # TabCompleteNext and in case we get something unknown
790
+ Default {
791
+ # Like MenuComplete but we don't want to add a space here because
792
+ # the user need to press space anyway to get the completion.
793
+ # Description will not be shown because that's not possible with TabCompleteNext
794
+ [System.Management.Automation.CompletionResult]::new($($comp.Name | __${t}_escapeStringWithSpecialChars), "$($comp.Name)", 'ParameterValue', "$($comp.Description)")
795
+ }
796
+ }
797
+
798
+ }
799
+ }
800
+
801
+ Register-ArgumentCompleter -CommandName '${t}' -ScriptBlock $__${e}CompleterBlock
802
+ `}const n={ShellCompDirectiveError:1,ShellCompDirectiveNoSpace:2,ShellCompDirectiveNoFileComp:4,ShellCompDirectiveFilterFileExt:8,ShellCompDirectiveFilterDirs:16,ShellCompDirectiveKeepOrder:32,ShellCompDirectiveDefault:0};var b=class{name;variadic;command;handler;constructor(t,i,e,o=!1){this.command=t,this.name=i,this.handler=e,this.variadic=o}},w=class{value;description;command;handler;alias;isBoolean;constructor(t,i,e,o,l,r){this.command=t,this.value=i,this.description=e,this.handler=o,this.alias=l,this.isBoolean=r}},m=class{value;description;options=new Map;arguments=new Map;parent;constructor(t,i){this.value=t,this.description=i}option(t,i,e,o){let l,r,s;typeof e=="function"?(l=e,r=o,s=!1):typeof e=="string"?(l=void 0,r=e,s=!0):(l=void 0,r=void 0,s=!0);let a=new w(this,t,i,l,r,s);return this.options.set(t,a),this}argument(t,i,e=!1){let o=new b(this,t,i,e);return this.arguments.set(t,o),this}},D=class extends m{commands=new Map;completions=[];directive=n.ShellCompDirectiveDefault;constructor(){super("","")}command(t,i){let e=new m(t,i);return this.commands.set(t,e),e}stripOptions(t){let i=[],e=0;for(;e<t.length;){let o=t[e];if(o.startsWith("-")){e++;let l=!1,r=this.findOption(this,o);if(r)l=r.isBoolean??!1;else for(let[,s]of this.commands){let a=this.findOption(s,o);if(a){l=a.isBoolean??!1;break}}!l&&e<t.length&&!t[e].startsWith("-")&&e++}else i.push(o),e++}return i}matchCommand(t){t=this.stripOptions(t);let i=[],e=[],o=null;for(let l=0;l<t.length;l++){let r=t[l];i.push(r);let s=this.commands.get(i.join(" "));if(s)o=s;else{e=t.slice(l,t.length);break}}return[o||this,e]}shouldCompleteFlags(t,i){if(i.startsWith("-"))return!0;if(t?.startsWith("-")){let e=this.findOption(this,t);if(!e){for(let[,o]of this.commands)if(e=this.findOption(o,t),e)break}return!(e&&e.isBoolean)}return!1}shouldCompleteCommands(t){return!t.startsWith("-")}handleFlagCompletion(t,i,e,o){let l;if(e.includes("=")){let[r]=e.split("=");l=r}else if(o?.startsWith("-")){let r=this.findOption(t,o);r&&!r.isBoolean&&(l=o)}if(l){let r=this.findOption(t,l);if(r?.handler){let s=[];r.handler.call(r,(a,c)=>s.push({value:a,description:c}),t.options),this.completions=s}return}if(e.startsWith("-")){let r=e.startsWith("-")&&!e.startsWith("--"),s=e.replace(/^-+/,"");for(let[a,c]of t.options)r&&c.alias&&`-${c.alias}`.startsWith(e)?this.completions.push({value:`-${c.alias}`,description:c.description}):!r&&a.startsWith(s)&&this.completions.push({value:`--${a}`,description:c.description})}}findOption(t,i){let e=t.options.get(i);if(e||(e=t.options.get(i.replace(/^-+/,"")),e))return e;for(let[o,l]of t.options)if(l.alias&&`-${l.alias}`===i)return l}handleCommandCompletion(t,i){let e=this.stripOptions(t);for(let[o,l]of this.commands){if(o==="")continue;let r=o.split(" ");r.slice(0,e.length).every((s,a)=>s===e[a])&&r[e.length]?.startsWith(i)&&this.completions.push({value:r[e.length],description:l.description})}}handlePositionalCompletion(t,i){let e=this.stripOptions(i),o=t.value.split(" ").length,l=Math.max(0,e.length-o),r=Array.from(t.arguments.entries());if(r.length>0){let s;if(l<r.length){let[a,c]=r[l];s=c}else{let a=r[r.length-1][1];a.variadic&&(s=a)}if(s&&s.handler&&typeof s.handler=="function"){let a=[];s.handler.call(s,(c,d)=>a.push({value:c,description:d}),t.options),this.completions.push(...a)}}}complete(t){this.directive=n.ShellCompDirectiveNoFileComp;let i=new Set;this.completions.filter(e=>i.has(e.value)?!1:(i.add(e.value),!0)).filter(e=>{if(t.includes("=")){let[,o]=t.split("=");return e.value.startsWith(o)}return e.value.startsWith(t)}).forEach(e=>console.log(`${e.value} ${e.description??""}`)),console.log(`:${this.directive}`)}parse(t){this.completions=[];let i=t[t.length-1]==="";i&&t.pop();let e=t[t.length-1]||"",o=t.slice(0,-1);i&&(e!==""&&o.push(e),e="");let[l]=this.matchCommand(o),r=o[o.length-1];this.shouldCompleteFlags(r,e)?this.handleFlagCompletion(l,o,e,r):(this.shouldCompleteCommands(e)&&this.handleCommandCompletion(o,e),l&&l.arguments.size>0&&this.handlePositionalCompletion(l,o)),this.complete(e)}setup(t,i,e){switch($(e==="zsh"||e==="bash"||e==="fish"||e==="powershell","Unsupported shell"),e){case"zsh":{let o=f(t,i);console.log(o);break}case"bash":{let o=g(t,i);console.log(o);break}case"fish":{let o=v(t,i);console.log(o);break}case"powershell":{let o=C(t,i);console.log(o);break}}}};const F=new D;export{b as Argument,m as Command,w as Option,D as RootCommand,n as ShellCompDirective,F as default};