arcanis / clipanion

Type-safe CLI library / framework with no runtime dependencies
https://mael.dev/clipanion/
1.1k stars 61 forks source link

Typepanion Literal Number and Option.String do not play nice together #125

Open xenoterracide opened 2 years ago

xenoterracide commented 2 years ago
// don't use well known ports
const isPort = isOneOf(
  [isLiteral(0), cascade(isNumber(), isInteger(), isPositive(), isInInclusiveRange(1024, 65535))],
  { exclusive: true },
)

export class App extends Command {
  readonly port = Option.String('--port', '0', { validator: isPort })

  static readonly paths = [Command.Default]
 }

unfortunately OptionString cannot take a number, and so literal 0 will fail

❯ yarn workspace @cof/e1-fake-chamber-of-secrets serve
Usage Error: Invalid value for port:

- .#1: Expected 0 (got "0")
- .#2: Expected to be in the [1024; 65535] range (got 0)

I guess my suggestion for a fix would be to allow a subset of primitives to Option.String fortunately express seems ok with the string