{"id":28372315,"url":"https://github.com/brainjs/nomnom","last_synced_at":"2026-07-01T05:31:10.105Z","repository":{"id":96108907,"uuid":"59974244","full_name":"BrainJS/nomnom","owner":"BrainJS","description":"Option parser for node with generated usage and commands","archived":false,"fork":false,"pushed_at":"2016-05-30T02:18:30.000Z","size":135,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-07-02T14:44:55.480Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BrainJS.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2016-05-30T02:16:17.000Z","updated_at":"2019-09-16T01:40:37.000Z","dependencies_parsed_at":"2023-09-26T07:51:31.819Z","dependency_job_id":null,"html_url":"https://github.com/BrainJS/nomnom","commit_stats":{"total_commits":128,"total_committers":14,"mean_commits":9.142857142857142,"dds":0.140625,"last_synced_commit":"6110ac36f9d94b7b7a0799e70ace729872fb26eb"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/BrainJS/nomnom","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Fnomnom","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Fnomnom/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Fnomnom/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Fnomnom/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BrainJS","download_url":"https://codeload.github.com/BrainJS/nomnom/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BrainJS%2Fnomnom/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267668756,"owners_count":24124967,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-29T02:00:12.549Z","response_time":2574,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-05-29T13:43:23.355Z","updated_at":"2026-07-01T05:31:10.088Z","avatar_url":"https://github.com/BrainJS.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deprecation notice\n\nNomnom is deprecated. Check out https://github.com/tj/commander.js, which should have most, if not all of the capability that nomnom had. Thank you!\n\n# nomnom\nnomnom is an option parser for node. It noms your args and gives them back to you in a hash.\n\n```javascript\nvar opts = require(\"nomnom\")\n   .option('debug', {\n      abbr: 'd',\n      flag: true,\n      help: 'Print debugging info'\n   })\n   .option('config', {\n      abbr: 'c',\n      default: 'config.json',\n      help: 'JSON file with tests to run'\n   })\n   .option('version', {\n      flag: true,\n      help: 'print version and exit',\n      callback: function() {\n         return \"version 1.2.4\";\n      }\n   })\n   .parse();\n\nif (opts.debug)\n   // do stuff\n```\n\nYou don't have to specify anything if you don't want to:\n\n```javascript\nvar opts = require(\"nomnom\").parse();\n\nvar url = opts[0];     // get the first positional arg\nvar file = opts.file   // see if --file was specified\nvar verbose = opts.v   // see if -v was specified\nvar extras = opts._    // get an array of the unmatched, positional args\n```\n\n# Install\nfor [node.js](http://nodejs.org/) and [npm](http://github.com/isaacs/npm):\n\n\tnpm install nomnom\n\n# More Details\nNomnom supports args like `-d`, `--debug`, `--no-debug`, `--file=test.txt`, `--file test.txt`, `-f test.txt`, `-xvf`, and positionals. Positionals are arguments that don't fit the `-a` or `--atomic` format and aren't attached to an option.\n\nValues are JSON parsed, so `--debug=true --count=3 --file=log.txt` would give you:\n\n```\n{\n   \"debug\": true,\n   \"count\": 3,\n   \"file\": \"log.txt\"\n}\n```\n\n# Commands\nNomnom supports command-based interfaces (e.g. with git: `git add -p` and `git rebase -i` where `add` and `rebase` are the commands):\n\n```javascript\nvar parser = require(\"nomnom\");\n\nparser.command('browser')\n   .callback(function(opts) {\n      runBrowser(opts.url);\n   })\n   .help(\"run browser tests\");\n\nparser.command('sanity')\n   .option('outfile', {\n      abbr: 'o',\n      help: \"file to write results to\"\n   })\n   .option('config', {\n      abbr: 'c',\n      default: 'config.json',\n      help: \"json manifest of tests to run\"\n   })\n   .callback(function(opts) {\n      runSanity(opts.filename);\n   })\n   .help(\"run the sanity tests\")\n\nparser.parse();\n```\n\nEach command generates its own usage message when `-h` or `--help` is specified with the command.\n\n# Usage\nNomnom prints out a usage message if `--help` or `-h` is an argument. Usage for these options in `test.js`:\n\n```javascript\nvar opts = require(\"nomnom\")\n   .script(\"runtests\")\n   .options({\n      path: {\n         position: 0,\n         help: \"Test file to run\",\n         list: true\n      },\n      config: {\n         abbr: 'c',\n         metavar: 'FILE',\n         help: \"Config file with tests to run\"\n      },\n      debug: {\n         abbr: 'd',\n         flag: true,\n         help: \"Print debugging info\"\n      }\n   }).parse();\n```\n\n...would look like this:\n\n\tusage: runtests \u003cpath\u003e... [options]\n\n\tpath     Test file to run\n\n\toptions:\n\t   -c FILE, --config FILE   Config file with tests to run\n\t   -d, --debug              Print debugging info\n\n# Options\nYou can either add a specification for an option with `nomnom.option('name', spec)` or pass the specifications to `nomnom.options()` as a hash keyed on option name. Each option specification can have the following fields:\n\n#### abbr and full\n`abbr` is the single character string to match to this option, `full` is the full-length string (defaults to the name of the option).\n\nThis option matches `-d` and `--debug` on the command line:\n\n```javascript\nnomnom.option('debug', {\n   abbr: 'd'\n})\n```\n\nThis option matches `-n 3`, `--num-lines 12` on the command line:\n\n```javascript\nnomnom.option('numLines', {\n   abbr: 'n',\n   full: 'num-lines'\n})\n```\n\n#### flag\n\nIf this is set to true, the option acts as a flag and doesn't swallow the next value on the command line. Default is `false`, so normally if you had a command line `--config test.js`, `config` would get a value of `test.js` in the options hash. Whereas if you specify:\n\n```javascript\nnomnom.option('config', {\n   flag: true\n})\n```\n\n`config` would get a value of `true` in the options hash, and `test.js` would be a free positional arg.\n\n#### metavar\n\n`metavar` is used in the usage printout e.g. `\"PATH\"` in `\"-f PATH, --file PATH\"`.\n\n#### string\n\nA shorthand for `abbr`, `full`, and `metavar`. For example, to attach an option to `-c` and `--config` use a `string: \"-c FILE, --config=FILE\"`\n\n#### help\n\nA string description of the option for the usage printout.\n\n#### default\n\nThe value to give the option if it's not specified in the arguments.\n\n#### type\n\nIf you don't want the option JSON-parsed, specify type `\"string\"`.\n\n#### callback\n\nA callback that will be executed as soon as the option is encountered. If the callback returns a string it will print the string and exit:\n\n```javascript\nnomnom.option('count', {\n   callback: function(count) {\n      if (count != parseInt(count)) {\n         return \"count must be an integer\";\n      }\n   }\n})\n```\n\n#### position\n\nThe position of the option if it's a positional argument. If the option should be matched to the first positional arg use position `0`, etc.\n\n#### list\n\nSpecifies that the option is a list. Appending can be achieved by specifying the arg more than once on the command line:\n\n\tnode test.js --file=test1.js --file=test2.js\n\nIf the option has a `position` and `list` is `true`, all positional args including and after `position` will be appended to the array.\n\n#### required\n\nIf this is set to `true` and the option isn't in the args, a message will be printed and the program will exit.\n\n#### choices\n\nA list of the possible values for the option (e.g. `['run', 'test', 'open']`). If the parsed value isn't in the list a message will be printed and the program will exit.\n\n#### transform\n\nA function that takes the value of the option as entered and returns a new value that will be seen as the value of the option.\n\n```javascript\nnomnom.option('date', {\n   abbr: 'd',\n   transform: function(timestamp) {\n     return new Date(timestamp);\n   }\n})\n```\n\n#### hidden\n\nOption won't be printed in the usage\n\n\n# Parser interface\n`require(\"nomnom\")` will give you the option parser. You can also make an instance of a parser with `require(\"nomnom\")()`. You can chain any of these functions off of a parser:\n\n#### option\n\nAdd an option specification with the given name:\n\n```javascript\nnomnom.option('debug', {\n   abbr: 'd',\n   flag: true,\n   help: \"Print debugging info\"\n})\n```\n\n#### options\n\nAdd options as a hash keyed by option name, good for a cli with tons of options like [this example](http://github.com/harthur/replace/blob/master/bin/replace.js):\n\n```javascript\nnomnom.options({\n   debug: {\n      abbr: 'd',\n      flag: true,\n      help: \"Print debugging info\"\n   },\n   fruit: {\n      help: \"Fruit to buy\"\n   }\n})\n```\n\n#### usage\n\nThe string that will override the default generated usage message.\n\n#### help\n\nA string that is appended to the usage.\n\n#### script\n\nNomnom can't detect the alias used to run your script. You can use `script` to provide the correct name for the usage printout instead of e.g. `node test.js`.\n\n#### printer\n\nOverrides the usage printing function.\n\n#### command\n\nTakes a command name and gives you a command object on which you can chain command options.\n\n#### nocommand\n\nGives a command object that will be used when no command is called.\n\n#### nocolors\n\nDisables coloring of the usage message.\n\n#### parse\n\nParses node's `process.argv` and returns the parsed options hash. You can also provide argv:\n\n```javascript\nvar opts = nomnom.parse([\"-xvf\", \"--atomic=true\"])\n```\n\n#### nom\n\nThe same as `parse()`.\n\n# Command interface\nA command is specified with `nomnom.command('name')`. All these functions can be chained on a command:\n\n#### option\n\nAdd an option specifically for this command.\n\n#### options\n\nAdd options for this command as a hash of options keyed by name.\n\n#### callback\n\nA callback that will be called with the parsed options when the command is used.\n\n#### help\n\nA help string describing the function of this command.\n\n#### usage\n\nOverride the default generated usage string for this command.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainjs%2Fnomnom","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrainjs%2Fnomnom","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrainjs%2Fnomnom/lists"}