Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

strongly-typed args #43

@cyberhck

Description

@cyberhck

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions