@oclif/plugin-autocomplete
Advanced tools
Comparing version 2.1.9 to 2.2.0
@@ -103,3 +103,3 @@ "use strict"; | ||
continue; | ||
f.summary = sanitizeSummary(f.summary || f.description); | ||
const flagSummary = sanitizeSummary(f.summary || f.description); | ||
let flagSpec = ''; | ||
@@ -115,3 +115,3 @@ if (f.type === 'option') { | ||
} | ||
flagSpec += `"[${f.summary}]`; | ||
flagSpec += `"[${flagSummary}]`; | ||
if (f.options) { | ||
@@ -129,3 +129,3 @@ flagSpec += `:${f.name} options:(${(_a = f.options) === null || _a === void 0 ? void 0 : _a.join(' ')})"`; | ||
} | ||
flagSpec += `--${f.name}"[${f.summary}]:`; | ||
flagSpec += `--${f.name}"[${flagSummary}]:`; | ||
if (f.options) { | ||
@@ -141,7 +141,7 @@ flagSpec += `${f.name} options:(${f.options.join(' ')})"`; | ||
// Flag.Boolean | ||
flagSpec += `"(-${f.char} --${f.name})"{-${f.char},--${f.name}}"[${f.summary}]"`; | ||
flagSpec += `"(-${f.char} --${f.name})"{-${f.char},--${f.name}}"[${flagSummary}]"`; | ||
} | ||
else { | ||
// Flag.Boolean | ||
flagSpec += `--${f.name}"[${f.summary}]"`; | ||
flagSpec += `--${f.name}"[${flagSummary}]"`; | ||
} | ||
@@ -148,0 +148,0 @@ flagSpec += ' \\\n'; |
@@ -6,4 +6,2 @@ import { Command } from '@oclif/core'; | ||
determineShell(shell: string): string; | ||
errorIfWindows(): void; | ||
errorIfNotSupportedShell(shell: string): void; | ||
get autocompleteCacheDir(): string; | ||
@@ -10,0 +8,0 @@ get acLogfilePath(): string; |
@@ -25,16 +25,2 @@ "use strict"; | ||
} | ||
errorIfWindows() { | ||
if (this.config.windows && !this.isBashOnWindows(this.config.shell)) { | ||
throw new Error('Autocomplete is not currently supported in Windows'); | ||
} | ||
} | ||
errorIfNotSupportedShell(shell) { | ||
if (!shell) { | ||
this.error('Missing required argument shell'); | ||
} | ||
this.errorIfWindows(); | ||
if (!['bash', 'zsh'].includes(shell)) { | ||
throw new Error(`${shell} is not a supported shell for autocomplete`); | ||
} | ||
} | ||
get autocompleteCacheDir() { | ||
@@ -41,0 +27,0 @@ return path.join(this.config.cacheDir, 'autocomplete'); |
@@ -11,4 +11,6 @@ import { AutocompleteBase } from '../../base'; | ||
private get zshSetupScriptPath(); | ||
private get pwshFunctionsDir(); | ||
private get bashFunctionsDir(); | ||
private get zshFunctionsDir(); | ||
private get pwshCompletionFunctionPath(); | ||
private get bashCompletionFunctionPath(); | ||
@@ -15,0 +17,0 @@ private get zshCompletionFunctionPath(); |
@@ -7,2 +7,3 @@ "use strict"; | ||
const zsh_1 = require("../../autocomplete/zsh"); | ||
const powershell_1 = require("../../autocomplete/powershell"); | ||
const bash_spaces_1 = require("../../autocomplete/bash-spaces"); | ||
@@ -23,3 +24,2 @@ const base_1 = require("../../base"); | ||
async run() { | ||
this.errorIfWindows(); | ||
// 1. ensure needed dirs | ||
@@ -37,2 +37,4 @@ await this.ensureDirs(); | ||
await fs.ensureDir(this.zshFunctionsDir); | ||
// ensure autocomplete powershell function dir | ||
await fs.ensureDir(this.pwshFunctionsDir); | ||
} | ||
@@ -51,2 +53,4 @@ async createFiles() { | ||
await fs.writeFile(this.zshCompletionFunctionPath, zshCompWithSpaces.generate()); | ||
const pwshComp = new powershell_1.default(this.config); | ||
await fs.writeFile(this.pwshCompletionFunctionPath, pwshComp.generate()); | ||
} | ||
@@ -62,2 +66,6 @@ } | ||
} | ||
get pwshFunctionsDir() { | ||
// <cachedir>/autocomplete/functions/powershell | ||
return path.join(this.autocompleteCacheDir, 'functions', 'powershell'); | ||
} | ||
get bashFunctionsDir() { | ||
@@ -71,2 +79,6 @@ // <cachedir>/autocomplete/functions/bash | ||
} | ||
get pwshCompletionFunctionPath() { | ||
// <cachedir>/autocomplete/functions/powershell/<bin>.ps1 | ||
return path.join(this.pwshFunctionsDir, `${this.cliBin}.ps1`); | ||
} | ||
get bashCompletionFunctionPath() { | ||
@@ -73,0 +85,0 @@ // <cachedir>/autocomplete/functions/bash/<bin>.bash |
@@ -11,3 +11,2 @@ "use strict"; | ||
const shell = args.shell || this.determineShell(this.config.shell); | ||
this.errorIfNotSupportedShell(shell); | ||
core_1.ux.action.start(`${chalk.bold('Building the autocomplete cache')}`); | ||
@@ -19,11 +18,26 @@ await create_1.default.run([], this.config); | ||
const tabStr = shell === 'bash' ? '<TAB><TAB>' : '<TAB>'; | ||
const note = shell === 'zsh' ? `After sourcing, you can run \`${chalk.cyan('$ compaudit -D')}\` to ensure no permissions conflicts are present` : 'If your terminal starts as a login shell you may need to print the init script into ~/.bash_profile or ~/.profile.'; | ||
const instructions = shell === 'powershell' ? | ||
`New-Item -Type Directory -Path (Split-Path -Parent $PROFILE) -ErrorAction SilentlyContinue | ||
Add-Content -Path $PROFILE -Value (Invoke-Expression -Command "${bin} autocomplete${this.config.topicSeparator}script ${shell}"); .$PROFILE` : | ||
`$ printf "eval $(${bin} autocomplete${this.config.topicSeparator}script ${shell})" >> ~/.${shell}rc; source ~/.${shell}rc`; | ||
let note = ''; | ||
switch (shell) { | ||
case 'zsh': | ||
note = `After sourcing, you can run \`${chalk.cyan('$ compaudit -D')}\` to ensure no permissions conflicts are present`; | ||
break; | ||
case 'bash': | ||
note = 'If your terminal starts as a login shell you may need to print the init script into ~/.bash_profile or ~/.profile.'; | ||
break; | ||
case 'powershell': | ||
note = `Use the \`MenuComplete\` mode to get matching completions printed below the command line:\n${chalk.cyan('Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete')}`; | ||
} | ||
this.log(` | ||
${chalk.bold(`Setup Instructions for ${bin.toUpperCase()} CLI Autocomplete ---`)} | ||
1) Add the autocomplete env var to your ${shell} profile and source it | ||
${chalk.cyan(`$ printf "eval $(${bin} autocomplete:script ${shell})" >> ~/.${shell}rc; source ~/.${shell}rc`)} | ||
1) Add the autocomplete ${shell === 'powershell' ? 'file' : 'env var'} to your ${shell} profile and source it | ||
NOTE: ${note} | ||
${chalk.cyan(instructions)} | ||
${chalk.bold('NOTE')}: ${note} | ||
2) Test it out, e.g.: | ||
@@ -41,3 +55,7 @@ ${chalk.cyan(`$ ${bin} ${tabStr}`)} # Command completion | ||
Index.args = { | ||
shell: core_1.Args.string({ description: 'shell type', required: false }), | ||
shell: core_1.Args.string({ | ||
description: 'Shell type', | ||
options: ['zsh', 'bash', 'powershell'], | ||
required: false, | ||
}), | ||
}; | ||
@@ -51,3 +69,4 @@ Index.flags = { | ||
'$ <%= config.bin %> autocomplete zsh', | ||
'$ <%= config.bin %> autocomplete powershell', | ||
'$ <%= config.bin %> autocomplete --refresh-cache', | ||
]; |
@@ -10,6 +10,11 @@ "use strict"; | ||
const shell = args.shell || this.config.shell; | ||
this.errorIfNotSupportedShell(shell); | ||
const binUpcase = this.cliBinEnvVar; | ||
const shellUpcase = shell.toUpperCase(); | ||
this.log(`${this.prefix}${binUpcase}_AC_${shellUpcase}_SETUP_PATH=${path.join(this.autocompleteCacheDir, `${shell}_setup`)} && test -f $${binUpcase}_AC_${shellUpcase}_SETUP_PATH && source $${binUpcase}_AC_${shellUpcase}_SETUP_PATH;${this.suffix}`); | ||
if (shell === 'powershell') { | ||
const completionFuncPath = path.join(this.config.cacheDir, 'autocomplete', 'functions', 'powershell', `${this.cliBin}.ps1`); | ||
this.log(`. ${completionFuncPath}`); | ||
} | ||
else { | ||
this.log(`${this.prefix}${binUpcase}_AC_${shellUpcase}_SETUP_PATH=${path.join(this.autocompleteCacheDir, `${shell}_setup`)} && test -f $${binUpcase}_AC_${shellUpcase}_SETUP_PATH && source $${binUpcase}_AC_${shellUpcase}_SETUP_PATH;${this.suffix}`); | ||
} | ||
} | ||
@@ -27,3 +32,7 @@ get prefix() { | ||
Script.args = { | ||
shell: core_1.Args.string({ description: 'shell type', required: false }), | ||
shell: core_1.Args.string({ | ||
description: 'Shell type', | ||
options: ['zsh', 'bash', 'powershell'], | ||
required: false, | ||
}), | ||
}; |
{ | ||
"version": "2.1.9", | ||
"version": "2.2.0", | ||
"commands": { | ||
@@ -28,2 +28,3 @@ "autocomplete:create": { | ||
"$ <%= config.bin %> autocomplete zsh", | ||
"$ <%= config.bin %> autocomplete powershell", | ||
"$ <%= config.bin %> autocomplete --refresh-cache" | ||
@@ -43,4 +44,9 @@ ], | ||
"name": "shell", | ||
"description": "shell type", | ||
"required": false | ||
"description": "Shell type", | ||
"required": false, | ||
"options": [ | ||
"zsh", | ||
"bash", | ||
"powershell" | ||
] | ||
} | ||
@@ -62,4 +68,9 @@ } | ||
"name": "shell", | ||
"description": "shell type", | ||
"required": false | ||
"description": "Shell type", | ||
"required": false, | ||
"options": [ | ||
"zsh", | ||
"bash", | ||
"powershell" | ||
] | ||
} | ||
@@ -66,0 +77,0 @@ } |
{ | ||
"name": "@oclif/plugin-autocomplete", | ||
"description": "autocomplete plugin for oclif", | ||
"version": "2.1.9", | ||
"version": "2.2.0", | ||
"author": "Salesforce", | ||
@@ -28,5 +28,5 @@ "bugs": "https://github.com/oclif/plugin-autocomplete/issues", | ||
"mocha": "^8.2.1", | ||
"nock": "^13.3.0", | ||
"nock": "^13.3.1", | ||
"nyc": "^15.1.0", | ||
"oclif": "^3.8.1", | ||
"oclif": "^3.9.0", | ||
"shx": "^0.3.3", | ||
@@ -33,0 +33,0 @@ "sinon": "^12.0.1", |
@@ -40,3 +40,3 @@ @oclif/plugin-autocomplete | ||
ARGUMENTS | ||
SHELL shell type | ||
SHELL (zsh|bash|powershell) Shell type | ||
@@ -56,6 +56,8 @@ FLAGS | ||
$ oclif-example autocomplete powershell | ||
$ oclif-example autocomplete --refresh-cache | ||
``` | ||
_See code: [src/commands/autocomplete/index.ts](https://github.com/oclif/plugin-autocomplete/blob/v2.1.9/src/commands/autocomplete/index.ts)_ | ||
_See code: [src/commands/autocomplete/index.ts](https://github.com/oclif/plugin-autocomplete/blob/v2.2.0/src/commands/autocomplete/index.ts)_ | ||
<!-- commandsstop --> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59643
22
1367
62