#!/usr/bin/env node
import { t as UsageAnalyzer } from "./usage-analyzer-YY8x_deb.mjs";
import { t as ConsoleReporter } from "./console-reporter-DkPP8snu.mjs";
import { resolve } from "path";
import chalk from "chalk";
import { Command } from "commander";

//#region src/cli.ts
/**
* CLI entry point for angular-clean
*/
const program = new Command();
program.name("ng-clean").description("Detect unused Angular components, services, pipes, modules, and directives").version("0.1.0").argument("[path]", "Path to Angular project", process.cwd()).option("-d, --detailed", "Show detailed usage information for used artifacts").option("-t, --type <type>", "Filter by artifact type (component|service|pipe|module|directive)").option("-e, --exclude <patterns...>", "Additional exclude patterns").action(async (path, options) => {
	try {
		const projectPath = resolve(path);
		console.log(chalk.bold.cyan("\n🔍 Angular Clean - Unused Code Detector\n"));
		console.log(chalk.gray(`Analyzing project at: ${projectPath}\n`));
		if (options.type) {
			const validTypes = [
				"component",
				"service",
				"pipe",
				"module",
				"directive"
			];
			if (!validTypes.includes(options.type)) {
				console.error(chalk.red(`\n❌ Invalid type: ${options.type}. Must be one of: ${validTypes.join(", ")}\n`));
				process.exit(1);
			}
		}
		const analyzeOptions = {
			path: projectPath,
			detailed: options.detailed || false,
			type: options.type,
			excludePatterns: options.exclude
		};
		const report = await new UsageAnalyzer(analyzeOptions).analyze();
		new ConsoleReporter(analyzeOptions).report(report);
		if (report.totalUnused + report.totalPossibleUnused > 0) {
			console.log(chalk.yellow(`⚠️  Found ${report.totalUnused} unused and ${report.totalPossibleUnused} possible-unused artifact(s)\n`));
			process.exit(1);
		} else {
			console.log(chalk.green("✓ No unused code found!\n"));
			process.exit(0);
		}
	} catch (error) {
		console.error(chalk.red("\n❌ Error during analysis:\n"));
		if (error instanceof Error) {
			console.error(chalk.red(error.message));
			if (process.env.DEBUG) {
				console.error(chalk.gray("\nStack trace:"));
				console.error(chalk.gray(error.stack));
			}
		} else console.error(chalk.red(String(error)));
		console.log(chalk.gray("\nTip: Set DEBUG=1 environment variable for more details\n"));
		process.exit(1);
	}
});
program.parse();

//#endregion
export {  };
//# sourceMappingURL=cli.mjs.map