diff --git a/src/cmd/setup-tachyon.js b/src/cmd/setup-tachyon.js index a409ae565..658c8590c 100644 --- a/src/cmd/setup-tachyon.js +++ b/src/cmd/setup-tachyon.js @@ -366,39 +366,39 @@ Welcome to the Particle Tachyon setup! This interactive command: } async _getSystemPassword() { - const questions = [ - { - type: 'password', - name: 'password', - message: 'Password for the system account:', - validate: (value) => { - if (!value) { - return 'Enter a password for the root account'; - } - return true; - } - }, - { - type: 'password', - name: 'passwordConfirm', - message: 'Re-enter the password for the root account:', - validate: (value) => { - if (!value) { - return 'You need to confirm the password'; - } - return true; + let attempts = 0; + const maxAttempts = 3; + + while (attempts < maxAttempts) { + const questions = [ + { + type: 'password', + name: 'password', + message: 'Password for the system account:', + validate: (value) => value ? true : 'Enter a password for the root account' + }, + { + type: 'password', + name: 'passwordConfirm', + message: 'Re-enter the password for the root account:', + validate: (value) => value ? true : 'You need to confirm the password' } + ]; + + const res = await this.ui.prompt(questions); + + if (res.password === res.passwordConfirm) { + return res.password; + } + + attempts++; + this.ui.write(`Passwords do not match.${os.EOL}`); + + if (attempts === maxAttempts) { + throw new Error('Passwords do not match. Restart the setup process.'); } - ]; - const res = await this.ui.prompt(questions); - - //check if the passwords match - if (res.password !== res.passwordConfirm) { - throw new Error('Passwords do not match. Please try again.'); } - - return res.password; - } + } async _getWifi() { const question = [ @@ -418,31 +418,43 @@ Welcome to the Particle Tachyon setup! This interactive command: } async _getWifiCredentials() { - const questions = [ - { - type: 'input', - name: 'ssid', - message: 'Enter your WiFi SSID:' - }, - { - type: 'password', - name: 'password', - message: 'Enter your WiFi password:' - }, - { - type: 'password', - name: 'passwordConfirm', - message: 'Re-enter your WiFi password:' - }, - ]; - const res = await this.ui.prompt(questions); - - if (res.password !== res.passwordConfirm) { - throw new Error('Passwords do not match. Please try again.'); + let attempts = 0; + const maxAttempts = 3; + + while (attempts < maxAttempts) { + const questions = [ + { + type: 'input', + name: 'ssid', + message: 'Enter your WiFi SSID:' + }, + { + type: 'password', + name: 'password', + message: 'Enter your WiFi password:' + }, + { + type: 'password', + name: 'passwordConfirm', + message: 'Re-enter your WiFi password:' + } + ]; + + const res = await this.ui.prompt(questions); + + if (res.password === res.passwordConfirm) { + return { ssid: res.ssid, password: res.password }; + } + + attempts++; + this.ui.write(`WiFi passwords do not match.${os.EOL}`); + + if (attempts === maxAttempts) { + throw new Error('WiFi passwords do not match. Restart the setup process.'); + } } - - return { ssid: res.ssid, password: res.password }; } + async _getKeys() { let question = [