Here is what I tried (code adapted the code from the example in the yargs github readme):
// main.ts
import {Argv} from "yargs";
console.info(`CLI starter.`);
function serve(port: string) {
console.info(`Serve on port ${port}.`);
}
require('yargs')
.command('serve', "Start the server.", (yargs: Argv) => {
yargs.option('port', {
describe: "Port to bind on",
default: "5000",
}).option('verbose', {
alias: 'v',
default: false,
})
}, (args: any) => {
if (args.verbose) {
console.info("Starting the server...");
}
serve(args.port);
}).argv;
Results:
npm run-script build; node build/main.js --port=432 --verbose
> typescript-cli-starter@0.0.1 build /Users/kaiyin/WebstormProjects/typescript-cli-starter
> tsc -p .
CLI starter.
Looks like yargs has no effects here.
Any idea how to get this to work?