mirror of
https://github.com/expo/plugin-autocomplete.git
synced 2026-11-15 09:08:08 -10:00
feat: install on windows bash (#34)
This commit is contained in:
1 parent
448d97f91d
commit
4ca20e5f84
3 files changed
+38
-7
No files matched your search
+15
-1
@@ -12,8 +12,18 @@ export abstract class AutocompleteBase extends Command {
|
||||
return this.config.bin.toUpperCase().replace('-', '_')
|
||||
}
|
||||
|
||||
public determineShell(shell: string) {
|
||||
if (!shell) {
|
||||
this.error('Missing required argument shell')
|
||||
} else if (this.isBashOnWindows(shell)) {
|
||||
return 'bash'
|
||||
} else {
|
||||
return shell
|
||||
}
|
||||
}
|
||||
|
||||
public errorIfWindows() {
|
||||
if (this.config.windows) {
|
||||
if (this.config.windows && !this.isBashOnWindows(this.config.shell)) {
|
||||
throw new Error('Autocomplete is not currently supported in Windows')
|
||||
}
|
||||
}
|
||||
@@ -41,4 +51,8 @@ export abstract class AutocompleteBase extends Command {
|
||||
const fd = fs.openSync(this.acLogfilePath, 'a')
|
||||
fs.write(fd, entry)
|
||||
}
|
||||
|
||||
private isBashOnWindows(shell: string) {
|
||||
return shell.endsWith('\\bash.exe')
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ export default class Index extends AutocompleteBase {
|
||||
|
||||
async run() {
|
||||
const {args, flags} = this.parse(Index)
|
||||
const shell = args.shell || this.config.shell
|
||||
const shell = args.shell || this.determineShell(this.config.shell)
|
||||
this.errorIfNotSupportedShell(shell)
|
||||
|
||||
cli.action.start(`${chalk.bold('Building the autocomplete cache')}`)
|
||||
|
||||
+22
-5
@@ -19,16 +19,33 @@ const config = new Config({root})
|
||||
const cmd = new AutocompleteTest([], config)
|
||||
|
||||
runtest('AutocompleteBase', () => {
|
||||
before(async () => {
|
||||
beforeEach(async () => {
|
||||
await config.load()
|
||||
})
|
||||
|
||||
it('#convertWindowsBash', async () => {
|
||||
expect(cmd.determineShell('bash')).to.eq('bash')
|
||||
expect(cmd.determineShell('zsh')).to.eq('zsh')
|
||||
expect(cmd.determineShell('fish')).to.eq('fish')
|
||||
expect(cmd.determineShell('C:\\Users\\someone\\bin\\bash.exe')).to.eq('bash')
|
||||
expect(() => {
|
||||
cmd.determineShell('')
|
||||
}).to.throw()
|
||||
})
|
||||
|
||||
it('#errorIfWindows', async () => {
|
||||
try {
|
||||
cmd.config.windows = true
|
||||
expect(() => {
|
||||
cmd.errorIfWindows()
|
||||
} catch (error) {
|
||||
expect(error.message).to.eq('Autocomplete is not currently supported in Windows')
|
||||
}
|
||||
}).to.throw('Autocomplete is not currently supported in Windows')
|
||||
})
|
||||
|
||||
it('#errorIfWindows no error with bash on windows', async () => {
|
||||
cmd.config.windows = true
|
||||
cmd.config.shell = 'C:\\bin\\bash.exe'
|
||||
expect(() => {
|
||||
cmd.errorIfWindows()
|
||||
}).to.not.throw('Autocomplete is not currently supported in Windows')
|
||||
})
|
||||
|
||||
it('#errorIfNotSupportedShell', async () => {
|
||||
|
||||
Reference in new issue
Block a user