Closed magicdawn closed 3 years ago
src/test.ts
#!/usr/bin/env ts-node-script import {Cli, Command} from 'clipanion' // greet [-v,--verbose] [--name ARG] class GreetCommand extends Command { @Command.Boolean(`-v,--verbose`) verbose: boolean @Command.String(`--name`) name: string static paths = [[`greet`]] async execute() { if (typeof this.name === `undefined`) { this.context.stdout.write(`You're not registered.\n`) } else { this.context.stdout.write(`Hello, ${this.name}!\n`) } } } const cli = new Cli({ binaryLabel: `My Utility`, binaryName: `bin`, binaryVersion: `1.0.0`, }) cli.register(Command.Entries.Help) cli.register(Command.Entries.Version) cli.register(GreetCommand) cli.runExit(process.argv.slice(2), { ...Cli.defaultContext, })
when execute
$ ./src/test.ts You're not registered.
tsconfig.json
{ "include": ["src/**/*"], "compilerOptions": { "rootDir": "src", "outDir": "lib", "allowSyntheticDefaultImports": true, "esModuleInterop": true, "moduleResolution": "node", "resolveJsonModule": true, "target": "es2019", "module": "CommonJS", "skipLibCheck": true, "incremental": true, "experimentalDecorators": true } }
the greet command should be called when execute ./src/test.ts greet, but not ./src/test.ts
./src/test.ts greet
./src/test.ts
@Command.Path() decorator will work, close this.
@Command.Path()
src/test.ts
when execute
tsconfig.json
the greet command should be called when execute
./src/test.ts greet
, but not./src/test.ts