hackages
Version:
CLI tool for learning software development concepts through test-driven development
81 lines (80 loc) • 2.67 kB
JavaScript
import { Command } from "commander";
import dotenv from "dotenv";
import { generateContent, generateLearningGoal } from "./commands/generate.js";
import { testCommand } from "./commands/test.js";
import { reviewCommand } from "./commands/review.js";
import { interactiveCommand } from "./commands/interactive.js";
import { loginCommand, logoutCommand } from "./commands/login.js";
import { onboardingCommand } from "./commands/onboarding.js";
import { checkIfLearningJSONIsEmpty, getCurrentUser } from "./services/auth.js";
// Load environment variables
dotenv.config();
const program = new Command();
const currentUser = getCurrentUser();
const userStatus = currentUser
? `\nLogged in as: ${currentUser.name || currentUser.login}`
: "";
program
.name("hackages")
.description("🎯 Learn software development concepts through test-driven development\n" +
"Run 'hackages' to start your learning journey!" +
userStatus)
.version("0.2.7");
// Test command - runs the tests for current exercise
program
.command("test")
.description("Run tests for the current exercise")
.action(async () => {
await testCommand();
});
// Review command - gets AI feedback on implementation
program
.command("review")
.description("Get AI-powered code review and feedback")
.action(async () => {
await reviewCommand();
});
// Continue command - interactive mode for existing exercises
program
.command("continue")
.description("Continue working on existing exercise (interactive mode)")
.action(async () => {
await interactiveCommand();
});
// Login command - authenticate with GitHub
program
.command("login")
.description("Login with your GitHub account")
.action(async () => {
await loginCommand();
});
// Logout command - clear authentication
program
.command("logout")
.description("Logout from your account")
.action(async () => {
await logoutCommand();
});
// Default behavior - start learning journey
program.action(async () => {
// check if there is a learning.json file in the .hackages directory at HOME directory
if (checkIfLearningJSONIsEmpty()) {
await onboardingCommand();
}
else {
// Existing user - use full flow with authentication
const learningGoals = await generateLearningGoal();
if (!learningGoals) {
return; // Exit if no learning goals were collected
}
await generateContent(learningGoals);
}
});
// Handle legacy --continue flag for backward compatibility
if (process.argv.includes("--continue")) {
interactiveCommand();
}
else {
program.parse();
}