yargs
yargs - npm
yargs/examples.md at main · yargs/yargs · GitHub
サブコマンドで場合分け
.command(command, description, builder, handler)
requiresArg は引数必須
demandOption は必須オプション
.demandCommand(1) でコマンド1つ必須に、なければヘルプ出る
code:sample.js
yargs(hideBin(process.argv))
.usage('Usage: $0 <command> options')
.command(
'dump',
'dump content',
yargs =>
yargs.usage('Usage: $0 dump --rk=<rk>').option('rk', {
demandOption: true,
requiresArg: true,
type: 'string',
describe: 'rk Cookie value',
}),
dump
)
.command(
'sync',
'sync content',
yargs =>
yargs.usage('Usage: $0 sync --rk=<rk>').option('rk', {
demandOption: true,
requiresArg: true,
type: 'string',
describe: 'rk Cookie value',
}),
sync
)
.option('verbose', {
alias: 'v',
type: 'boolean',
})
.demandCommand(1).argv;
#Node