Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add overwrite option to download command #785

Merged
merged 3 commits into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions bin/stencil-download.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ program
.option('-f, --file [filename]', 'specify the filename to download only')
.option('-e, --exclude [exclude]', 'specify a directory to exclude from download')
.option('-c, --channel_id [channelId]', 'specify the channel ID of the storefront', parseInt)
.option('-o, --overwrite', 'overwrite local with remote files')
.parse(process.argv);

checkNodeVersion();
Expand All @@ -25,23 +26,31 @@ const options = {
exclude: ['parsed', 'manifest.json', ...extraExclude],
apiHost: cliOptions.host,
channelId: cliOptions.channel_id,
overwrite: cliOptions.overwrite,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is just a boolean, I would prefer more specific name, like skipOverwriteQuestion or omitOverwriteAsk.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this one isn't actually saying whether to ask the question, but is the actual answer to the question: Should we overwrite? Hence why it seems correct for it to just be called overwrite

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have refactored this to simply be a boolean, rather than a "Yes" or "No" string value

applyTheme: true, // fix to be compatible with stencil-push.utils
file: cliOptions.file,
};

async function run(opts) {
const overwriteType = opts.file ? opts.file : 'files';

const answers = await inquirer.prompt([
const promptAnswers = await inquirer.prompt([
{
message: `${'Warning'.yellow} -- overwrite local with remote ${overwriteType}?`,
name: 'overwrite',
type: 'checkbox',
choices: ['Yes', 'No'],
type: 'confirm',
when() {
return !opts.overwrite;
},
},
]);

if (!answers.overwrite.includes('Yes')) {
const answers = {
...opts,
...promptAnswers,
};

if (!answers.overwrite) {
console.log(`Request cancelled by user ${'No'.red}`);
return;
}
Expand Down