Schniz / cmd-ts

💻 A type-driven command line argument parser
https://cmd-ts.now.sh
MIT License
241 stars 25 forks source link

Add a `object` combinator #20

Open Schniz opened 4 years ago

Schniz commented 4 years ago

The basic should be the same as command, and maybe command should use it internally:

object({
  someName: ArgParser<T>,
  otherName: ArgParser<R>,
}) => ArgParser<{ someName: T, otherName: R }>
Schniz commented 3 years ago

I have implemented it. Wasn't hard. But I'm not sure that it is far better than:

const extended = {
  someName: myParser(),
  otherName: otherName(),
} as const

command({
  args: { ...extended }
  ...
})

Maybe I will do it just for the sake of single responsibility, the command function is fairly large. Extracting the object parsing into an object would kinda make sense for maintainability.