You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

49 lines
1.5 KiB

// you may not need all of these but they come up a lot
import fs from "fs";
import assert from "assert";
import logging from '../lib/logging.js';
import glob from "fast-glob";
import path from "path";
import template from "lodash/template.js";
const log = logging.create(import.meta.url);
export const description = "Describe your command here."
// your command uses the npm package commander's options format
export const options = [
["--input <string>", "A string option with a default.", "default.json"],
["--min <number>", "A number option, no default."],
]
// example of a positional argument, it's the 1st argument to main
export const argument = ["source", "source directory"];
// put required options in the required variable
export const required = [
["--output <string>", "Save to file rather than stdout."],
]
// handy function for checking things are good and aborting
const check = (test, fail_message) => {
if(!test) {
log.error(fail_message);
process.exit(1);
}
}
export const main = async (arg, opts) => {
// if they give an numeric option this is how you can convert it
// yes, this is annoying and commander should handle it but oh well
if(opts.min !== undefined) {
// commander doesn't do integer conversions sadly
opts.min = parseInt(opts.min, 10);
check(!isNaN(opts.min), "--min must be a number");
}
// it's easier to debug options with console
console.log("OPTIONS", opts, "ARG", arg);
// due to how async/await works it's just easier to manually exit with exit codes
process.exit(0);
}