EDIT FROM JEFF: despite what this says, we already support strongly-typed flags, but with typescript 3.x I think it would also be possible to support args
As of now, when I try to lookup what values are present on args and flags, it's quite tricky and it's not accurate because of any typing. If we could make it generic something like this:
import {Command, flags} from '@oclif/command'
interface IFlags {
help: IBooleanFlag
name: string
connected: boolean
}
interface IArgs {
file: string
}
export default class ReactComponent extends Command<IFlags, IArgs> {
static description = 'Generate react components'
static flags = {
help: flags.help({char: 'h'}),
name: flags.string({char: 'n', description: 'Component Name'}),
connected: flags.boolean({char: 'c', description: 'add connect()'})
}
static args = [{name: 'file'}]
async run() {
const {args, flags} = this.parse(ReactComponent)
const name = flags.name || 'world'
}
}
I do realize that doing argument parsing is different than it is now, that could be tackled either with next major version with breaking changes, or we can find a way around that (or simply say parse will return that type). This would improve experience by so much.
EDIT FROM JEFF: despite what this says, we already support strongly-typed flags, but with typescript 3.x I think it would also be possible to support args
As of now, when I try to lookup what values are present on args and flags, it's quite tricky and it's not accurate because of
anytyping. If we could make it generic something like this:I do realize that doing argument parsing is different than it is now, that could be tackled either with next major version with breaking changes, or we can find a way around that (or simply say parse will return that type). This would improve experience by so much.