{"id":13902915,"url":"https://github.com/jspears/ts-arg","last_synced_at":"2025-04-25T14:32:08.824Z","repository":{"id":44212243,"uuid":"240434586","full_name":"jspears/ts-arg","owner":"jspears","description":"A Typescript decorator based argument parser","archived":false,"fork":false,"pushed_at":"2023-04-01T12:25:33.000Z","size":373,"stargazers_count":3,"open_issues_count":21,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-23T02:04:14.574Z","etag":null,"topics":["argv","cli","command-line","decorators","node","typescripts"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jspears.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-14T05:22:46.000Z","updated_at":"2024-07-12T01:41:43.730Z","dependencies_parsed_at":"2024-07-12T01:53:58.114Z","dependency_job_id":null,"html_url":"https://github.com/jspears/ts-arg","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jspears%2Fts-arg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jspears%2Fts-arg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jspears%2Fts-arg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jspears%2Fts-arg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jspears","download_url":"https://codeload.github.com/jspears/ts-arg/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250834140,"owners_count":21494918,"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":["argv","cli","command-line","decorators","node","typescripts"],"created_at":"2024-08-06T22:01:29.673Z","updated_at":"2025-04-25T14:32:07.884Z","avatar_url":"https://github.com/jspears.png","language":"TypeScript","funding_links":[],"categories":["cli"],"sub_categories":[],"readme":"TS-Arg\n===\nTool for making decorator based command line argument parsers.\nMore info [here](https://jspears.github.io/ts-arg/)\n\n## Installation\nTo use this tool you need to have \n``` \n\"experimentalDecorators\": true,  \n\"emitDecoratorMetadata\": true,\n``` \neither in your tsconfig.json or your command line parameters.\n\n![Node.js CI](https://github.com/jspears/ts-arg/workflows/Node.js%20CI/badge.svg)\n\n## Usage\nAdd the `@Arg` decorator to the class you want to use for your CLI.\n\n### Example\nSee a full example in [./example](./example)\n```ts static\nimport {Arg, configure} from \"ts-arg\";\n\nclass MyOptions {\n  \n   @Arg('do you want it to be chatty')\n   verbose:boolean;\n\n   @Arg({short:'T', description:'What is your T'})\n   tbone:string;\n\n   @Arg(\"A number of things\");\n   count:number;\n\n}\n\nconst opts = configure(new MyOptions);\n\n\n\n```\n\n### Configuration\nIf it doesn't quite do what you want checkout the possible options.\n```ts\n     \n    long?: string\n    short?: string,\n    description?: string,\n    required?: boolean,\n    default?: boolean,\n    type?: 'Boolean' | 'String' | 'Number' | 'Int' | 'JSON' | '[]' | any,\n    converter?: Converter,\n    itemType?: 'Boolean' | 'String' | 'Number' | 'Int' | 'JSON' | any,\n```\n\n### Application Style\nSometimes storing the parameters is desired, by labeling your class with\nthe `@Config` decorator, a few things happen.\n\n- All commands are prefixed with the \"argPrefix\" value which defaults to the \"prefix\" value which itself defaults to className.\n- ENV parameters are enabled allowing ENV properties to be read with the correct prefix.  Similar to the\n  `argPerfix` the `envPrefix` defaults to the `prefix` and then to the class name.\n- A configuration file is looked for, by default a JSON file (parser is specfiable).  The rcFile variable\n   is defaulted to the `.${prefix}`. value.\n- A property named `packagePrefix` which defaults to `prefix` is read from the current project's \n  package.json and attempts to set the current project. \n  \nExample:\n\n```ts \n#!/usr/bin/env node\n\nimport {configure, Config, Arg} from 'ts-arg';\n\n@Config(\"myapp\")\nclass MyOptions {\n  @Arg(\"verbosity on/off\")\n  verbose:boolean;\n\n  @Arg({description:\"Paths to look for\", default:true})\n  paths:string[]\n\n  @Arg()\n  name:string;\n \n}\nconsole.table(configure(new MyOption));\n\n\n```  \n       \nThen options can be provided via cli:\n```sh\n $ ./bin/myapp.js --myapp-name=stuff -v ./path/to/thing.\n```\nor they can be combined with ENV\n```sh\n $ MYAPP_VERBOSE=1 ./bin/myapp.js --myapp-name=stuff ./path/to/thing.\n```\nand it could be combined with `package.json`\n```json\n\n{\n\"name\": \"my-super-app\",\n\"myapp\": {\n    \"name\": \"stuff\",\n    \"paths\": [\"./src\",\"./test\"],\n    \"verbose\": true\n  }\n}\n\n```\nOr a dot file `.myapprc`\n```json\n{\n   \"paths\": [\"./src\",\"./test\"],\n   \"verbose\": true,\n   \"name\": \"stuff\"\n}\n\n\n```\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjspears%2Fts-arg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjspears%2Fts-arg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjspears%2Fts-arg/lists"}