Skip to content

feat: add Args.option() for typed arg options#1568

Open
rexxars wants to merge 2 commits into
oclif:mainfrom
rexxars:rexxars/typed-arg-options
Open

feat: add Args.option() for typed arg options#1568
rexxars wants to merge 2 commits into
oclif:mainfrom
rexxars:rexxars/typed-arg-options

Conversation

@rexxars

@rexxars rexxars commented Mar 30, 2026

Copy link
Copy Markdown
Contributor

Adds a new Args.option() method mirroring Flags.option(), which provides type-safe option usage:

class Deploy extends Command {
  static args = {
    env: Args.option({
      options: ['production', 'staging', 'development'] as const
    })()
  }

  async run() {
    const {args} = await this.parse(Deploy)
    // `args.env` typed as `'production' | 'staging' | 'development' | undefined`
  }
}

Setting it as required removes the undefined from the union.

@rexxars

rexxars commented Apr 1, 2026

Copy link
Copy Markdown
Contributor Author

Updated to include stricter type parsing: I feel it is easy to assume that options like multiple: true would go alongside options, but they should be passed on the second call.

I think theoretically we could make Args.string()/Args.integer() work too, but it would require a lot more typescript overloads - let me know if that is preferable.

@rexxars

rexxars commented May 6, 2026

Copy link
Copy Markdown
Contributor Author

@jfeingold35 Any thoughts on this?

@jfeingold35

Copy link
Copy Markdown
Contributor

@rexxars , sorry for the delay! I'll get this reviewed shortly and talk it over with the team.

@jfeingold35

Copy link
Copy Markdown
Contributor

@rexxars , the code looks clean to me. We'll do some QAing and then we can get this approved and merged. However, it would be ideal if you could have a few runtime tests, e.g.,

  • can it parse one arg
  • Does it play well with multiple
  • Does it reject invalid args
    etc
    Also, the documentation would need to be updated as well.

@rexxars

rexxars commented May 12, 2026

Copy link
Copy Markdown
Contributor Author

Will have a look. I couldn't find any documentation on Flags.option(), so wasn't sure if this was meant to be "public" or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants