From ff5af0009e0deb621da053e7177499373f303201 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 28 Oct 2024 07:44:46 -0700 Subject: [PATCH 1/3] await inquirer prompts --- cli/src/commands/new/index.ts | 2 +- cli/src/commands/sdk/remove/index.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/src/commands/new/index.ts b/cli/src/commands/new/index.ts index 8a3999c6..5e83e886 100644 --- a/cli/src/commands/new/index.ts +++ b/cli/src/commands/new/index.ts @@ -217,7 +217,7 @@ export default class NewCommand extends Command { let updateSDK = false; if (!installedSdkVersion) { - const confirmed = inquirer.confirm({ + const confirmed = await inquirer.confirm({ message: `You do not have the ${sdkText} installed. Would you like to install it now?`, default: true, }); diff --git a/cli/src/commands/sdk/remove/index.ts b/cli/src/commands/sdk/remove/index.ts index 4b65e4da..a607b911 100644 --- a/cli/src/commands/sdk/remove/index.ts +++ b/cli/src/commands/sdk/remove/index.ts @@ -72,7 +72,7 @@ export default class SDKRemoveCommand extends Command { if (!flags.force) { try { - const confirmed = inquirer.confirm({ + const confirmed = await inquirer.confirm({ message: "Are you sure you want to remove all Modus SDKs?", default: false, }); @@ -108,7 +108,7 @@ export default class SDKRemoveCommand extends Command { this.exit(1); } else if (!flags.force) { try { - const confirmed = inquirer.confirm({ + const confirmed = await inquirer.confirm({ message: `Are you sure you want to remove all Modus ${sdk} SDKs?`, default: false, }); @@ -136,7 +136,7 @@ export default class SDKRemoveCommand extends Command { this.exit(1); } else if (!flags.force) { try { - const confirmed = inquirer.confirm({ + const confirmed = await inquirer.confirm({ message: `Are you sure you want to remove ${sdkText}?`, default: false, }); From 0b7256468453b4cc3957f9f388e9296b0f4b418e Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 28 Oct 2024 08:26:31 -0700 Subject: [PATCH 2/3] adjust prompt error handling --- cli/src/commands/new/index.ts | 2 + cli/src/commands/runtime/remove/index.ts | 68 ++++++------- cli/src/commands/sdk/remove/index.ts | 124 +++++++++++------------ 3 files changed, 91 insertions(+), 103 deletions(-) diff --git a/cli/src/commands/new/index.ts b/cli/src/commands/new/index.ts index 5e83e886..d9aeff5a 100644 --- a/cli/src/commands/new/index.ts +++ b/cli/src/commands/new/index.ts @@ -133,6 +133,8 @@ export default class NewCommand extends Command { } catch (err: any) { if (err.name === "ExitPromptError") { this.abort(); + } else { + throw err; } } } diff --git a/cli/src/commands/runtime/remove/index.ts b/cli/src/commands/runtime/remove/index.ts index 22bce6ba..fd910758 100644 --- a/cli/src/commands/runtime/remove/index.ts +++ b/cli/src/commands/runtime/remove/index.ts @@ -40,19 +40,19 @@ export default class RuntimeRemoveCommand extends Command { static examples = ["modus runtime remove v0.0.0", "modus runtime remove all"]; async run(): Promise { - const { args, flags } = await this.parse(RuntimeRemoveCommand); - if (!args.version) { - this.logError(`No runtime version specified. Run ${chalk.whiteBright("modus runtime remove ")}, or ${chalk.whiteBright("modus runtime remove all")}`); - return; - } + try { + const { args, flags } = await this.parse(RuntimeRemoveCommand); + if (!args.version) { + this.logError(`No runtime version specified. Run ${chalk.whiteBright("modus runtime remove ")}, or ${chalk.whiteBright("modus runtime remove all")}`); + return; + } - if (args.version.toLowerCase() === "all") { - const versions = await vi.getInstalledRuntimeVersions(); - if (versions.length === 0) { - this.log(chalk.yellow("No Modus runtimes are installed.")); - this.exit(1); - } else if (!flags.force) { - try { + if (args.version.toLowerCase() === "all") { + const versions = await vi.getInstalledRuntimeVersions(); + if (versions.length === 0) { + this.log(chalk.yellow("No Modus runtimes are installed.")); + this.exit(1); + } else if (!flags.force) { const confirmed = await inquirer.confirm({ message: "Are you sure you want to remove all Modus runtimes?", default: false, @@ -60,27 +60,21 @@ export default class RuntimeRemoveCommand extends Command { if (!confirmed) { this.abort(); } - } catch (err: any) { - if (err.name === "ExitPromptError") { - this.abort(); - } } - } - for (const version of versions) { - await this.removeRuntime(version); - } - } else if (!args.version.startsWith("v")) { - this.logError("Version must start with 'v'."); - this.exit(1); - } else { - const runtimeText = `Modus Runtime ${args.version}`; - const isInstalled = await vi.runtimeVersionIsInstalled(args.version); - if (!isInstalled) { - this.log(chalk.yellow(runtimeText + "is not installed.")); + for (const version of versions) { + await this.removeRuntime(version); + } + } else if (!args.version.startsWith("v")) { + this.logError("Version must start with 'v'."); this.exit(1); - } else if (!flags.force) { - try { + } else { + const runtimeText = `Modus Runtime ${args.version}`; + const isInstalled = await vi.runtimeVersionIsInstalled(args.version); + if (!isInstalled) { + this.log(chalk.yellow(runtimeText + "is not installed.")); + this.exit(1); + } else if (!flags.force) { const confirmed = await inquirer.confirm({ message: `Are you sure you want to remove ${runtimeText}?`, default: false, @@ -88,14 +82,16 @@ export default class RuntimeRemoveCommand extends Command { if (!confirmed) { this.abort(); } - } catch (err: any) { - if (err.name === "ExitPromptError") { - this.abort(); - } } - } - await this.removeRuntime(args.version); + await this.removeRuntime(args.version); + } + } catch (err: any) { + if (err.name === "ExitPromptError") { + this.abort(); + } else { + throw err; + } } } diff --git a/cli/src/commands/sdk/remove/index.ts b/cli/src/commands/sdk/remove/index.ts index a607b911..9b070498 100644 --- a/cli/src/commands/sdk/remove/index.ts +++ b/cli/src/commands/sdk/remove/index.ts @@ -50,28 +50,28 @@ export default class SDKRemoveCommand extends Command { static examples = ["modus sdk remove assemblyscript v0.0.0", "modus sdk remove all"]; async run(): Promise { - const { args, flags } = await this.parse(SDKRemoveCommand); - if (!args.version) { - this.logError(`No SDK specified! Run ${chalk.whiteBright("modus sdk remove [version]")}, or ${chalk.whiteBright("modus sdk remove all")}`); - return; - } + try { + const { args, flags } = await this.parse(SDKRemoveCommand); + if (!args.version) { + this.logError(`No SDK specified! Run ${chalk.whiteBright("modus sdk remove [version]")}, or ${chalk.whiteBright("modus sdk remove all")}`); + return; + } - if (args.name.toLowerCase() === "all") { - let found = false; - for (const sdk of Object.values(SDK)) { - const versions = await vi.getInstalledSdkVersions(sdk); - if (versions.length > 0) { - found = true; - break; + if (args.name.toLowerCase() === "all") { + let found = false; + for (const sdk of Object.values(SDK)) { + const versions = await vi.getInstalledSdkVersions(sdk); + if (versions.length > 0) { + found = true; + break; + } + } + if (!found) { + this.log(chalk.yellow("No Modus SDKs are installed.")); + this.exit(1); } - } - if (!found) { - this.log(chalk.yellow("No Modus SDKs are installed.")); - this.exit(1); - } - if (!flags.force) { - try { + if (!flags.force) { const confirmed = await inquirer.confirm({ message: "Are you sure you want to remove all Modus SDKs?", default: false, @@ -79,35 +79,29 @@ export default class SDKRemoveCommand extends Command { if (!confirmed) { this.abort(); } - } catch (err: any) { - if (err.name === "ExitPromptError") { - this.abort(); - } } - } - for (const sdk of Object.values(SDK)) { - const versions = await vi.getInstalledSdkVersions(sdk); - for (const version of versions) { - await this.removeSDK(sdk, version); + for (const sdk of Object.values(SDK)) { + const versions = await vi.getInstalledSdkVersions(sdk); + for (const version of versions) { + await this.removeSDK(sdk, version); + } } - } - if (flags.runtimes) { - const versions = await vi.getInstalledRuntimeVersions(); - for (const version of versions) { - await this.removeRuntime(version); + if (flags.runtimes) { + const versions = await vi.getInstalledRuntimeVersions(); + for (const version of versions) { + await this.removeRuntime(version); + } } - } - } else { - const sdk = parseSDK(args.name); - if (args.version.toLowerCase() === "all") { - const versions = await vi.getInstalledSdkVersions(sdk); - if (versions.length === 0) { - this.log(chalk.yellow(`No Modus ${sdk} SDKs are installed.`)); - this.exit(1); - } else if (!flags.force) { - try { + } else { + const sdk = parseSDK(args.name); + if (args.version.toLowerCase() === "all") { + const versions = await vi.getInstalledSdkVersions(sdk); + if (versions.length === 0) { + this.log(chalk.yellow(`No Modus ${sdk} SDKs are installed.`)); + this.exit(1); + } else if (!flags.force) { const confirmed = await inquirer.confirm({ message: `Are you sure you want to remove all Modus ${sdk} SDKs?`, default: false, @@ -115,27 +109,21 @@ export default class SDKRemoveCommand extends Command { if (!confirmed) { this.abort(); } - } catch (err: any) { - if (err.name === "ExitPromptError") { - this.abort(); - } } - } - for (const version of versions) { - await this.removeSDK(sdk, version); - } - } else if (!args.version.startsWith("v")) { - this.logError("Version must start with 'v'."); - this.exit(1); - } else { - const sdkText = `Modus ${sdk} SDK ${args.version}`; - const isInstalled = await vi.sdkVersionIsInstalled(sdk, args.version); - if (!isInstalled) { - this.log(chalk.yellow(sdkText + "is not installed.")); + for (const version of versions) { + await this.removeSDK(sdk, version); + } + } else if (!args.version.startsWith("v")) { + this.logError("Version must start with 'v'."); this.exit(1); - } else if (!flags.force) { - try { + } else { + const sdkText = `Modus ${sdk} SDK ${args.version}`; + const isInstalled = await vi.sdkVersionIsInstalled(sdk, args.version); + if (!isInstalled) { + this.log(chalk.yellow(sdkText + "is not installed.")); + this.exit(1); + } else if (!flags.force) { const confirmed = await inquirer.confirm({ message: `Are you sure you want to remove ${sdkText}?`, default: false, @@ -143,14 +131,16 @@ export default class SDKRemoveCommand extends Command { if (!confirmed) { this.abort(); } - } catch (err: any) { - if (err.name === "ExitPromptError") { - this.abort(); - } } - } - await this.removeSDK(sdk, args.version); + await this.removeSDK(sdk, args.version); + } + } + } catch (err: any) { + if (err.name === "ExitPromptError") { + this.abort(); + } else { + throw err; } } } From 1485ea3b0559824fc979f61b87729e2d518ed047 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 28 Oct 2024 09:12:08 -0700 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d9db535..c5412727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change Log -## 2024-10-25 - Version 0.13.0 +## 2024-01-28 - CLI Version 0.13.1 + +- Fix issues with interactive CLI prompts [#517](https://github.com/hypermodeinc/modus/pull/517) + +## 2024-10-25 - Version 0.13.0 (all components) _NOTE: This is the first fully open-source release, using the name "Modus" for the framework. "Hypermode" still refers to the company and the commercial hosting platform - but not the framework.