Roaders / ts-command-line-args

A typescript wrapper for command-line-args that allow you to generate config from existing TS interfaces
26 stars 11 forks source link

Support for environment variables #30

Open lunaris opened 2 years ago

lunaris commented 2 years ago

Hey there. Would this library be open to a contribution that allowed supporting environment variables alongside command-line arguments? Something in line with commander's env method on Options, but with the typing benefits of ts-command-line-args. I'm envisaging an interface something like:

const args = parse<ICopyFilesArguments>({
  sourcePath: {
    type: String,
    env: "SOURCE_PATH",
  },
})

With the merge order being -- default values, configuration file, environment variables, command-line arguments. I'm not sure if this is something you feel falls under the remit of this library, but if it is, I'd be happy to help develop it. Our use case is largely one of backwards compatibility (we are porting some applications that support both command-line and environment variables to NodeJS) and a slightly better support for environment variables in some of the containerised environments we deploy to.

Thanks in advance for your thoughts and the work on the library so far!

Roaders commented 2 years ago

yes... That could be useful and should be fairly easy to implemet as well. If you do a PR I'll take a look.