I have been breaking my head over this. I have looked at a lot of tutorials, not sure what am I doing wrong. Here's my sample test.ts
import * as yargs from 'yargs';
const argv = yargs.options({
env: {
alias: 'e',
choices: ['dev', 'prod'] as const,
demandOption: true,
description: 'app environment'
},
port: {
alias: 'p',
default: 80,
description: 'port'
}
})
.argv;
console.log(argv);
package.json
"dependencies": {
"@types/node": "^16.9.1",
"@types/yargs": "^15.0.0",
"ts-node": "^10.7.0",
"typescript": "^4.6.3",
"winston": "^3.3.3",
"yargs": "^15.4.1"
},
Output
(base) 3c22fb37c8c169:test sriabhil$ npm run sri --env=prod --port=88
> test@1.0.0 sri
> ts-node ./src/test.ts
Options:
--help Show help [boolean]
--version Show version number [boolean]
--env, -e app environment [required] [choices: "dev", "prod"]
--port, -p port [default: 80]
Missing required argument: env
Can someone please help me with this? I feel like I am missing something very basic but not sure what exactly