{"id":23483466,"url":"https://github.com/khtdr/opts","last_synced_at":"2026-03-17T21:05:16.579Z","repository":{"id":56654144,"uuid":"81613617","full_name":"khtdr/opts","owner":"khtdr","description":"A library for parsing command line options in javascript.","archived":false,"fork":false,"pushed_at":"2020-10-27T02:28:07.000Z","size":43,"stargazers_count":6,"open_issues_count":0,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-03-07T19:10:55.013Z","etag":null,"topics":["cli-args","cli-utilities","javascript","nodejs","option-parser","options-parsing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khtdr.png","metadata":{"files":{"readme":"README.org","changelog":"CHANGES.org","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-10T22:42:13.000Z","updated_at":"2025-05-09T00:09:01.000Z","dependencies_parsed_at":"2022-08-15T22:40:37.018Z","dependency_job_id":null,"html_url":"https://github.com/khtdr/opts","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/khtdr/opts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khtdr%2Fopts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khtdr%2Fopts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khtdr%2Fopts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khtdr%2Fopts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khtdr","download_url":"https://codeload.github.com/khtdr/opts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khtdr%2Fopts/sbom","scorecard":{"id":559343,"data":{"date":"2025-08-11","repo":{"name":"github.com/khtdr/opts","commit":"3ee55ed7545530a8d792a924e308e5719ef3eaac"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":0,"reason":"Found 2/28 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: BSD 2-Clause \"Simplified\" License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 4 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-20T13:12:33.670Z","repository_id":56654144,"created_at":"2025-08-20T13:12:33.670Z","updated_at":"2025-08-20T13:12:33.670Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30631437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["cli-args","cli-utilities","javascript","nodejs","option-parser","options-parsing"],"created_at":"2024-12-24T21:12:04.606Z","updated_at":"2026-03-17T21:05:16.564Z","avatar_url":"https://github.com/khtdr.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"#+TITLE: opts.js\n\nFind the full documentation, source code, and examples online at https://khtdr.com/opts.\n\nOr download this README as a man-page.\n#+BEGIN_SRC bash\ncurl -o opts.3 https://raw.githubusercontent.com/khtdr/opts/master/man.3\nman ./opts.3\n#+END_SRC\n\n* NAME\nopts.js - a command line parser for options and arguments\n\n* SYNOPSIS\n\nThe following example uses a custom *version* function, and opts in to the automatic help text. No pun intended.\n\n#+BEGIN_SRC javascript\nvar opts = require('opts');\n\nvar options = [\n  { short       : 'v'\n  , long        : 'version'\n  , description : 'Show version and exit'\n  , callback    : function () { console.log('v1.0'); process.exit(1); }\n  }\n];\n\nopts.parse(options, true);\nconsole.log('Example 1');\nprocess.exit(0);\n#+END_SRC\nSee https://raw.githubusercontent.com/khtdr/opts/master/examples/example1.js\n\n*** running:\n#+BEGIN_SRC bash\n$ node ./example1\n#+END_SRC\n*** produces:\n#+BEGIN_SRC bash\nExample 1\n#+END_SRC\n\n*** running:\n#+BEGIN_SRC bash\n$ node ./example1 --help\n#+END_SRC\n*** produces:\n#+BEGIN_SRC bash\nUsage: node ./example1 [options]\nShow this help message\n   --help\nShow version and exit\n   -v, --version\n#+END_SRC\n\n*** running:\n#+BEGIN_SRC sh\nnode ./example1 -v\n#+END_SRC\n*** produces:\n#+BEGIN_SRC sh\nv1.0\n#+END_SRC\n\n\n\n* INSTALLATION\n\nYou do not need to use NPM or any package manager. It is written in plain-old Javascript and can be downloaded and included in your Node.js project, as-is. All of the examples use this approach.\n.RE\nSee https://github.com/khtdr/opts/tree/master/examples\n\n** Stand-alone version\n#+BEGIN_SRC bash\ncd /path/to/your/project\ncurl -o opts.js https://raw.githubusercontent.com/khtdr/opts/master/src/opts.js\n#+END_SRC\n\n** NPM version\n#+BEGIN_SRC bash\nnpm install opts\n#+END_SRC\n\n* USAGE\n** LOADING\nWith classic syntax:\n#+BEGIN_SRC javascript\nvar opts = require('opts');\nopts.parse(options, arguments, help);\n#+END_SRC\n\nWith modern syntax:\n#+BEGIN_SRC javascript\nimport * as opts from 'opts';\nopts.parse(options, arguments, help);\n#+END_SRC\n\nIf you installed ~opts~ with NPM, the typescript definitions should automatically be available in your editor. Otherwise you can download the .d.ts file manually.\n.RE\nSee https://raw.githubusercontent.com/khtdr/opts/master/src/opts.d.ts\n\n** CONFIGURING\n\n=opts.parse(options, arguments, help)=\n\nOptions are flag-arguments. Arguments are everything else. Consider the following hypothetical command for starting a server that listens on http://0.0.0.0:4000\n\n#+BEGIN_SRC bash\nnode ./my-app start --host 0.0.0.0 -p 4000\n#+END_SRC\n\nIn this example, the options are =--host 0.0.0.0= and =-p 4000=. The argument is =start=. The arguments can be after, before, or among the options.\n\n*** options\n\n~options~ is an array of option objects. Each option in the array can have the following fields. None are required, but you should at least provide a short or long name.\n\n#+BEGIN_SRC javascript\nlet options = [\n  { short       : 'l',\n    long        : 'list',\n    description : 'Show a list',\n    value       : false, // default false\n    required    : true, // default false\n    callback    : function (value) { ... },\n  }, // ... followed by more options\n];\n#+END_SRC\n\n*** arguments\n~arguments~ require less configuration. This is an optional argument to ~opts.parse~:\n\n#+BEGIN_SRC javascript\nlet arguments = [\n    { name     : 'script',\n      required : true, // not required by default\n      callback : function (value) { ... },\n    };\n  ]\n#+END_SRC\n\n*** help text generator\nFinally, you can add an automatically generated help message by passing\na last parameter of =true=. This is also an optional argument to ~opts.parse~.\n\n#+BEGIN_SRC javascript\nopts.parse(options, true);\n// or if you want more control, you can do:\n/*\n  options.push({\n    long        : 'help',\n    description : 'Show this help message',\n    callback    : require('opts').help,\n  }\n  opts.parse(options);\n*/\n#+END_SRC\n\n\n\n* AUTHOR / CHANGELOG / LICENSE\n\nEmail: ohkay@khtdr.com\n\nRelatively unchanged since 2010.\n.RE\nSee https://github.com/khtdr/opts/blob/master/CHANGES.org\n\nBSD 2-Clause License\n.RE\nSee https://github.com/khtdr/opts/blob/master/LICENSE.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhtdr%2Fopts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhtdr%2Fopts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhtdr%2Fopts/lists"}