Skip to content

Commit

Permalink
add install command to starship cli, add command specific questions a…
Browse files Browse the repository at this point in the history
…nd prompts
  • Loading branch information
Anmol1696 committed May 22, 2024
1 parent 60aeb14 commit 17d5dd7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
25 changes: 22 additions & 3 deletions clients/js/packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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];
Expand All @@ -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);
Expand Down
11 changes: 4 additions & 7 deletions clients/js/packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,14 @@ export const usageText =`
Usage: starship <command> [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.
Expand Down
9 changes: 8 additions & 1 deletion clients/js/packages/client/src/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -45,7 +52,7 @@ export class StarshipInstaller {
}

private async runInstallation(command: string) {
shell.exec(command);
shell.exec(command);
}
}

Expand Down

0 comments on commit 17d5dd7

Please sign in to comment.