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

Any way to add a default number? #43

Closed ohare93 closed 9 months ago

ohare93 commented 9 months ago
interface IArguments {
  latest?: number;
  ...
}

export const args = parse<IArguments>(
  {
    latest: {type: Number, optional: true},
    ...
  }
);

I have the above setup. I can pass --latest 3 to get 3. Is there any way I can have it so that passing --latest only will result in 1? I cannot seem to get the typing to be happy with passing a boolean, or defaulting to 1 when --latest is passed and null when it is not.

Thanks for any help 👍

Roaders commented 9 months ago

no, you can't have a number as a default value for a boolean cli arg.

ohare93 commented 9 months ago

How about a default for a number cli arg? Or is it always mandatory for a value to be passed?