0.0.2 • Published 4 years ago
fs-read-write v0.0.2
Introduction
Modular typescript CLI builder
Why to have another cli parser when we have yargs, oclif and so on.
- Modularity
const base = baseCommand()
.flag(['--debug', '-d'])
.parse((match)=>{
return {
debug: match('--debug', (v) => !!v, false)
}
})
const buildBase = base
.flag('--port')
.flag('--env')
.parse(async (match, prev)=> {
return {
...prev,
env: await match('--env', Prompt.select('Please select environment', ['production', 'development']), 'development')
port: await match('--port', Prompt.number('Please enter port number'), 3000)
}
})
cli({
cliName: 'pkg',
commands: [
base.command('lint').handle(()=> {
// Handle lint
}),
buildBase.command('watch').handle(({ debug, env, port })=>{
// handle watch command
}), buildBase.command('build').handle(({ debug, env, port })=>{
// handle watch command
})
]
})
- Arguments validation order
Arguments dependencies
Let's assume simple cli
yarn xxx --namespace abc --customer sample
- Customer value depends on namespace
- Let's assume that
abc
namespace is invalid and correct namespace isabc_123
Cli should fail