nzp-cli
v1.2.2
Published
A Node.js CLI tool
Downloads
11
Maintainers
Readme
nzp-cli
A Node.js CLI tool that can be installed and used directly from the terminal.
Installation
Global Installation
npm install -g nzp-cliLocal Installation
npm install nzp-cliUsage
Interactive Mode (Recommended)
Enter the interactive mode for a better experience:
# Start interactive mode (default)
nzp-cli
# Or explicitly start interactive mode
nzp-cli interactive
# or
nzp-cli iOnce in interactive mode, you'll see a prompt:
nzp-cli> You can then type commands directly:
nzp-cli> hello World
Hello, World!
nzp-cli> echo This is a test
This is a test
nzp-cli> calc 2 + 2
2 + 2 = 4
nzp-cli> help
Available commands:
calc Simple calculator
clear Clear the screen
echo Echo your message
exit Exit the interactive mode
help Show available commands
hello Say hello
info Show CLI information
quit Exit the interactive mode
version Show version information
nzp-cli> exit
Goodbye! 👋Command Mode
You can also use commands directly without entering interactive mode:
# Show help
nzp-cli --help
# Show version
nzp-cli --version
# Say hello
nzp-cli hello
# Say hello with a name
nzp-cli hello --name "Your Name"
# Show CLI information
nzp-cli infoDevelopment
If you want to develop this CLI tool locally:
- Clone the repository
- Install dependencies:
npm install - Link the package globally for testing:
npm link - Now you can use
nzp-clicommand anywhere
Using as a Module
You can also use nzp-cli as a Node.js module in your projects:
Installation
npm install nzp-cliUsage Examples
CommonJS
const { calc, hello, echo, getInfo } = require('nzp-cli');
// Calculator
const result = calc('2 + 2'); // Returns 4
const product = calc('10 * 5'); // Returns 50
// Hello
const greeting = hello('Alice'); // Returns "Hello, Alice!"
const defaultGreeting = hello(); // Returns "Hello, World!"
// Echo
const message = echo('Hello', 'World'); // Returns "Hello World"
// Get Info
const info = getInfo();
console.log(info);
// {
// name: 'nzp-cli',
// version: '1.2.0',
// description: 'A Node.js CLI tool',
// nodeVersion: 'v18.0.0',
// platform: 'darwin'
// }Error Handling
const { calc } = require('nzp-cli');
try {
const result = calc('2 + 2');
console.log(result); // 4
} catch (error) {
console.error('Calculation error:', error.message);
}
try {
calc('invalid expression'); // Throws error
} catch (error) {
console.error(error.message);
// "Invalid expression. Only numbers and basic operators (+, -, *, /) are allowed."
}Available Functions
calc(expression)- Calculate mathematical expressionshello(name?)- Generate greeting messageecho(...messages)- Join messages togethergetInfo()- Get CLI package information
See examples/usage-example.js for more examples.
Commands
Interactive Mode Commands
When in interactive mode, you can use:
hello [name]- Say hello (default: "World")echo <message>- Echo your messagecalc <expression>- Simple calculator (e.g.,calc 2 + 2)info- Show CLI informationversion- Show version informationhelp- Show available commandsclear- Clear the screenexitorquit- Exit interactive mode
Command Mode Commands
nzp-cli hello [options]- Say hellonzp-cli info- Show CLI informationnzp-cli interactiveornzp-cli i- Start interactive mode
Publishing
To publish this package to npm:
- Make sure you have an npm account (sign up at https://www.npmjs.com/signup)
- Login to npm:
npm login - Check if the package name is available
- Publish:
npm publish
For detailed publishing instructions, see PUBLISH.md.
License
MIT
