DeveloperBreeze

Javascript Programming Tutorials, Guides & Best Practices

Explore 93+ expertly crafted javascript tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Crafting Beautiful CLI Tools with Node.js: Make Command-Line Interfaces Fun

Tutorial August 20, 2024
javascript nodejs

const inquirer = require('inquirer');

yargs.command({
    command: 'create',
    describe: 'Create a new file',
    handler() {
        inquirer.prompt([
            {
                type: 'input',
                name: 'filename',
                message: 'Enter the file name:'
            },
            {
                type: 'list',
                name: 'extension',
                message: 'Choose a file extension:',
                choices: ['.js', '.txt', '.md']
            }
        ]).then(answers => {
            console.log(chalk.blue(`Creating file: ${answers.filename}${answers.extension}`));
            // Add your file creation logic here
        });
    }
});

yargs.parse();

This code adds a create command that prompts the user to enter a filename and select a file extension. The results are then displayed with a styled message.