-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex
87 lines (79 loc) · 2.35 KB
/
index
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#! /usr/bin/env node
const inquirer = require('inquirer')
const util = require('util')
const chalk = require('chalk')
const exec = util.promisify(require('child_process').exec)
const key = 'Docker images clean tools'
inquirer
.prompt([
{
type: 'expand',
message: 'Sure to clean docker images?',
name: 'Docker images clean tools',
choices: [
{
key: 'a',
name: 'Clean all images on your disk.',
value: 'all'
},
{
key: 'r',
name: 'figure out registry',
value: 'registry'
},
{
key: 't',
name: 'figure out registry and tag',
value: 'tag'
},
{
key: 'i',
name: 'figure out image id',
value: 'id'
},
new inquirer.Separator(),
{
key: 'c',
name: 'Abort',
value: 'abort'
}
]
}
])
.then(async answer => {
const choiceVal = answer[key]
let ret
try {
if (['id', 'tag'].includes(choiceVal)) {
const answer = await inquirer.prompt([
{
type: 'input',
name: choiceVal,
message: choiceVal === 'id' ? "What's the image id ?" : "What's the registry:tag ?"
}
])
console.log(chalk.bgRed('~~~~~~~doing~~~~~~~'))
ret = await exec(`docker rmi ${answer[choiceVal]}`)
} else if (choiceVal === 'registry') {
console.log(chalk.red('attention: This operation deletes all registry that match this value, is you dont not want, use ctrl+c to exit.'))
const answer = await inquirer.prompt([
{
type: 'input',
name: choiceVal,
message: "What's the registry name ?"
}
])
console.log(chalk.bgRed('~~~~~~~doing~~~~~~~'))
ret = await exec(`docker images --format '{{.Repository}}:{{.Tag}}' | grep ${answer[choiceVal]} | xargs docker rmi`)
} else if (choiceVal === 'all') {
console.log(chalk.bgRed('~~~~~~~doing~~~~~~~'))
ret = await exec('docker rmi $(docker images -q)')
} else {
return
}
console.log(chalk.green(ret.stdout))
console.log(chalk.green('~~~~~~~work success!~~~~~~~'))
} catch (error) {
console.error(chalk.red(`exec error: ${error.message}`))
}
})