@jill64/ts-cli
> Solidly-Typed CLI Router
Installation
npm i @jill64/ts-cli
Example
import { App } from '@jill64/ts-cli'
new App(
{
args: [
['arg1', 'Argument 1'],
['arg2', 'Argument 2'],
['arg3', 'Argument 3']
],
options: {
verbose: {
alias: 'V',
description: 'Verbose output'
},
host: {
alias: 'h',
description: 'Host name',
type: 'string'
}
},
optional: [
['optional-1', 'Optional Argument 1'],
['optional-2', 'Optional Argument 2'],
['optional-3', 'Optional Argument 3']
],
rest: {
placeholder: 'rest-argument',
description: 'Rest Argument'
},
codes: {
0: success,
1: failure
}
},
({ args, options, optional, rest }) => {
options.verbose
options.host
return 0
}
)
Add Route (Subcommands)
The add
function defines a route.
import { App } from '@jill64/ts-cli'
new App()
.add(
'test',
{
},
() => {
}
)
.add(
'test start',
{
},
() => {
}
)
Run as Command
The run
function executes the command immediately using process.argv
.
import { App } from '@jill64/ts-cli'
import process from 'node:process'
new App().run(process.argv)
Export as API
import { App } from '@jill64/ts-cli'
export const command = new App().add().add()
import { command } from 'index.js'
command.execute({
args: {
arg1: 'value1',
arg2: 'value2',
arg3: 'value3'
},
optional: {
'optional-1': 'optional-value1',
'optional-2': 'optional-value2',
'optional-3': 'optional-value3'
},
options: {
verbose: true,
host: 'example.com'
}
})
command.invoke.test({
})
command.invoke['test start']({
})
License
MIT