command-line-usage: Missing `name` in README example

Trying to run the example throws with:
NAME_MISSING: Invalid option definitions: the name property is required on each definition

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (19 by maintainers)

Commits related to this issue

Most upvoted comments

I just hadn’t gotten to raw yet 😃

This has been super helpful, @75lb! I’ll give the docs another read now and see if I can help in some way.

Wait… don’t go all reacting all negative just yet! 😄 … still cleaning it up!

Just for completeness, in case others run into this problem during migration… I ended up with:

const commandLineArgs = require("command-line-args");
const getUsage = require("command-line-usage");

// ℹ️ This is for commandLineArgs, so it can parse incoming arguments.
const optionList = [{
  alias: "h",
  defaultValue: false,
  description: "Display this usage guide.",
  name: "help",
  type: Boolean,
}, {
  alias: "s",
  defaultOption: true,
  description: "URL to ReSpec source file.",
  multiple: false,
  name: "src",
  type: String,
}];

// ℹ️ this is for getUsage(), so it can display helpful stuff. 
const usageSections = [{
  header: "respec2html",
  content: "Converts a ReSpec source file to HTML and prints to std out.",
  footer: "Project home: [underline]{https://github.com/w3c/respec}"
}, {
  header: "Options",
  optionList,
}];

let parsedArgs;
try {
  parsedArgs = commandLineArgs(optionList);
} catch (err) {
  console.error(err);
  console.log(getUsage(usageSections));
  return process.exit(2);
}
// other stuff... where it's all good :)