Straightforward and type-safe command-line argument parsing with subcommands.
https://github.com/justjake/ts-cli.git
Straightforward and type-safe command-line argument parsing with subcommands.
import { createCLICommand, validate, logger, runThenExitIfMain, runCommand } from '@jitl/cli'
export const command = createCLICommand({
description: `Say hello`,
flags: {
name: {
description: `What name should we greet?`,
validate: validate.string(),
},
exuberant: {
description: `Are we excited?`,
validate: validate.boolean(),
default: () => false,
},
},
async run({ name, exuberant }) {
logger.log(`Hello, ${name}. Nice to see you today${exuberant ? '!' : '.'}`)
},
})
runThenExitIfMain(module, (name, argv) => runCommand(name, command, argv))
@types/... packages, few infer
the arguments of the run() function of a command from the parameters.
The parameters of the run(flags, args, rest) function are completely inferred
from the runtime type specification, so your CLI command declarations are
succinct and readable.
run()
function.
This package offers flexibility through composition, rather than a
complex "plug-ins" or "hooks" interface.
--bool | --value given-value.Positional arguments are still available for glob-related use-cases.
Because this package is short, has a flat dependency graph, and favors composition over hooks/plugins/inheritance, it's easy to replace, wrap, extend, smoosh, and make it your own.
This package only imports its dependencies when they are needed for a specific purpose.
chalk: imported when displaying help output. Used to bold text, which has a nicetable: imported when displaying help output. Used to format the table offs-extra: imported when loading a directory of subcommands. Used to scan aCommandLoaders
object.
inquirer: imported when a user fails to provide a required argument. UsedIn short, this package never imports a dependency on the happy path to run a fully-specified command.
For now, you'll need to read the code.
Command interface to allow nesting subcommandsAn elegant design would allow for arbitrary nesting of commands and subcommand loaders.
validate: Validator<T> interface is not introspectable at runtime,A usable system should be able to infer specific syntax based on the type of the flag.