Getting Started
Installation
sh
npm install cli-kissYour first CLI
Example minimal "greet" CLI with:
- a required
namepositional argument - optional
--loudboolean flag
ts
import {
command,
operation,
optionFlag,
positionalRequired,
runAndExit,
type,
} from "cli-kiss";
const greetCommand = command(
{ description: "Greet someone" },
operation(
{
options: {
loud: optionFlag({ long: "loud", description: "Print in uppercase" }),
},
positionals: [
positionalRequired({
type: type("name"),
description: "The name of the person to greet",
}),
],
},
async (_context, { options: { loud }, positionals: [name] }) => {
const message = `Hello, ${name}!`;
console.log(loud ? message.toUpperCase() : message);
},
),
);
await runAndExit("greet", process.argv.slice(2), {}, greetCommand, {
buildVersion: "1.0.0",
});Run it:
sh
greet Alicetext
Hello, Alice!Pass a flag:
sh
greet --loud Alicetext
HELLO, ALICE!Help and color (built-in):
sh
greet --help --colortext
Usage: greet <name>
Greet someone
Positionals:
<name> The name of the person to greet
Options:
--loud[=no] Print in uppercaseVersion (built-in):
sh
greet --versiontext
greet 1.0.0Project structure
A typical cli-kiss project looks like this:
text
my-cli/
├── src/
│ ├── index.ts ← entry point: calls runAndExit
│ └── commands/
│ ├── deploy.ts ← command(...) definitions
│ └── rollback.ts
└── package.jsonEach command lives in its own file and is composed together in the entry point. See the Commands guide to learn how.
