| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A template for quickly bootstrapping a Command Line Interface (CLI) project in JavaScript.
Are repetitive tasks and inconsistent command-line interfaces stealing your peace of mind? Do you yearn for a development workflow that feels intuitive, efficient, and genuinely enjoyable? The cli-pattern is your pathway to clarity and calm, empowering you to reclaim control and find your development zen.
Ready to unlock your full potential? With cli-pattern, you'll experience a profound impact on your development process, leading to:
cli-pattern offers a robust set of features to empower your CLI development:
This section outlines the directory and file structure of the project.
/ ├── bin # Folder: Contains executable scripts. │ └── cli.js # Executable: Main CLI entry point script. ├── config # Folder: Contains configuration files. │ └── default.config.js # Configuration: Default configuration settings. ├── src # Folder: Contains source code files. │ ├── commands # Folder: Contains definitions for CLI commands. │ │ ├── example # Folder: Example CLI command implementation. │ │ │ ├── action.js # Source Code: Action logic for the example command. │ │ │ └── index.js # Source Code: Definition and setup for the example command. │ │ ├── quickly # Folder: Quickly CLI command implementation. │ │ │ ├── action.js # Source Code: Action logic for the quickly command. │ │ │ └── index.js # Source Code: Definition and setup for the quickly command. │ │ └── sample # Folder: Sample CLI command implementation. │ │ ├── action.js # Source Code: Action logic for the sample command. │ │ └── index.js # Source Code: Definition and setup for the sample command. │ ├── utils # Folder: Contains utility functions. │ │ ├── loadCommands.js # Source Code: Utility for loading CLI commands. │ │ └── logger.js # Source Code: Utility for logging messages. │ └── index.js # Source Code: Main entry point for the application source. ├── .gitignore # Configuration: Specifies intentionally untracked files to ignore. ├── .npmcheckrc.json ├── .prettierignore # Configuration: Specifies files to be ignored by Prettier. ├── .prettierrc.json # Configuration: Defines Prettier formatting rules. ├── CHANGELOG.md ├── CLI_API.md # Documentation: Provides API reference for the CLI. ├── CONTRIBUTING.md # Documentation: Guidelines for contributing to the project. ├── LICENSE # Legal: Project license information. ├── md.config.js # Configuration: Configuration for markdown processing. ├── package-lock.json # Dependency Management: Records the exact dependency tree. ├── package.json # Configuration: Project metadata and dependency definitions. ├── README.md # Documentation: Project overview and instructions. ├── RULES_OF_CONDUCT.md # Documentation: Defines rules of conduct for the project community. └── SCRIPTS.md
This section guides you on how to leverage cli-pattern to create new commands and options, and highlights the powerful features available out-of-the-box.
To create a new command, follow these simple steps:
Create a new directory under src/commands. The directory name will be your command name. For instance, to create a mycommand command, create src/commands/mycommand/.
Inside your new command directory, create two files:
Here's an example based on the example command:
src/commands/mycommand/index.js
const action = require('./action');
module.exports = (program, mergedConfig) => {
program
.command('mycommand')
.description('A brief description of what mycommand does.')
.argument('<requiredArg>', 'A required argument for mycommand.')
.option(
'-o, --optional-option <value>',
'An optional option for mycommand.',
'defaultValue'
)
.action(async (requiredArg, options, command) => {
const commandConfig = mergedConfig.mycommand || {};
const finalOptions = {
...mergedConfig,
...commandConfig,
...command.opts(),
...options,
requiredArg,
};
await action(finalOptions, command.logger);
});
};src/commands/mycommand/action.js
module.exports = async (options, logger) => {
logger.info('mycommand action executed!');
logger.debug('Received options for mycommand:', options);
// Your command's core logic goes here.
// You can access arguments and options via the 'options' object.
};Your new command is automatically loaded! Once these files are in place, cli-pattern automatically discovers and registers your mycommand. You can then run it from your terminal:
./bin/cli.js mycommand <value_for_requiredArg> --optional-option <value>cli-pattern leverages commander.js for defining command-line interfaces. You can define arguments and options directly in your command's index.js file:
Refer to the commander.js documentation for advanced argument and option parsing.
When you create commands with cli-pattern, you automatically benefit from:
This project utilizes a variety of npm scripts to automate tasks such as testing, linting, and building. A comprehensive list and description of these scripts can be found in the CLI Scripts Documentation.
For detailed information on available commands, arguments, and options, please refer to the CLI API Documentation.
Contributions are welcome! Please read our contributing guidelines to get started.
This project is licensed under the MIT License. See the LICENSE file for details.
| Back | FazBrowse Home | New Git URL |