team-cli
Automate all the things with a team-centric CLI. Abstract away annoying day-to-day tasks and eliminate tribal team knowledge by building your team their very own CLI.
Getting Started
Initialize Project
mkdir teamname-clicd teamname-cligit initnpm initnpm install --save team-cli
Create Bin index.js
Then in an index.js
you could write the following:
#!/usr/bin/env node const resolve = ;const cli = ; const commandsDir = ;;
Point to Bin index.js in Package
Then customize your package.json
to include a path to the bin:
"bin":
Create Commands
Then you may make a commands
directory with files like command-foo.js
:
const run = ;const resolve = ; const script = ; // also supports bash .ps1 scripts const action = async { await // Or, run any Node code you wish}; moduleexports = title: 'foo <param>' description: 'Calls foo' action
Try it out!
node ./index.js --help
Options
Any command can export the following options:
title: 'foo' // or 'foo <required_param>' or 'foo [optional_param]' {} // function with param as a string or undefined description: 'Calls foo' // optional alias: 'f' // optional option: '-f, --force' 'Forces something to happen' // optional, this will become available globally not just per-command
For Your Users
At any time a --help
or -h
may be passed to log commands to the console.
Prompts
Optionally, you may find it useful to walk users through a guided CLI experience with prompts to your users. I suggest prompts for this task, but any tool of your choice will work within an action.
Example usage with prompts:
const action = async { if !cmd let value: cmdResponse = await ; cmd = cmdResponse await ;};
Logging
The environment's log level can be changed with process.env.LOG_LEVEL
to any of winston's supported log levels including verbose
.
To customize where logs are saved, pass a second param in your index.js
's cli
call like so: