Skip to content

Commit

Permalink
Added uninstallPicoSDK command
Browse files Browse the repository at this point in the history
Signed-off-by: paulober <[email protected]>
  • Loading branch information
paulober committed Sep 6, 2024
1 parent ca4bce8 commit d915369
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@
"command": "raspberry-pi-pico.newExampleProject",
"title": "New Example Pico Project",
"category": "Raspberry Pi Pico"
},
{
"command": "raspberry-pi-pico.uninstallPicoSDK",
"title": "Uninstall Pico SDK",
"category": "Raspberry Pi Pico"
}
],
"configuration": {
Expand Down
62 changes: 62 additions & 0 deletions src/commands/uninstallPicoSDK.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { Command } from "./command.mjs";
import Logger from "../logger.mjs";
import { window } from "vscode";
import { rimraf } from "rimraf";
import { join } from "path";
import { homedir } from "os";
import { unknownErrorToString } from "../utils/errorHelper.mjs";

export default class UninstallPicoSDKCommand extends Command {
private _logger: Logger = new Logger("UninstallPicoSDKCommand");

public static readonly id = "uninstallPicoSDK";

constructor() {
super(UninstallPicoSDKCommand.id);
}

async execute(): Promise<void> {
// show modal warning that this will delete the Pico SDK and
// all its automatically installed dependencies from the system
// and ask for confirmation

const response = await window.showWarningMessage(
"Uninstalling Pico SDK - Are you sure you want to continue?",
{
modal: true,
detail:
"This will delete the Pico SDK and all its automatically installed " +
"dependencies from the system. This action cannot be undone.",
},
"Yes",
"No"
);

if (response === "Yes") {
// uninstall the Pico SDK and all its automatically installed dependencies
this._logger.info("Uninstalling Pico SDK...");

try {
// rimraf ~/.pico-sdk
await rimraf(join(homedir(), ".pico-sdk"), {
preserveRoot: false,
maxRetries: 1,
retryDelay: 1000,
});

this._logger.info("Pico SDK uninstalled successfully");
void window.showInformationMessage("Pico SDK uninstalled successfully");
} catch (error) {
this._logger.error(
"Failed to uninstall Pico SDK",
unknownErrorToString(error)
);
void window.showErrorMessage("Failed to uninstall Pico SDK");

return;
}
} else {
this._logger.debug("Pico SDK uninstallation cancelled");
}
}
}
2 changes: 2 additions & 0 deletions src/extension.mts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import VersionBundlesLoader from "./utils/versionBundles.mjs";
import { pyenvInstallPython, setupPyenv } from "./utils/pyenvUtil.mjs";
import NewExampleProjectCommand from "./commands/newExampleProject.mjs";
import SwitchBoardCommand from "./commands/switchBoard.mjs";
import UninstallPicoSDKCommand from "./commands/uninstallPicoSDK.mjs";

export async function activate(context: ExtensionContext): Promise<void> {
Logger.info(LoggerSource.extension, "Extension activation triggered");
Expand Down Expand Up @@ -111,6 +112,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
new ConfigureCmakeCommand(),
new ImportProjectCommand(context.extensionUri),
new NewExampleProjectCommand(context.extensionUri),
new UninstallPicoSDKCommand(),
];

// register all command handlers
Expand Down

0 comments on commit d915369

Please sign in to comment.