0.0.5 • Published 6 years ago

rh_arg-parser v0.0.5

Weekly downloads
11
License
MIT
Repository
-
Last release
6 years ago

###Example:

const genFeature: FeatureList<GenOptions> = {
  name: "Generate types",
  entrypoint: "gen",
  examples: [
    "gql-typegen --schema ./gqlschema.json --write ./output.ts",
    "gql-typegen --schema ./gqlschema.json --append --write ./output.ts",
    "gql-typegen -s ./gqlschema.json -o ./output.ts",
    "gql-typegen ./gqlschema.json ./output.ts",
    "gql-typegen ./gqlschema.json"
  ],
  default: true,
  feature: {
    callback: generateTypes,
    description: ""
  },
  expecting: {
    upto: 2
  },
  options: {
    write: null,
    source: null,
    append: false,
    ignoreEnums: false,
    oldApollo: false,
    onlyNull: false
  },
  properties: [
    {
      command: "write",
      alias: ["o", "w"],
      callback: (options, path: string) => ({ write: path }),
      input: true
    },
    {
      command: "schema",
      alias: ["s"],
      callback: (options, path: string) => ({ source: path }),
      input: true
    },
    {
      command: "only-null",
      alias: ["n"],
      callback: options => ({ onlyNull: true }),
      input: false
    },
    {
      command: "append",
      alias: ["a"],
      callback: options => ({ append: true }),
      input: false
    },
    {
      command: "ignore-enums",
      alias: ["i"],
      callback: options => ({ ignoreEnums: true }),
      input: false
    },
    {
      command: "old-apollo",
      callback: options => ({ oldApollo: true }),
      input: false
    }
  ]
};

if (module.parent === null) {
  const args = [...process.argv].slice(2);
  if (args.length === 0) {
    printHelp([genFeature]);
    process.exit(1);
  }

  runFeature(genFeature, args).catch(e => {
    console.error(e.message);
    process.exit(1);
  });
}