@oclif/plugin-autocomplete
Advanced tools
Comparing version 3.0.5 to 3.0.6
@@ -8,4 +8,5 @@ import { Command } from '@oclif/core'; | ||
determineShell(shell: string): string; | ||
getSetupEnvVar(shell: string): string; | ||
writeLogFile(msg: string): void; | ||
private isBashOnWindows; | ||
} |
@@ -28,2 +28,5 @@ import { Command } from '@oclif/core'; | ||
} | ||
getSetupEnvVar(shell) { | ||
return `${this.cliBinEnvVar}_AC_${shell.toUpperCase()}_SETUP_PATH`; | ||
} | ||
writeLogFile(msg) { | ||
@@ -30,0 +33,0 @@ mkdirSync(this.config.cacheDir, { recursive: true }); |
@@ -12,2 +12,3 @@ import { AutocompleteBase } from '../../base.js'; | ||
run(): Promise<void>; | ||
private printShellInstructions; | ||
} |
@@ -6,18 +6,2 @@ import { Args, Flags, ux } from '@oclif/core'; | ||
import Create from './create.js'; | ||
const noteFromShell = (shell) => { | ||
switch (shell) { | ||
case 'zsh': { | ||
return `After sourcing, you can run \`${chalk.cyan('$ compaudit -D')}\` to ensure no permissions conflicts are present`; | ||
} | ||
case 'bash': { | ||
return 'If your terminal starts as a login shell you may need to print the init script into ~/.bash_profile or ~/.profile.'; | ||
} | ||
case 'powershell': { | ||
return `Use the \`MenuComplete\` mode to get matching completions printed below the command line:\n${chalk.cyan('Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete')}`; | ||
} | ||
default: { | ||
return ''; | ||
} | ||
} | ||
}; | ||
export default class Index extends AutocompleteBase { | ||
@@ -52,26 +36,82 @@ static args = { | ||
if (!flags['refresh-cache']) { | ||
const { bin } = this.config; | ||
const tabStr = shell === 'bash' ? '<TAB><TAB>' : '<TAB>'; | ||
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`; | ||
const note = noteFromShell(shell); | ||
this.log(` | ||
${chalk.bold(`Setup Instructions for ${bin.toUpperCase()} CLI Autocomplete ---`)} | ||
this.printShellInstructions(shell); | ||
} | ||
} | ||
printShellInstructions(shell) { | ||
const setupEnvVar = this.getSetupEnvVar(shell); | ||
const tabStr = shell === 'bash' ? '<TAB><TAB>' : '<TAB>'; | ||
const scriptCommand = `${this.config.bin} autocomplete${this.config.topicSeparator}script ${shell}`; | ||
let instructions = ` | ||
Setup Instructions for ${this.config.bin.toUpperCase()} CLI Autocomplete --- | ||
============================================== | ||
`; | ||
switch (shell) { | ||
case 'bash': { | ||
instructions += ` | ||
1) Run this command in your terminal window: | ||
1) Add the autocomplete ${shell === 'powershell' ? 'file' : 'env var'} to your ${shell} profile and source it | ||
${chalk.cyan(`printf "eval $(${scriptCommand})" >> ~/.bashrc; source ~/.bashrc`)} | ||
${chalk.cyan(instructions)} | ||
The previous command adds the ${chalk.cyan(setupEnvVar)} environment variable to your Bash config file and then sources the file. | ||
${chalk.bold('NOTE')}: ${note} | ||
${chalk.bold('NOTE')}: If you’ve configured your terminal to start as a login shell, you may need to modify the command so it updates either the ~/.bash_profile or ~/.profile file. For example: | ||
2) Test it out, e.g.: | ||
${chalk.cyan(`$ ${bin} ${tabStr}`)} # Command completion | ||
${chalk.cyan(`$ ${bin} command --${tabStr}`)} # Flag completion | ||
${chalk.cyan(`printf "eval $(${scriptCommand}) >> ~/.bash_profile; source ~/.bash_profile`)} | ||
Or: | ||
Enjoy! | ||
`); | ||
${chalk.cyan(`printf "eval $(${scriptCommand})" >> ~/.profile; source ~/.profile`)} | ||
2) Start using autocomplete: | ||
${chalk.cyan(`sf ${tabStr}`)} # Command completion | ||
${chalk.cyan(`sf command --${tabStr}`)} # Flag completion | ||
`; | ||
break; | ||
} | ||
case 'zsh': { | ||
instructions += ` | ||
1) Run this command in your terminal window: | ||
${chalk.cyan(`printf "eval $(${scriptCommand})" >> ~/.zshrc; source ~/.zshrc`)} | ||
The previous command adds the ${chalk.cyan(setupEnvVar)} environment variable to your zsh config file and then sources the file. | ||
2) (Optional) Run this command to ensure that you have no permissions conflicts: | ||
${chalk.cyan('compaudit -D')} | ||
3) Start using autocomplete: | ||
${chalk.cyan(`sf ${tabStr}`)} # Command completion | ||
${chalk.cyan(`sf command --${tabStr}`)} # Flag completion | ||
`; | ||
break; | ||
} | ||
case 'powershell': { | ||
instructions += ` | ||
1) Run these two cmdlets in your PowerShell window in the order shown: | ||
${chalk.cyan(`New-Item -Type Directory -Path (Split-Path -Parent $PROFILE) -ErrorAction SilentlyContinue | ||
Add-Content -Path $PROFILE -Value (Invoke-Expression -Command "${scriptCommand}"); .$PROFILE`)} | ||
2) (Optional) If you want matching completions printed below the command line, run this cmdlet: | ||
${chalk.cyan('Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete')} | ||
3) Start using autocomplete: | ||
${chalk.cyan(`sf ${tabStr}`)} # Command completion | ||
${chalk.cyan(`sf command --${tabStr}`)} # Flag completion | ||
`; | ||
break; | ||
} | ||
} | ||
instructions += ` | ||
Every time you enter ${tabStr}, the autocomplete feature displays a list of commands (or flags if you type --), along with their summaries. Enter a letter and then ${tabStr} again to narrow down the list until you end up with the complete command that you want to execute. | ||
Enjoy! | ||
`; | ||
this.log(instructions); | ||
} | ||
} |
@@ -17,4 +17,2 @@ import { Args } from '@oclif/core'; | ||
const shell = args.shell ?? this.config.shell; | ||
const binUpcase = this.cliBinEnvVar; | ||
const shellUpcase = shell.toUpperCase(); | ||
if (shell === 'powershell') { | ||
@@ -25,3 +23,3 @@ const completionFuncPath = path.join(this.config.cacheDir, 'autocomplete', 'functions', 'powershell', `${this.cliBin}.ps1`); | ||
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}`); | ||
this.log(`${this.prefix}${this.getSetupEnvVar(shell)}=${path.join(this.autocompleteCacheDir, `${shell}_setup`)} && test -f $${this.getSetupEnvVar(shell)} && source $${this.getSetupEnvVar(shell)};${this.suffix}`); | ||
} | ||
@@ -28,0 +26,0 @@ } |
@@ -117,3 +117,3 @@ { | ||
}, | ||
"version": "3.0.5" | ||
"version": "3.0.6" | ||
} |
{ | ||
"name": "@oclif/plugin-autocomplete", | ||
"description": "autocomplete plugin for oclif", | ||
"version": "3.0.5", | ||
"version": "3.0.6", | ||
"author": "Salesforce", | ||
@@ -14,6 +14,6 @@ "bugs": "https://github.com/oclif/plugin-autocomplete/issues", | ||
"devDependencies": { | ||
"@commitlint/config-conventional": "^18.4.4", | ||
"@commitlint/config-conventional": "^18.6.0", | ||
"@oclif/plugin-help": "^6", | ||
"@oclif/prettier-config": "^0.2.1", | ||
"@oclif/test": "^3.1.7", | ||
"@oclif/test": "^3.1.12", | ||
"@types/chai": "^4", | ||
@@ -27,6 +27,6 @@ "@types/chalk": "^2.2.0", | ||
"chai": "^4", | ||
"commitlint": "^18.4.3", | ||
"commitlint": "^18.6.0", | ||
"eslint": "^8.56.0", | ||
"eslint-config-oclif": "^5.0.0", | ||
"eslint-config-oclif-typescript": "^3.0.31", | ||
"eslint-config-oclif-typescript": "^3.0.39", | ||
"eslint-config-prettier": "^9.1.0", | ||
@@ -37,6 +37,6 @@ "globby": "^11", | ||
"mocha": "^10.2.0", | ||
"nock": "^13.4.0", | ||
"nock": "^13.5.0", | ||
"nyc": "^15.1.0", | ||
"oclif": "^4.1.0", | ||
"prettier": "^3.1.1", | ||
"oclif": "^4.4.0", | ||
"prettier": "^3.2.4", | ||
"shx": "^0.3.3", | ||
@@ -43,0 +43,0 @@ "ts-node": "^10.9.2", |
@@ -63,3 +63,3 @@ # @oclif/plugin-autocomplete | ||
_See code: [src/commands/autocomplete/index.ts](https://github.com/oclif/plugin-autocomplete/blob/v3.0.5/src/commands/autocomplete/index.ts)_ | ||
_See code: [src/commands/autocomplete/index.ts](https://github.com/oclif/plugin-autocomplete/blob/v3.0.6/src/commands/autocomplete/index.ts)_ | ||
<!-- commandsstop --> |
Sorry, the diff of this file is not supported yet
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
420645
1418