Skip to content

Commit

Permalink
change questions, only ask about --force if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Feb 4, 2020
1 parent f5d94a5 commit bf912fe
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions src/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,31 +51,44 @@ async function main() {
{
type: 'autocomplete',
name: 'src',
message: 'Search from history',
message: 'Repo to clone?',
suggest: (input, choices) =>
choices.filter(({ value }) => fuzzysearch(input, value)),
choices
},
{
type: 'input',
name: 'dest',
message: 'Dest? (default ".")',
message: 'Destination directory?',
initial: '.'
},
{
type: 'toggle',
name: 'force',
message: 'Force overriding?'
},
{
type: 'toggle',
name: 'cache',
message: 'From cache?'
message: 'Use cached version?'
}
]);

const empty =
!fs.existsSync(options.dest) || fs.readdirSync(options.dest).length === 0;

if (!empty) {
const { force } = await prompt([
{
type: 'toggle',
name: 'force',
message: 'Overwrite existing files?'
}
]);

if (!force) {
console.error(chalk.magenta(`! Directory not empty — aborting`));
return;
}
}

run(options.src, options.dest, {
force: options.force,
force: true,
cache: options.cache
});
} else {
Expand Down

0 comments on commit bf912fe

Please sign in to comment.