All files / src/Program/options util.ts

78.57% Statements 11/14
100% Branches 2/2
50% Functions 1/2
77.77% Lines 7/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 2343x   43x           43x             301x   301x 301x   301x    
import { Command, Option } from 'commander';
 
export const addOptions = (command: Command, options: Option[]) => {
  for (const option of options) command.addOption(option);
 
  return command;
};
 
export const newOption = <T>(
  flags: string,
  description: string,
  envName: string,
  argParser?: (value: string, previous: T) => T,
  defaultValue?: unknown
) => {
  const option = new Option(flags, description).env(envName);
 
  if (argParser !== undefined) option.argParser(argParser);
  if (defaultValue !== undefined) option.default(defaultValue);
 
  return option;
};