All files / src options.ts

0% Statements 0/12
100% Branches 0/0
0% Functions 0/4
0% Lines 0/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50                                                                                                   
import mapValues from "lodash/mapValues";
import yargs from "yargs";
import { sync as findUp } from "find-up";
import { Plugin } from "@hygiene/core";
import { run } from "./command/run";
 
export const createCommand = ({ plugins }: { plugins: Plugin<any, any>[] }) => {
  const cmd = yargs
    .scriptName("hygiene")
    .option("json", {
      describe: "Report as JSON",
      type: "boolean",
      default: false
    })
    .option("ignore-pattern", {
      describe: "Pattern of files to ignore",
      type: "string",
      default: null
    })
    .option("ignore-path", {
      describe: "Specify path of ignore file",
      type: "string",
      default: findUp(".gitignore")
    })
    .option("ignore", {
      describe: "Disable use of ignore files and patterns",
      type: "boolean",
      default: true
    })
    .command({
      command: "run [glob]",
      describe: "",
      // @ts-ignore Type 'Argv<{}>' is missing the following properties from type 'Options': _, json, ignorePath
      handler: run({ plugins }),
      builder: yargs => yargs.default("glob", "**/*")
    })
    .demandCommand()
    .help();
 
  plugins.forEach(plugin => {
    const options = mapValues(plugin.getConfigDefinition(), option => ({
      group: plugin.name,
      ...option
    }));
    cmd.options(options);
  });
 
  return cmd;
};