Gunshi is a modern javascript command-line library
[!TIP]
gunshi (θ»εΈ«) is a position in ancient Japanese samurai battle in which a samurai devised strategies and gave orders. That name is inspired by the word βcommandβ.
Gunshi is designed to simplify the creation of modern command-line interfaces:
# npm
npm install --save gunshi
## pnpm
pnpm add gunshi
## yarn
yarn add gunshi
## deno
deno add jsr:@gunshi/gunshi
## bun
bun add gunshi
# npm
npm install --save gunshi@beta
## pnpm
pnpm add gunshi@beta
## yarn
yarn add gunshi@beta
## deno (you can specify version with `@`)
deno add jsr:@gunshi/gunshi@0.27.2
## bun
bun add gunshi@beta
import { cli } from 'gunshi'
// define a command with declarative configuration, using commandable object
const command = {
name: 'greet',
description: 'A greeting command',
args: {
name: {
type: 'string',
short: 'n',
description: 'Name to greet'
},
greeting: {
type: 'string',
short: 'g',
default: 'Hello',
description: 'Greeting to use (default: "Hello")'
},
times: {
type: 'number',
short: 't',
default: 1,
description: 'Number of times to repeat the greeting (default: 1)'
}
},
run: ctx => {
const { name = 'World', greeting, times } = ctx.values
for (let i = 0; i < times; i++) {
console.log(`${greeting}, ${name}!`)
}
}
}
// run a command that is defined above
// (the 3rd argument of `cli` is the command option)
await cli(process.argv.slice(2), command, {
name: 'my-app',
version: '1.0.0',
description: 'My CLI application'
})
About more details and usage, see documentations
If you are interested in contributing to gunshi, I highly recommend checking out the contributing guidelines here. Youβll find all the relevant information such as how to make a PR, how to setup development) etc., there.
This project is inspired and powered by:
citty, created by UnJS team and contributorsordana, createdy by sapphi-red, inspired documentation generationThank you!
The development of Gunshi is supported by my OSS sponsors!
We use cookies
We use cookies to analyze traffic and improve your experience. You can accept or reject analytics cookies.