{"id":17817979,"url":"https://github.com/kjirou/minimist-subcommand","last_synced_at":"2025-03-18T04:30:42.075Z","repository":{"id":47452096,"uuid":"42919501","full_name":"kjirou/minimist-subcommand","owner":"kjirou","description":"A simple sub-command parser for minimist","archived":false,"fork":false,"pushed_at":"2021-08-31T07:40:06.000Z","size":28,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-11T03:34:01.835Z","etag":null,"topics":["getopt","minimist","nodejs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/minimist-subcommand","language":"TypeScript","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/kjirou.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}},"created_at":"2015-09-22T07:52:40.000Z","updated_at":"2020-02-17T06:27:00.000Z","dependencies_parsed_at":"2022-09-06T03:30:26.502Z","dependency_job_id":null,"html_url":"https://github.com/kjirou/minimist-subcommand","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjirou%2Fminimist-subcommand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjirou%2Fminimist-subcommand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjirou%2Fminimist-subcommand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kjirou%2Fminimist-subcommand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kjirou","download_url":"https://codeload.github.com/kjirou/minimist-subcommand/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243910715,"owners_count":20367538,"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","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":["getopt","minimist","nodejs"],"created_at":"2024-10-27T16:47:00.438Z","updated_at":"2025-03-18T04:30:41.781Z","avatar_url":"https://github.com/kjirou.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# minimist-subcommand\n\n[![npm version](https://badge.fury.io/js/minimist-subcommand.svg)](http://badge.fury.io/js/minimist-subcommand)\n[![Build Status](https://travis-ci.org/kjirou/minimist-subcommand.svg?branch=master)](https://travis-ci.org/kjirou/minimist-subcommand)\n\nA simple sub-command parser for [minimist](https://www.npmjs.com/package/minimist)\n\n\n## Installation\n\n```bash\nnpm install minimist-subcommand\n```\n\n\n## Examples\n\n### Basic\n\n`basic.js`:\n\n```js\nconst parseArgs = require('minimist');\nconst {parseCommands} = require('minimist-subcommand');\n\n// parse sub-commands\nconst commandDefinition = {\n  commands: {\n    foo: null,\n    bar: null\n  }\n};\nconst parsedCommandsAndArgv = parseCommands(commandDefinition, process.argv.slice(2));\n\n// pass parsed argv to minimist\nconst options = parseArgs(parsedCommandsAndArgv.argv);\n\nconsole.log('sub-command:', parsedCommandsAndArgv.commands);\nconsole.log('parsed options by minimist:', options);\n```\n\n```bash\n$ node ./basic.js foo arg -a -b val -c\nsub-command: [ 'foo' ]\nparsed options by minimist: { _: [ 'arg' ], a: true, b: 'val', c: true }\n```\n\n```bash\n$ node ./basic.js arg -a\nsub-command: []\nparsed options by minimist: { _: [ 'arg' ], a: true }\n```\n\n```bash\n$ node ./basic.js bar foo\nsub-command: [ 'bar' ]\nparsed options by minimist: { _: [ 'foo' ] }\n```\n\n### Nested commands\n\n`nested-commands.js`:\n\n```js\nconst parseArgs = require('minimist');\nconst {parseCommands} = require('minimist-subcommand');\n\n// parse sub-commands\nconst commandDefinition = {\n  commands: {\n    singleton: null,\n    married: {\n      commands: {\n        child: {\n          commands: {\n            grandchild: null\n          }\n        }\n      }\n    }\n  }\n};\nconst parsedCommandsAndArgv = parseCommands(commandDefinition, process.argv.slice(2));\n\n// pass parsed argv to minimist\nconst options = parseArgs(parsedCommandsAndArgv.argv);\n\nconsole.log('commands:', parsedCommandsAndArgv.commands);\nconsole.log('parsed options by minimist:', options);\n```\n\n```bash\n$ node ./nested-commands.js married child grandchild arg -a\ncommands: [ 'married', 'child', 'grandchild' ]\nparsed options by minimist: { _: [ 'arg' ], a: true }\n```\n\n```bash\n$ node ./nested-commands.js singleton child grandchild\ncommands: [ 'singleton' ]\nparsed options by minimist: { _: [ 'child', 'grandchild' ] }\n```\n\n### Use \"default\" option\n\n`use-default-option.js`:\n\n```js\nconst parseArgs = require('minimist');\nconst {parseCommands} = require('minimist-subcommand');\n\n// parse sub-commands\nconst commandDefinition = {\n  default: 'bar',\n  commands: {\n    foo: null,\n    bar: null\n  }\n};\nconst parsedCommandsAndArgv = parseCommands(commandDefinition, process.argv.slice(2));\n\n// pass parsed argv to minimist\nconst options = parseArgs(parsedCommandsAndArgv.argv);\n\nconsole.log('sub-command:', parsedCommandsAndArgv.commands);\nconsole.log('parsed options by minimist:', options);\n```\n\n```bash\n$ node ./use-default-option.js arg -a\nsub-command: [ 'bar' ]\nparsed options by minimist: { _: [ 'arg' ], a: true }\n```\n\n\n## Command's Schema\n\nIf you want to check schema of `commandDefinition`, please use `COMMAND_JSON_SCHEMA`.\n\n```js\nconst COMMAND_JSON_SCHEMA = require('minimist-subcommand').COMMAND_JSON_SCHEMA;\n\nconst commandDefinition = {\n  commands: {\n    foo: null,\n    bar: null\n  }\n};\n\n// I will leave it to the judgment of the user.\nsomeJsonSchemaLibrary.validate(COMMAND_JSON_SCHEMA, commandDefinition);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkjirou%2Fminimist-subcommand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkjirou%2Fminimist-subcommand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkjirou%2Fminimist-subcommand/lists"}