-
Notifications
You must be signed in to change notification settings - Fork 22
/
uninstall.ts
44 lines (40 loc) · 1.53 KB
/
uninstall.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {Command, flags} from '@oclif/command'
import {Plugin} from '@oclif/config'
import cli from 'cli-ux'
import Plugins from '../../plugins'
export default class PluginsUninstall extends Command {
static description = 'removes a plugin from the CLI'
static usage = 'plugins:uninstall PLUGIN...'
static help = `
Example:
$ <%- config.bin %> plugins:uninstall <%- config.pjson.oclif.examplePlugin || "myplugin" %>
`
static variableArgs = true
static args = [{name: 'plugin', description: 'plugin to uninstall'}]
static flags = {
help: flags.help({char: 'h'}),
verbose: flags.boolean({char: 'v'}),
}
static aliases = ['plugins:unlink', 'plugins:remove']
plugins = new Plugins(this.config)
async run() {
const {flags, argv} = this.parse(PluginsUninstall)
this.plugins = new Plugins(this.config)
if (flags.verbose) this.plugins.verbose = true
if (!argv.length) argv.push('.')
for (let plugin of argv) {
const friendly = this.plugins.friendlyName(plugin)
cli.action.start(`Uninstalling ${friendly}`)
const unfriendly = await this.plugins.hasPlugin(plugin)
if (!unfriendly) {
let p = this.config.plugins.find(p => p.name === plugin) as Plugin | undefined
if (p) {
if (p && p.parent) return this.error(`${friendly} is installed via plugin ${p.parent!.name}, uninstall ${p.parent!.name} instead`)
}
return this.error(`${friendly} is not installed`)
}
await this.plugins.uninstall(unfriendly.name)
cli.action.stop()
}
}
}