Claude Code के साथ CLI Tools कैसे Develop करें
Claude Code का उपयोग करके CLI tools develop करना सीखें। Practical code examples और step-by-step guidance शामिल है।
Claude Code से CLI Tool Development को तेज़ करें
जब आप अपना खुद का CLI tool बनाना चाहते हैं, तो Claude Code सबसे अच्छा partner है। Argument parsing, subcommand design, interactive I/O तक — बस “ऐसा CLI बनाना है” बताने मात्र से implementation हो जाता है।
Project का Initial Setup
> TypeScript में CLI tool का project बनाओ।
> commander से arguments parse करो, eslint और prettier भी setup करो।
> npx ts-node src/index.ts से execute हो सके ऐसा बनाओ।
Argument Parsing और Subcommands
Commander का उपयोग करके CLI की basic structure इस प्रकार है।
#!/usr/bin/env node
import { Command } from "commander";
import { version } from "../package.json";
const program = new Command();
program
.name("mytool")
.description("Project management CLI tool")
.version(version);
program
.command("init")
.description("Project को initialize करें")
.option("-t, --template <name>", "Template का नाम", "default")
.option("-d, --dir <path>", "Target directory", ".")
.action(async (options) => {
console.log(`Template "${options.template}" से initialize हो रहा है...`);
await initProject(options.template, options.dir);
console.log("पूरा हो गया!");
});
program
.command("generate <type> <name>")
.alias("g")
.description("File generate करें (component, hook, page)")
.option("--dry-run", "Actually file बनाए बिना preview करें")
.action(async (type, name, options) => {
if (options.dryRun) {
console.log(`[dry-run] ${type} "${name}" generate होगा`);
return;
}
await generateFile(type, name);
});
program
.command("check")
.description("Project की स्थिति जांचें")
.action(async () => {
await runHealthCheck();
});
program.parse();
Interactive Input
Inquirer library का उपयोग करके interactive input का implementation।
import inquirer from "inquirer";
import chalk from "chalk";
interface ProjectConfig {
name: string;
framework: string;
features: string[];
packageManager: string;
}
async function interactiveInit(): Promise<ProjectConfig> {
const answers = await inquirer.prompt([
{
type: "input",
name: "name",
message: "Project का नाम:",
validate: (input: string) =>
/^[a-z0-9-]+$/.test(input) || "केवल lowercase letters, numbers और hyphens use कर सकते हैं",
},
{
type: "list",
name: "framework",
message: "Framework:",
choices: ["React", "Next.js", "Astro", "Vue"],
},
{
type: "checkbox",
name: "features",
message: "Additional features:",
choices: [
{ name: "TypeScript", checked: true },
{ name: "ESLint", checked: true },
{ name: "Prettier", checked: true },
{ name: "Testing (Vitest)" },
{ name: "CI/CD (GitHub Actions)" },
],
},
{
type: "list",
name: "packageManager",
message: "Package manager:",
choices: ["npm", "pnpm", "yarn"],
},
]);
console.log(chalk.green("\nSettings:"));
console.log(chalk.cyan(` Project name: ${answers.name}`));
console.log(chalk.cyan(` Framework: ${answers.framework}`));
console.log(chalk.cyan(` Features: ${answers.features.join(", ")}`));
return answers;
}
Progress Bar और Spinner
Processing की progress को visually display करें।
import ora from "ora";
import cliProgress from "cli-progress";
async function processFiles(files: string[]) {
const bar = new cliProgress.SingleBar({
format: "Processing |{bar}| {percentage}% | {value}/{total} files",
barCompleteChar: "█",
barIncompleteChar: "░",
});
bar.start(files.length, 0);
for (const file of files) {
await processFile(file);
bar.increment();
}
bar.stop();
console.log(chalk.green("सभी files की processing पूरी हो गई!"));
}
async function installDependencies(packages: string[]) {
const spinner = ora("Dependencies install हो रही हैं...").start();
try {
await execAsync(`npm install ${packages.join(" ")}`);
spinner.succeed("Dependencies install पूरा हुआ");
} catch (error) {
spinner.fail("Installation fail हो गया");
throw error;
}
}
Test Implementation
CLI tool के tests भी Claude Code से करवा सकते हैं।
import { describe, it, expect } from "vitest";
import { execSync } from "child_process";
describe("mytool CLI", () => {
it("version display कर सकता है", () => {
const output = execSync("npx ts-node src/index.ts --version").toString();
expect(output.trim()).toMatch(/^\d+\.\d+\.\d+$/);
});
it("help display कर सकता है", () => {
const output = execSync("npx ts-node src/index.ts --help").toString();
expect(output).toContain("Project management CLI tool");
expect(output).toContain("init");
expect(output).toContain("generate");
});
it("non-existent command पर error देता है", () => {
expect(() => {
execSync("npx ts-node src/index.ts unknown 2>&1");
}).toThrow();
});
});
npm package के रूप में publish करने का तरीका npm package publish में देखें। Claude Code की basic usage के लिए getting started guide, और productivity बढ़ाने के tips के लिए productivity को 3 गुना करने वाले 10 Tips देखें।
Summary
Claude Code का उपयोग करके, argument parsing, interactive input, progress display, और testing सहित CLI tools को कम समय में develop किया जा सकता है। बस “ऐसा command चाहिए” natural language में बताएं, और तुरंत काम करने वाला tool तैयार हो जाता है।
विस्तार से जानने के लिए Claude Code official documentation देखें।
Related Posts
Claude Code से अपने Side Projects को Supercharge कैसे करें [Examples के साथ]
Claude Code से personal development projects को dramatically speed up करना सीखें। Real-world examples और idea से deployment तक practical workflow शामिल है।
Claude Code से Refactoring कैसे Automate करें
Claude Code से efficiently code refactoring automate करना सीखें। Real-world projects के लिए practical prompts और concrete refactoring patterns शामिल हैं।
Claude Code के साथ Complete CORS Configuration Guide
Claude Code का उपयोग करके complete CORS configuration guide सीखें। Practical tips और code examples शामिल हैं।