Skip to content

Commit

Permalink
Revised msgs for protection status
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Jun 18, 2024
1 parent 93973a2 commit 7b7f80d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
12 changes: 6 additions & 6 deletions src/cli/device-protection.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = ({ commandProcessor, root }) => {
const deviceProtection = commandProcessor.createCategory(root, 'device-protection', 'Commands for managing device protection');
const deviceProtection = commandProcessor.createCategory(root, 'device-protection', 'Manage device protection');

commandProcessor.createCommand(deviceProtection, 'status', 'Gets the current device protection status', {
handler: () => {
Expand All @@ -15,31 +15,31 @@ module.exports = ({ commandProcessor, root }) => {
options: {
'open': {
boolean: true,
description: 'Turns a protected device an unprotected/open device'
description: 'Turns a protected device into an open device'
}
},
handler: (args) => {
const DeviceProtectionCommands = require('../cmd/device-protection');
return new DeviceProtectionCommands(args).disableProtection(args);
},
examples: {
'$0 $command': 'Turns a protected device to being protected in service mode',
'$0 $command --open': 'Turns a protected device back to an unprotected/open device'
'$0 $command': 'Puts a protected device into service mode',
'$0 $command --open': 'Turns a protected device into an open device'
}
});

commandProcessor.createCommand(deviceProtection, 'enable', 'Enables device protection', {
options: {
file: {
description: 'Provide file to use for device protection'
description: 'File to use for device protection'
}
},
handler: (args) => {
const DeviceProtectionCommands = require('../cmd/device-protection');
return new DeviceProtectionCommands().enableProtection(args);
},
examples: {
'$0 $command': 'Enables device protection'
'$0 $command': 'Turns an open device into a protected device'
}
});

Expand Down
28 changes: 16 additions & 12 deletions src/cmd/device-protection.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,21 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {
return this._withDevice(async () => {
const s = await this._getDeviceProtection();
let res;
if (!s.protected && !s.overridden) {
res = `Open (not protected)${os.EOL}${chalk.yellow('Run \'particle device-protection enable\' to protect the device')}`;
} else if (s.protected && !s.overridden) {
res = `Protected${os.EOL}${chalk.yellow('Run \'particle device-protection disable\' to put the device in service mode')}`;
} else if (s.overridden) {
res = `Protected (service mode)${os.EOL}${chalk.yellow('Run \'particle device-protection enable\' to protect the device')}`;
let helper;

if (s.overridden) {
res = 'Protected device (service mode)';
helper = `Run ${chalk.yellow('particle device-protection enable')} to take the device out of service mode`;
} else if (s.protected) {
res = 'Protected device';
helper = `Run ${chalk.yellow('particle device-protection disable')} to put the device in service mode`;
} else {
res = 'Open device';
helper = `Run ${chalk.yellow('particle device-protection enable')} to protect the device`;
}

const deviceStr = await this._getDeviceString();
this.ui.stdout.write(`Device protection for ${deviceStr} : ${res}${os.EOL}`);
this.ui.stdout.write(`${deviceStr}: ${chalk.bold.white(res)}${os.EOL}${helper}${os.EOL}`);
return s;
});
}
Expand All @@ -79,7 +85,7 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {
let s = await this._getDeviceProtection();

if (!s.protected && !s.overridden) {
this.ui.stdout.write(`Device ${deviceStr} is not protected${os.EOL}`);
this.ui.stdout.write(`${deviceStr} is not a protected device${os.EOL}`);
return;
}

Expand Down Expand Up @@ -111,13 +117,13 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {
s = await this._getDeviceProtection();

if (!open) {
this.ui.stdout.write(`Device ${deviceStr} is in service mode.${os.EOL}Device is put into service mode for a total of 20 reboots or 24 hours.${os.EOL}`);
this.ui.stdout.write(`Device ${deviceStr} is in service mode${os.EOL}Device is put into service mode for a total of 20 reboots or 24 hours${os.EOL}`);
return;
}

const localBootloaderPath = await this._downloadBootloader();
await this._flashBootloader(localBootloaderPath, 'disable');
this.ui.stdout.write(`Device ${deviceStr} is open (unprotected)${os.EOL}`);
this.ui.stdout.write(`Device ${deviceStr} is open${os.EOL}`);

const success = await this._markAsDevelopmentDevice(true);
this.ui.stdout.write(success ?
Expand Down Expand Up @@ -314,9 +320,7 @@ module.exports = class DeviceProtectionCommands extends CLICommandBase {
await this.getUsbDevice(this.device);

if (this.device.isInDfuMode) {
this.ui.stdout.write(`Device is in DFU mode. Performing a reset to get the device in normal mode. Please wait...${os.EOL}`);
await this._resetDevice(this.device);
this.ui.stdout.write(`Done! Device is now in normal mode${os.EOL}`);
await this.getUsbDevice(this.device);
}

Expand Down

0 comments on commit 7b7f80d

Please sign in to comment.