{"id":15956249,"url":"https://github.com/aniketfuryrocks/smartarg","last_synced_at":"2025-04-04T07:42:55.115Z","repository":{"id":57363960,"uuid":"268054839","full_name":"aniketfuryrocks/SmartArg","owner":"aniketfuryrocks","description":"SmartArg is a forked repo of Arg, with smart help and version logging","archived":false,"fork":false,"pushed_at":"2020-05-30T12:31:09.000Z","size":73,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-01T14:17:48.947Z","etag":null,"topics":["arg","args","commander","nodejs","parser","yarg"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/smartarg","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/aniketfuryrocks.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":"2020-05-30T10:11:00.000Z","updated_at":"2021-06-14T15:05:48.000Z","dependencies_parsed_at":"2022-09-16T22:51:37.087Z","dependency_job_id":null,"html_url":"https://github.com/aniketfuryrocks/SmartArg","commit_stats":null,"previous_names":["eadded/smartarg"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aniketfuryrocks%2FSmartArg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aniketfuryrocks%2FSmartArg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aniketfuryrocks%2FSmartArg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aniketfuryrocks%2FSmartArg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aniketfuryrocks","download_url":"https://codeload.github.com/aniketfuryrocks/SmartArg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247142042,"owners_count":20890652,"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":["arg","args","commander","nodejs","parser","yarg"],"created_at":"2024-10-07T13:30:03.677Z","updated_at":"2025-04-04T07:42:55.088Z","avatar_url":"https://github.com/aniketfuryrocks.png","language":"JavaScript","readme":"# Smart Arg 🤓\n\n`Smart Arg` is a forked repo of [Arg](https://github.com/vercel/arg), with smart help and version logging.\n\n## Installation\n\nUse Yarn or NPM to install.\n\n```console\n$ yarn add smartarg\n```\n\nor\n\n```console\n$ npm install smartarg\n```\n\n## Usage\n*all examples are in type script*\n```\nimport SmartArg from \"smartarg\";\n\ninterface args {\n    \"--say\": string,\n    \"--secret\": boolean\n}\n\nconst args: args = new SmartArg\u003cargs\u003e()\n    .name(\"SmartArg\")\n    .version(\"0.0.1\")\n    .description(\"Forked repo of Arg, with smart help and version logging\")\n    .option([\"-s\", \"--say\"], String, \"prints the value of --say\")\n    .option([\"--secret\"], Boolean, \"prints a secret\")\n    .smartParse()\n\nif (args[\"--say\"])\n    console.log(`You asked me to say ${args[\"--say\"]}`);\nif (args[\"--secret\"])\n    console.log(\"Checkout @eadded/firejs. Best React Static Generator\");\n```\n\n*Output on -h*\n\n![image](sample.png)\n\n## Functions\n\n```name(string)```          specify project name\n\n```version(string)```       specify project version\n\n```description(string)``` specify project description\n\n```usage(string)``` specify commandline usage, default : ```name``` \u003cflag\u003e\n\n```examples(string)``` specify an example, default : ```name``` -h\n\n```primaryColor(number)``` specify [ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code) color code, default : 1\n\n```secondaryColor(number)``` specify [ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code) color code, default : 33\n\n```smartParse(config)``` terminates the program after printing help on ```[-h,--help]``` and version on ```[-v,--version]```, else returns [result](#result)\n\n```parse(config)``` returns [result](#result)\n\n## Result\n\nIt returns an object with any values present on the command-line (missing options are thus\nmissing from the resulting object). SmartArg performs no validation/requirement checking - we\nleave that up to the application.\n\nAll parameters that aren't consumed by options (commonly referred to as \"extra\" parameters)\nare added to `result._`, which is _always_ an array (even if no extra parameters are passed,\nin which case an empty array is returned).\n\nFor example:\n\n```console\n$ node ./hello.js --verbose -vvv --port=1234 -n 'My name' foo bar --tag qux --tag=qix -- --foobar\n```\n\n```\n// test.js\nimport SmartArg, {COUNT} from \"smartarg\";\ninterface args {\n    \"--verbose\": string,\n    \"--port\": boolean,\n    \"--name\": string,\n    \"--tag\": [string],\n    \"--label\": string\n}\n\nconst args: args = new SmartArg\u003cargs\u003e()\n    .option([\"-v\", \"--verbose\"], COUNT, \"Counts the number of times --verbose is passed\")\n    .option([\"-p\", \"--port\"], COUNT, \"Counts the number of times --verbose is passed\")\n    .option([\"-n\", \"--name\"], String, \"Counts the number of times --verbose is passed\")\n    .option([\"-t\", \"--tag\"], [String], \"Counts the number of times --verbose is passed\")\n    .option([\"--label\"], COUNT, \"Counts the number of times --verbose is passed\")\n    .parse();\n\nconsole.log(args);\n/*\n{\n\t_: [\"foo\", \"bar\", \"--foobar\"],\n\t'--port': 1234,\n\t'--verbose': 4,\n\t'--name': \"My name\",\n\t'--tag': [\"qux\", \"qix\"]\n}\n*/\n```\n\nThe values for each key=\u0026gt;value pair is either a type (function or [function]) or a string (indicating an alias).\n\n- In the case of a function, the string value of the argument's value is passed to it,\n  and the return value is used as the ultimate value.\n\n- In the case of an array, the only element _must_ be a type function. Array types indicate\n  that the argument may be passed multiple times, and as such the resulting value in the returned\n  object is an array with all of the values that were passed using the specified flag.\n\n- In the case of a string, an alias is established. If a flag is passed that matches the _key_,\n  then the _value_ is substituted in its place.\n\nType functions are passed three arguments:\n\n1. The parameter value (always a string)\n2. The parameter name (e.g. `--label`)\n3. The previous value for the destination (useful for reduce-like operations or for supporting `-v` multiple times, etc.)\n\nThis means the built-in `String`, `Number`, and `Boolean` type constructors \"just work\" as type functions.\n\nNote that `Boolean` and `[Boolean]` have special treatment - an option argument is _not_ consumed or passed, but instead `true` is\nreturned. These options are called \"flags\".\n\nFor custom handlers that wish to behave as flags, you may pass the function through `flag()`:\n\n```\nimport SmartArg, {flag} from \"./SmartArg\";\n\nconst argv = ['--foo', 'bar', '-ff', 'baz', '--foo', '--foo', 'qux', '-fff', 'qix'];\n\nfunction myHandler(value, argName, previousValue) {\n    /* `value` is always `true` */\n    return 'na ' + (previousValue || 'batman!');\n}\n\ninterface args {\n    \"--foo\": string\n}\n\nconst args = new SmartArg\u003cargs\u003e()\n    .option([\"-f\",\"--foo\"], flag(myHandler),\"\")\n    .parse({argv});\n\nconsole.log(args);\n/*\n{\n\t_: ['bar', 'baz', 'qux', 'qix'],\n\t'--foo': 'na na na na na na na na batman!'\n}\n*/\n```\n\nAs well, `SmartArg` supplies a helper argument handler called `COUNT`, which equivalent to a `[Boolean]` argument's `.length`\nproperty - effectively counting the number of times the boolean flag, denoted by the key, is passed on the command line.\n\n### Options\n\nObject passed to `parse()` or `smartParse()` specifies parsing options to modify the behavior.\n\n#### `argv`\n\nIf you have already sliced or generated a number of raw arguments to be parsed (as opposed to letting `SmartArg`\nslice them from `process.argv`) you may specify them in the `argv` option.\n\n#### `permissive`\n\nWhen `permissive` set to `true`, `SmartArg` will push any unknown arguments\nonto the \"extra\" argument array (`result._`) instead of throwing an error about\nan unknown flag.\n\n#### `stopAtPositional`\n\nWhen `stopAtPositional` is set to `true`, `SmartArg` will halt parsing at the first\npositional argument.\n\n### Errors\n\nSome errors that `SmartArg` throws provide a `.code` property in order to aid in recovering from user error, or to\ndifferentiate between user error and developer error (bug).\n\n##### ARG_UNKNOWN_OPTION\n\nIf an unknown option (not defined in the spec object) is passed, an error with code `ARG_UNKNOWN_OPTION` will be thrown\n\n## License \u0026 Copyright\nCopyright (C) 2020 Aniket Prajapati\n\nLicensed under the [MIT LICENSE](LICENSE)\n\n## Contributors\n + [Aniket Prajapati](https://github.com/aniketfuryrocks) @ prajapati.ani306@gmail.com , [eAdded](http://www.eadded.com)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faniketfuryrocks%2Fsmartarg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faniketfuryrocks%2Fsmartarg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faniketfuryrocks%2Fsmartarg/lists"}