A starter template for building command-line interface (CLI) applications with Node.js and Commander.js.
- Robust CLI Foundation: Built with Commander.js for easy command definition, option parsing, and help generation.
- Graceful Error Handling: Safely handles missing
package.json
by providing informative messages and exiting cleanly. - Cross-Platform Compatibility: Designed to run seamlessly on various operating systems.
- Testable Structure: Includes Jest for unit and integration testing, ensuring reliability.
To use this CLI, first ensure you have Node.js (>=18.0.0) and npm installed.
You can install @shytiger/cli-starter
globally to use it as a command from anywhere in your terminal. Once installed, cli-starter
becomes available on your local machine.
# Using npm
npm install -g @shytiger/cli-starter
# Using yarn
yarn global add @shytiger/cli-starter
To verify the installation, you can check the version:
cli-starter --version
If you prefer to clone the repository and run it locally:
git clone https://github.com/ioncakephper/cli-starter.git
cd cli-starter
npm install
# Then you can run it using:
node bin/cli-starter.js <command>
You can also use npx
to run @shytiger/cli-starter
without installing it globally. This is convenient for one-off uses or to ensure you're always using the latest version. See the Usage section for examples.
Once installed, you can use @shytiger/cli-starter
in several ways:
cli-starter hello [name]
# Say hello to someone. If no name is provided, it defaults to "world".
# Output: Hello, world! (if no name)
# Output: Hello, Alice! (if name is Alice)
cli-starter --version
# Output: 0.1.0
cli-starter --help
# Displays help information
If you have npx
installed (comes with npm 5.2+), you can run the CLI without global installation:
npx @shytiger/cli-starter hello [name]
# Say hello to someone. If no name is provided, it defaults to "world".
# Output: Hello, world! (if no name)
# Output: Hello, Bob! (if name is Bob)
npx @shytiger/cli-starter --version
# Output: 0.1.0
npx @shytiger/cli-starter --help
# Displays help information
If you have cloned the repository and installed dependencies locally:
node bin/cli-starter.js hello [name]
# Output: Hello, world! (if no name)
# Output: Hello, Alice! (if name is Alice)
node bin/cli-starter.js --version
# Output: 0.1.0
node bin/cli-starter.js --help
# Displays help information
This section provides a detailed overview of cli-starter
commands and their available options.
These options can be used with any command.
-V, --version
: Output the current version of the CLI.- Example:
cli-starter --version
- Example:
-h, --help
: Display help information for the CLI or a specific command.- Example:
cli-starter --help
- Example (for a command):
cli-starter hello --help
- Example:
Say hello to someone. If no name is provided, it defaults to "world".
- Arguments:
[name]
(optional): The name of the person to greet.
- Options:
- (No specific options for this command yet)
- Examples:
cli-starter hello
- Output:
Hello, world!
- Output:
cli-starter hello Alice
- Output:
Hello, Alice!
- Output:
Initialize a new project.
- Arguments:
- (No specific arguments for this command)
- Options:
-q, --quick
: Quick initialization without prompts.
- Examples:
cli-starter init
- Output:
Project initialized!
- Output:
cli-starter i --quick
- Output:
Project initialized!
- Output:
We welcome contributions to @shytiger/cli-starter
! Please see our CONTRIBUTING.md for details on how to get started, including our code of conduct.
For bug reports, feature requests, or general discussions, please visit our GitHub Issues or GitHub Discussions.
This project is licensed under the MIT License - see the LICENSE file for details.