mirror of
https://github.com/cupcakearmy/unbrew.git
synced 2024-12-22 16:16:26 +00:00
add confirm dialog
This commit is contained in:
parent
fca1685ffc
commit
db92c675b1
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user