add confirm dialog

This commit is contained in:
cupcakearmy 2020-05-11 18:14:32 +02:00
parent fca1685ffc
commit db92c675b1
No known key found for this signature in database
GPG Key ID: D28129AE5654D9D9

View File

@ -19,8 +19,8 @@ function getListOfLeaves() {
return list.trim().split('\n') return list.trim().split('\n')
} }
function getLoosers(keepers) { function getLoosers(keepers, leaves = getListOfLeaves()) {
return getListOfLeaves().filter((leave) => !keepers.includes(leave)) return leaves.filter((leave) => !keepers.includes(leave))
} }
async function main() { async function main() {
@ -29,28 +29,46 @@ async function main() {
return return
} }
let leaves
let loosers
leaves = getListOfLeaves()
const { keepers } = await inquirer.prompt([ const { keepers } = await inquirer.prompt([
{ {
type: 'checkbox', type: 'checkbox',
message: 'Uncheck all unwanted packages', message: 'Select packages to keep (all by default)',
name: 'keepers', name: 'keepers',
choices: getListOfLeaves().map((leave) => ({ choices: leaves.map((leave) => ({
name: leave, name: leave,
checked: true, checked: true,
})), })),
}, },
]) ])
console.log('🗑 Uninstalling:', chalk.bold.blue(getLoosers(keepers).join(' '))) loosers = getLoosers(keepers, leaves)
while (true) { const { confirmed } = await inquirer.prompt([
const loosers = getLoosers(keepers) {
if (!loosers.length) break type: 'confirm',
name: 'confirmed',
message: `Delelte: ${chalk.bold.blue(loosers.join(' '))}`,
},
])
if (!confirmed) {
console.log(chalk.bold.red('Aborted'))
return
}
console.log('🗑 Uninstalling')
while (loosers.length) {
const joinedLoosers = loosers.join(' ') const joinedLoosers = loosers.join(' ')
cp.execSync(`brew uninstall ${joinedLoosers}`) cp.execSync(`brew uninstall ${joinedLoosers}`)
loosers = getLoosers(keepers)
} }
console.log('🧽 Cleaning up') console.log('🧽 Cleaning up')
cp.execSync(`brew cleanup`) cp.execSync(`brew cleanup`)
console.log(chalk.bold.green('🚀 Done')) console.log(chalk.bold.green('🚀 Done'))
} }
main() main()