hackages
Version:
CLI tool for learning software development concepts through test-driven development
79 lines (78 loc) โข 2.75 kB
JavaScript
import chalk from "chalk";
import prompts from "prompts";
import { testCommand } from "./test.js";
import { reviewCommand } from "./review.js";
import { exerciseFilesExist, getPreviousLearningSuggestions, handleNextLearning } from "../services/file-manager.js";
import { clearScreen, printHeader, printWarning } from "../utils/console.js";
async function showMenu() {
console.log("\n" + chalk.bold.yellow("๐ฏ What would you like to do?"));
// Check for previous learning suggestions
const previousSuggestions = getPreviousLearningSuggestions();
const choices = [
{
title: "๐งช Run Tests",
description: "Validate your code implementation",
value: "test",
},
{
title: "๐ Code Review",
description: "Get AI feedback on your code",
value: "review",
},
];
// Add Next Learning option if previous feedback exists
if (previousSuggestions) {
choices.push({
title: "๐ Next Learning",
description: "Continue with recommended learning steps",
value: "next-learning",
});
}
choices.push({
title: "๐ Exit",
description: "End your learning session",
value: "exit",
});
const response = await prompts({
type: "select",
name: "action",
message: "Choose an action:",
choices,
initial: 0,
});
// Handle Ctrl+C (user cancellation)
if (!response.action) {
console.log(chalk.bold.green("\n๐ Happy learning! See you next time!"));
return;
}
switch (response.action) {
case "test":
await testCommand();
await showMenu(); // Show menu again after running tests
break;
case "review":
await reviewCommand();
await showMenu(); // Show menu again after code review
break;
case "next-learning":
if (previousSuggestions) {
await handleNextLearning(previousSuggestions);
await showMenu(); // Show menu again after generating next exercise
}
break;
case "exit":
console.log(chalk.bold.green("๐ Happy learning! See you next time!"));
break;
}
}
export async function interactiveCommand() {
clearScreen();
printHeader("Hackages Lab - Continue Mode");
console.log(chalk.gray("Welcome back! Let's continue your learning journey.\n"));
// Check if files exist
if (!exerciseFilesExist()) {
printWarning("โ ๏ธ No existing exercise found. Please run 'hackages' to create a new exercise.");
return;
}
await showMenu();
}