From 17d5dd756e97fe7cb0340081356304589c7089c1 Mon Sep 17 00:00:00 2001 From: Anmol1696 Date: Wed, 22 May 2024 15:51:05 +0400 Subject: [PATCH] add install command to starship cli, add command specific questions and prompts --- clients/js/packages/cli/src/index.ts | 25 ++++++++++++++++++--- clients/js/packages/cli/src/utils.ts | 11 ++++----- clients/js/packages/client/src/installer.ts | 9 +++++++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/clients/js/packages/cli/src/index.ts b/clients/js/packages/cli/src/index.ts index 5e646c45..7c51f2a5 100755 --- a/clients/js/packages/cli/src/index.ts +++ b/clients/js/packages/cli/src/index.ts @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { StarshipClient } from '@starship-ci/client'; // Adjust the import path as necessary +import { StarshipClient, StarshipInstaller } from '@starship-ci/client'; // Adjust the import path as necessary import { Inquirerer, type Question } from 'inquirerer'; import minimist from 'minimist'; @@ -26,6 +26,16 @@ const prompter = new Inquirerer({ const questions: Question[] = params.map(name => ({ name, type: 'text' })); +// Filter questions based on the command +function getQuestionsForCommand(command: string): Question[] { + const commonQuestions = questions.filter(q => q.name !== 'helmFile'); + if (['start', 'deploy', 'start-ports', 'wait-for-pods'].includes(command)) { + return questions; // Include all questions, including helmFile + } else { + return commonQuestions; // Exclude helmFile + } +} + // Main function to run the application async function main() { const command: string = argv._[0]; @@ -39,15 +49,24 @@ async function main() { // Load configuration and prompt for missing parameters const config = loadConfig(argv); - const args = await prompter.prompt({ ...config.context }, questions, { + const commandQuestions = getQuestionsForCommand(command); + const args = await prompter.prompt({ ...config.context }, commandQuestions, { usageText }); - + const client = new StarshipClient(args); client.setConfig(config.starship); + const installer = new StarshipInstaller(); + // Execute command based on input switch (command) { + case 'install': + installer.checkAndInstallDependencies().catch((err: any) => { + console.error('An error occurred during start:', err); + process.exit(1); + }); + break; case 'start': client.start().catch((err: any) => { console.error('An error occurred during start:', err); diff --git a/clients/js/packages/cli/src/utils.ts b/clients/js/packages/cli/src/utils.ts index 68ba5286..b93f3a40 100644 --- a/clients/js/packages/cli/src/utils.ts +++ b/clients/js/packages/cli/src/utils.ts @@ -76,17 +76,14 @@ export const usageText =` Usage: starship [options] Commands: + start Start the Starship services. + stop Remove all components related to the deployment. deploy Deploy starship using specified options or configuration file. setup Setup initial configuration and dependencies. start-ports Start port forwarding for the deployed services. stop-ports Stop port forwarding. - teardown Remove all components related to the deployment. - upgrade Upgrade the deployed application to a new version. - undeploy Remove starship deployment using specified options or configuration file. - delete-helm Delete a specific Helm release. - remove-helm Remove Helm chart from local configuration. - clean-kind Clean up Kubernetes kind cluster resources. - setup-kind Setup a Kubernetes kind cluster for development. + delete Delete a specific Helm release. + get-pods Get the list of pods for the Helm release. clean Perform a clean operation to tidy up resources. version, -v Display the version of the Starship Client. diff --git a/clients/js/packages/client/src/installer.ts b/clients/js/packages/client/src/installer.ts index 11c1bcfd..93868651 100644 --- a/clients/js/packages/client/src/installer.ts +++ b/clients/js/packages/client/src/installer.ts @@ -34,6 +34,13 @@ export class StarshipInstaller { } } + async checkAndInstallDependencies() { + for (const dependency of Object.keys(this.installations)) { + console.log(`Checking ${dependency}...`); + await this.checkAndInstallBinary(dependency); + } + } + async installBinary(binaryName: string) { const platform = os.platform(); const installation = this.installations[binaryName]; @@ -45,7 +52,7 @@ export class StarshipInstaller { } private async runInstallation(command: string) { - shell.exec(command); + shell.exec(command); } }