Skip to content

Commit

Permalink
If there are multiple seeds that match, the CLI will ask you which on…
Browse files Browse the repository at this point in the history
…e you want, instead of just blindly

assuming the first one.

Part of #1.
  • Loading branch information
jkomoros committed Jul 4, 2023
1 parent 763b04f commit 9522113
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion tools/garden/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import {
exit
} from 'process';

import inquirer from 'inquirer';
import { packSeedReference } from '../../src/reference.js';

const cliOptions = z.object({
seed: z.optional(seedID),
help: z.optional(z.boolean()),
Expand All @@ -39,8 +42,26 @@ const main = async (opts : CLIOptions) => {
}
const garden = await loadLocalGarden(overrides);
const seedID = opts.seed || '';
const options = garden.optionsForID(seedID);
if (options.length == 0) {
throw new Error(`Unknown seed: ${seedID}`);
}
let seedRef = options[0];
if (options.length > 1) {
const answers = await inquirer.prompt([{
name: 'question',
type: 'list',
choices: options.map(option => ({
name: packSeedReference(option),
value: option
})),
message: `There are multiple seeds with ID ${seedID}. Which one do you want to use?`,
default: options[0]
}]);
seedRef = answers.question;
}
//Select default seed
const seed = await garden.seed(seedID);
const seed = await garden.seed(seedRef);
if (!seed) {
console.error('Unknown seed "' + seedID + '"');
exit(1);
Expand Down

0 comments on commit 9522113

Please sign in to comment.