Command flag for `ParseOptions`
- Dominant language
- TypeScript
- Stars
- 3.6k
- Forks
- 681
- PR merge metrics
- No merged PRs in 30d
Description
**Is your feature request related to a problem? Please describe.**
I want to create a CLI with multiple command that flags are used differently. Something like the `deno` cli.
**Describe the solution you'd like**
A nest of `ParseOptions` would be ideal. Here is my purposal:
```ts
import { parseArgs } from 'https://deno.land/std@0.213.0/cli/parse_args.ts'
const option = {
commandList: [
{ command: 'build' },
{ command: 'dev', alias: { watch: 'w' }, boolean: [ 'watch' ] },
{
command: 'start',
commandList: [
{ command: 'the-sims', },
{ command: 'fallout', alias: { series: 's' }, string: [ 'series' ] },
],
alias: { mode: 'm', vsync: 'v' },
string: [ 'mode' ],
boolean: [ 'vsync' ],
}
],
alias: { help: 'h', version: 'v' },
boolean: [ 'help', 'version' ],
}
parseArgs([ 'build', '-w' ], option)
// parsedArgs: { command: [ 'build' ], watch: true, w: true, _: [] }
parseArgs([ '-w', 'build' ], option)
// parsedArgs: { watch: true, w: true, _: [ 'build' ] }
parseArgs([ 'start', 'fallout', '-v', '-m window' ], option)
// parsedArgs: { command: [ 'start', 'fallout' ], v: true, vsync:true, m:'window', mode:'window', _: [] }
parseArgs([ 'start', '-v', 'fallout', '--mode=window' ], option)
// parsedArgs: { command: [ 'start' ], v: true, vsync:true, m:'window', mode:'window', _: [ 'fallout' ] }
```
**Describe alternatives you've considered**
I don't know, but for now I will check the first and second item in `Deno.args` to decide if it is a command or not. It is fine but it doesn't offer a good context for alias flags.
Contributor guide
Assessment
This issue has not been assessed yet.