@stricli/auto-complete 0.0.1

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/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # `@stricli/auto-complete`
2
+
3
+ > Common utilities for enhancing Stricli applications with autocomplete
4
+
5
+ [![NPM Version](https://img.shields.io/npm/v/@stricli/auto-complete.svg?style=flat-square)](https://www.npmjs.com/package/@stricli/auto-complete)
6
+ [![NPM Type Definitions](https://img.shields.io/npm/types/@stricli/auto-complete.svg?style=flat-square)](https://www.npmjs.com/package/@stricli/auto-complete)
7
+ [![NPM Downloads](https://img.shields.io/npm/dm/@stricli/auto-complete.svg?style=flat-square)](https://www.npmjs.com/package/@stricli/auto-complete)
8
+
9
+ 👉 See **https://bloomberg.github.io/stricli/packages/auto-complete** for documentation on this package.
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ "use strict";var I=Object.create;var u=Object.defineProperty;var N=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,F=Object.prototype.hasOwnProperty;var j=(t,e)=>()=>(t&&(e=t(t=0)),e);var B=(t,e)=>{for(var o in e)u(t,o,{get:e[o],enumerable:!0})},G=(t,e,o,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of R(e))!F.call(t,i)&&i!==o&&u(t,i,{get:()=>e[i],enumerable:!(a=N(e,i))||a.enumerable});return t};var d=(t,e,o)=>(o=t!=null?I(_(t)):{},G(e||!t||!t.__esModule?u(o,"default",{value:t,enumerable:!0}):o,t));function w(t){return`# @stricli/auto-complete START [${t}]`}async function f(t){let{os:e=v.default,fs:o=A.default,path:a=P.default}=t;if(!t.process.env.SHELL?.includes("bash")){t.process.stderr.write(`Skipping bash as shell was not detected.
3
+ `);return}let i=e.homedir(),p=a.join(i,".bashrc"),n;try{n=(await o.promises.readFile(p)).toString().split(/\n/)}catch{t.process.stderr.write(`Expected to edit ~/.bashrc but file was not found.
4
+ `);return}return{install:async(s,m)=>{let r=w(s),l=n.indexOf(r),x=`__${s}_complete`,S=[r,`${x}() { export COMP_LINE; COMPREPLY=( $(${m} $COMP_LINE) ); return 0; }`,`complete -o default -o nospace -F ${x} ${s}`,h];if(l>=0){let M=n.indexOf(h,l);n.splice(l,M-l+1,...S)}else n.push(...S);await o.promises.writeFile(p,n.join(`
5
+ `)),t.process.stdout.write("Restart bash shell or run `source ~/.bashrc` to load changes.\n")},uninstall:async s=>{let m=w(s),r=n.indexOf(m);if(r>=0){let l=n.indexOf(h,r);n.splice(r,l-r+1)}await o.promises.writeFile(p,n.join(`
6
+ `)),t.process.stdout.write("Restart bash shell or run `source ~/.bashrc` to load changes.\n")}}}var v,A,P,h,O=j(()=>{"use strict";v=d(require("os"),1),A=d(require("fs"),1),P=d(require("path"),1);h="# @stricli/auto-complete END"});var b={};B(b,{install:()=>J,uninstall:()=>U});async function J(t,e){t.bash&&await(await f(this))?.install(e,t.bash)}async function U(t,e){t.bash&&await(await f(this))?.uninstall(e)}var g=j(()=>{"use strict";O()});var L=require("@stricli/core");var c=require("@stricli/core");var C=require("@stricli/core");var T={parse:String,brief:"Target command run by user",placeholder:"targetCommand"},E=(0,C.buildCommand)({loader:async()=>{let{install:t}=await Promise.resolve().then(()=>(g(),b));return t},parameters:{flags:{bash:{kind:"parsed",brief:"Command executed by bash to generate completion proposals",parse:String,optional:!0,placeholder:"command"}},positional:{kind:"tuple",parameters:[T]}},docs:{brief:"Installs autocomplete support for target command on all provided shell types"}});var $=(0,C.buildCommand)({loader:async()=>{let{uninstall:t}=await Promise.resolve().then(()=>(g(),b));return t},parameters:{flags:{bash:{kind:"boolean",brief:"Uninstall autocompletion for bash",optional:!0}},positional:{kind:"tuple",parameters:[T]}},docs:{brief:"Uninstalls autocomplete support for target command on all selected shell types"}});var y={name:"@stricli/auto-complete",version:"0.0.1",description:"Common utilities for enhancing Stricli applications with autocomplete",license:"Apache-2.0",repository:{type:"git",url:"https://github.com/bloomberg/stricli/tree/main/packages/auto-complete"},author:"Michael Molisani <mmolisani@bloomberg.net>",files:["dist"],type:"module",exports:{import:"./dist/index.js",require:"./dist/index.cjs"},types:"dist/index.d.ts",bin:"dist/bin/cli.js",scripts:{format:"prettier --config ../../.prettierrc -w .","format:check":"prettier --config ../../.prettierrc -c .",lint:"eslint src","lint:fix":"eslint src --fix",typecheck:"tsc -p tsconfig.json --noEmit",build:"tsup",prepublishOnly:"npm run build"},tsup:{entry:["src/index.ts","src/bin/cli.ts"],format:["esm","cjs"],tsconfig:"src/tsconfig.json",dts:!0,minify:!0,clean:!0},devDependencies:{"@typescript-eslint/eslint-plugin":"^8.2.0","@typescript-eslint/parser":"^8.2.0",eslint:"^8.57.0","eslint-plugin-import":"^2.26.0","eslint-plugin-prettier":"^5.0.0",prettier:"^3.0.0",tsup:"^6.7.0",typescript:"5.6.x"},dependencies:{"@stricli/core":"^0.0.1"}};var D=(0,c.buildRouteMap)({routes:{install:E,uninstall:$},aliases:{i:"install"},docs:{brief:"Manage auto-complete command installations for shells"}}),k=(0,c.buildApplication)(D,{name:y.name,versionInfo:{getCurrentVersion:async()=>y.version}});(0,L.run)(k,process.argv.slice(2),globalThis);
@@ -0,0 +1 @@
1
+ #!/usr/bin/env node
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import{a as t,c as e}from"../chunk-ADA5XTIG.js";import{run as p}from"@stricli/core";import{buildApplication as r,buildRouteMap as o}from"@stricli/core";var i={name:"@stricli/auto-complete",version:"0.0.1",description:"Common utilities for enhancing Stricli applications with autocomplete",license:"Apache-2.0",repository:{type:"git",url:"https://github.com/bloomberg/stricli/tree/main/packages/auto-complete"},author:"Michael Molisani <mmolisani@bloomberg.net>",files:["dist"],type:"module",exports:{import:"./dist/index.js",require:"./dist/index.cjs"},types:"dist/index.d.ts",bin:"dist/bin/cli.js",scripts:{format:"prettier --config ../../.prettierrc -w .","format:check":"prettier --config ../../.prettierrc -c .",lint:"eslint src","lint:fix":"eslint src --fix",typecheck:"tsc -p tsconfig.json --noEmit",build:"tsup",prepublishOnly:"npm run build"},tsup:{entry:["src/index.ts","src/bin/cli.ts"],format:["esm","cjs"],tsconfig:"src/tsconfig.json",dts:!0,minify:!0,clean:!0},devDependencies:{"@typescript-eslint/eslint-plugin":"^8.2.0","@typescript-eslint/parser":"^8.2.0",eslint:"^8.57.0","eslint-plugin-import":"^2.26.0","eslint-plugin-prettier":"^5.0.0",prettier:"^3.0.0",tsup:"^6.7.0",typescript:"5.6.x"},dependencies:{"@stricli/core":"^0.0.1"}};var l=o({routes:{install:t,uninstall:e},aliases:{i:"install"},docs:{brief:"Manage auto-complete command installations for shells"}}),s=r(l,{name:i.name,versionInfo:{getCurrentVersion:async()=>i.version}});p(s,process.argv.slice(2),globalThis);
@@ -0,0 +1 @@
1
+ import{buildCommand as r}from"@stricli/core";function l(t,e){if(t.length<=1)return t[0]??"";if(t.length===2)return t.join(` ${e.conjunction} `);let o=t.slice(0,t.length-1).join(", ");return e.serialComma&&(o+=","),[o,e.conjunction,t[t.length-1]].join(" ")}var i={parse:String,brief:"Target command run by user",placeholder:"targetCommand"},p=r({loader:async()=>{let{install:t}=await import("./impl-CQ7GTRH2.js");return t},parameters:{flags:{bash:{kind:"parsed",brief:"Command executed by bash to generate completion proposals",parse:String,optional:!0,placeholder:"command"}},positional:{kind:"tuple",parameters:[i]}},docs:{brief:"Installs autocomplete support for target command on all provided shell types"}});function u(t,e){let o=l(Object.keys(e),{conjunction:"and",serialComma:!0});return r({loader:async()=>{let{install:a}=await import("./impl-CQ7GTRH2.js");return function(){return a.call(this,e,t)}},parameters:{},docs:{brief:`Installs ${o} autocomplete support for ${t}`}})}var d=r({loader:async()=>{let{uninstall:t}=await import("./impl-CQ7GTRH2.js");return t},parameters:{flags:{bash:{kind:"boolean",brief:"Uninstall autocompletion for bash",optional:!0}},positional:{kind:"tuple",parameters:[i]}},docs:{brief:"Uninstalls autocomplete support for target command on all selected shell types"}});function C(t,e){let o=Object.entries(e).filter(([,n])=>n).map(([n])=>n),a=l(o,{conjunction:"and",serialComma:!0});return r({loader:async()=>{let{uninstall:n}=await import("./impl-CQ7GTRH2.js");return function(){return n.call(this,e,t)}},parameters:{},docs:{brief:`Uninstalls ${a} autocomplete support for ${t}`}})}export{p as a,u as b,d as c,C as d};
@@ -0,0 +1,5 @@
1
+ import b from"node:os";import x from"node:fs";import C from"node:path";function m(t){return`# @stricli/auto-complete START [${t}]`}var c="# @stricli/auto-complete END";async function p(t){let{os:i=b,fs:r=x,path:u=C}=t;if(!t.process.env.SHELL?.includes("bash")){t.process.stderr.write(`Skipping bash as shell was not detected.
2
+ `);return}let f=i.homedir(),a=u.join(f,".bashrc"),e;try{e=(await r.promises.readFile(a)).toString().split(/\n/)}catch{t.process.stderr.write(`Expected to edit ~/.bashrc but file was not found.
3
+ `);return}return{install:async(s,l)=>{let o=m(s),n=e.indexOf(o),d=`__${s}_complete`,h=[o,`${d}() { export COMP_LINE; COMPREPLY=( $(${l} $COMP_LINE) ); return 0; }`,`complete -o default -o nospace -F ${d} ${s}`,c];if(n>=0){let S=e.indexOf(c,n);e.splice(n,S-n+1,...h)}else e.push(...h);await r.promises.writeFile(a,e.join(`
4
+ `)),t.process.stdout.write("Restart bash shell or run `source ~/.bashrc` to load changes.\n")},uninstall:async s=>{let l=m(s),o=e.indexOf(l);if(o>=0){let n=e.indexOf(c,o);e.splice(o,n-o+1)}await r.promises.writeFile(a,e.join(`
5
+ `)),t.process.stdout.write("Restart bash shell or run `source ~/.bashrc` to load changes.\n")}}}async function A(t,i){t.bash&&await(await p(this))?.install(i,t.bash)}async function O(t,i){t.bash&&await(await p(this))?.uninstall(i)}export{A as install,O as uninstall};
package/dist/index.cjs ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";var N=Object.create;var d=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var M=Object.getOwnPropertyNames;var R=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var S=(t,e)=>()=>(t&&(e=t(t=0)),e);var w=(t,e)=>{for(var o in e)d(t,o,{get:e[o],enumerable:!0})},A=(t,e,o,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of M(e))!_.call(t,n)&&n!==o&&d(t,n,{get:()=>e[n],enumerable:!(i=k(e,n))||i.enumerable});return t};var f=(t,e,o)=>(o=t!=null?N(R(t)):{},A(e||!t||!t.__esModule?d(o,"default",{value:t,enumerable:!0}):o,t)),F=t=>A(d({},"__esModule",{value:!0}),t);function j(t){return`# @stricli/auto-complete START [${t}]`}async function x(t){let{os:e=P.default,fs:o=O.default,path:i=T.default}=t;if(!t.process.env.SHELL?.includes("bash")){t.process.stderr.write(`Skipping bash as shell was not detected.
2
+ `);return}let n=e.homedir(),u=i.join(n,".bashrc"),r;try{r=(await o.promises.readFile(u)).toString().split(/\n/)}catch{t.process.stderr.write(`Expected to edit ~/.bashrc but file was not found.
3
+ `);return}return{install:async(s,h)=>{let a=j(s),l=r.indexOf(a),y=`__${s}_complete`,g=[a,`${y}() { export COMP_LINE; COMPREPLY=( $(${h} $COMP_LINE) ); return 0; }`,`complete -o default -o nospace -F ${y} ${s}`,b];if(l>=0){let I=r.indexOf(b,l);r.splice(l,I-l+1,...g)}else r.push(...g);await o.promises.writeFile(u,r.join(`
4
+ `)),t.process.stdout.write("Restart bash shell or run `source ~/.bashrc` to load changes.\n")},uninstall:async s=>{let h=j(s),a=r.indexOf(h);if(a>=0){let l=r.indexOf(b,a);r.splice(a,l-a+1)}await o.promises.writeFile(u,r.join(`
5
+ `)),t.process.stdout.write("Restart bash shell or run `source ~/.bashrc` to load changes.\n")}}}var P,O,T,b,v=S(()=>{"use strict";P=f(require("os"),1),O=f(require("fs"),1),T=f(require("path"),1);b="# @stricli/auto-complete END"});var c={};w(c,{install:()=>B,uninstall:()=>U});async function B(t,e){t.bash&&await(await x(this))?.install(e,t.bash)}async function U(t,e){t.bash&&await(await x(this))?.uninstall(e)}var m=S(()=>{"use strict";v()});var G={};w(G,{buildInstallCommand:()=>E,buildUninstallCommand:()=>L});module.exports=F(G);var p=require("@stricli/core");function C(t,e){if(t.length<=1)return t[0]??"";if(t.length===2)return t.join(` ${e.conjunction} `);let o=t.slice(0,t.length-1).join(", ");return e.serialComma&&(o+=","),[o,e.conjunction,t[t.length-1]].join(" ")}var $={parse:String,brief:"Target command run by user",placeholder:"targetCommand"},K=(0,p.buildCommand)({loader:async()=>{let{install:t}=await Promise.resolve().then(()=>(m(),c));return t},parameters:{flags:{bash:{kind:"parsed",brief:"Command executed by bash to generate completion proposals",parse:String,optional:!0,placeholder:"command"}},positional:{kind:"tuple",parameters:[$]}},docs:{brief:"Installs autocomplete support for target command on all provided shell types"}});function E(t,e){let o=C(Object.keys(e),{conjunction:"and",serialComma:!0});return(0,p.buildCommand)({loader:async()=>{let{install:i}=await Promise.resolve().then(()=>(m(),c));return function(){return i.call(this,e,t)}},parameters:{},docs:{brief:`Installs ${o} autocomplete support for ${t}`}})}var Y=(0,p.buildCommand)({loader:async()=>{let{uninstall:t}=await Promise.resolve().then(()=>(m(),c));return t},parameters:{flags:{bash:{kind:"boolean",brief:"Uninstall autocompletion for bash",optional:!0}},positional:{kind:"tuple",parameters:[$]}},docs:{brief:"Uninstalls autocomplete support for target command on all selected shell types"}});function L(t,e){let o=Object.entries(e).filter(([,n])=>n).map(([n])=>n),i=C(o,{conjunction:"and",serialComma:!0});return(0,p.buildCommand)({loader:async()=>{let{uninstall:n}=await Promise.resolve().then(()=>(m(),c));return function(){return n.call(this,e,t)}},parameters:{},docs:{brief:`Uninstalls ${i} autocomplete support for ${t}`}})}0&&(module.exports={buildInstallCommand,buildUninstallCommand});
@@ -0,0 +1,22 @@
1
+ import { CommandContext, Command } from '@stricli/core';
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+ import * as os from 'os';
5
+
6
+ interface StricliAutoCompleteContext extends CommandContext {
7
+ readonly process: Pick<NodeJS.Process, "stderr" | "stdout" | "env">;
8
+ readonly os?: Pick<typeof os, "homedir">;
9
+ readonly fs?: {
10
+ readonly promises: Pick<typeof fs.promises, "readFile" | "writeFile">;
11
+ };
12
+ readonly path?: Pick<typeof path, "join">;
13
+ }
14
+
15
+ type Shell = "bash";
16
+ type ShellAutoCompleteCommands = Readonly<Partial<Record<Shell, string>>>;
17
+ type ActiveShells = Readonly<Partial<Record<Shell, boolean>>>;
18
+
19
+ declare function buildInstallCommand<CONTEXT extends StricliAutoCompleteContext>(targetCommand: string, commands: ShellAutoCompleteCommands): Command<CONTEXT>;
20
+ declare function buildUninstallCommand<CONTEXT extends StricliAutoCompleteContext>(targetCommand: string, shells: ActiveShells): Command<CONTEXT>;
21
+
22
+ export { StricliAutoCompleteContext, buildInstallCommand, buildUninstallCommand };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ import{b as t,d as o}from"./chunk-ADA5XTIG.js";export{t as buildInstallCommand,o as buildUninstallCommand};
package/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@stricli/auto-complete",
3
+ "version": "0.0.1",
4
+ "description": "Common utilities for enhancing Stricli applications with autocomplete",
5
+ "license": "Apache-2.0",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/bloomberg/stricli/tree/main/packages/auto-complete"
9
+ },
10
+ "author": "Michael Molisani <mmolisani@bloomberg.net>",
11
+ "files": [
12
+ "dist"
13
+ ],
14
+ "type": "module",
15
+ "exports": {
16
+ "import": "./dist/index.js",
17
+ "require": "./dist/index.cjs"
18
+ },
19
+ "types": "dist/index.d.ts",
20
+ "bin": "dist/bin/cli.js",
21
+ "scripts": {
22
+ "format": "prettier --config ../../.prettierrc -w .",
23
+ "format:check": "prettier --config ../../.prettierrc -c .",
24
+ "lint": "eslint src",
25
+ "lint:fix": "eslint src --fix",
26
+ "typecheck": "tsc -p tsconfig.json --noEmit",
27
+ "build": "tsup",
28
+ "prepublishOnly": "npm run build"
29
+ },
30
+ "tsup": {
31
+ "entry": [
32
+ "src/index.ts",
33
+ "src/bin/cli.ts"
34
+ ],
35
+ "format": [
36
+ "esm",
37
+ "cjs"
38
+ ],
39
+ "tsconfig": "src/tsconfig.json",
40
+ "dts": true,
41
+ "minify": true,
42
+ "clean": true
43
+ },
44
+ "devDependencies": {
45
+ "@typescript-eslint/eslint-plugin": "^8.2.0",
46
+ "@typescript-eslint/parser": "^8.2.0",
47
+ "eslint": "^8.57.0",
48
+ "eslint-plugin-import": "^2.26.0",
49
+ "eslint-plugin-prettier": "^5.0.0",
50
+ "prettier": "^3.0.0",
51
+ "tsup": "^6.7.0",
52
+ "typescript": "5.6.x"
53
+ },
54
+ "dependencies": {
55
+ "@stricli/core": "^0.0.1"
56
+ }
57
+ }