{"id":22070014,"url":"https://github.com/tashuo/yargs-example","last_synced_at":"2025-03-23T18:45:10.131Z","repository":{"id":177225474,"uuid":"660099171","full_name":"tashuo/yargs-example","owner":"tashuo","description":"yargs + typescript example","archived":false,"fork":false,"pushed_at":"2023-06-29T09:07:12.000Z","size":38,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-05T02:37:23.617Z","etag":null,"topics":["command","console","decorator","nodejs","typescript","yargs"],"latest_commit_sha":null,"homepage":"","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/tashuo.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":"2023-06-29T08:39:21.000Z","updated_at":"2023-07-01T04:00:09.000Z","dependencies_parsed_at":"2023-07-07T04:00:23.380Z","dependency_job_id":null,"html_url":"https://github.com/tashuo/yargs-example","commit_stats":null,"previous_names":["tashuo/yargs-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tashuo%2Fyargs-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tashuo%2Fyargs-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tashuo%2Fyargs-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tashuo%2Fyargs-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tashuo","download_url":"https://codeload.github.com/tashuo/yargs-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245153211,"owners_count":20569400,"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":["command","console","decorator","nodejs","typescript","yargs"],"created_at":"2024-11-30T20:14:26.339Z","updated_at":"2025-03-23T18:45:10.114Z","avatar_url":"https://github.com/tashuo.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"yargs \u0026\u0026 typescript examples\n\n使用`yargs`做的一个简单的todo-list命令行工具，主要熟悉`yargs`在`typescript`+`node`环境下的使用及装饰器的使用\n\n## install\n```shell\n$ npm install -g typescript ts-node\n$ git clone git@github.com:tashuo/yargs-example.git\n$ cd yargs-example \u0026\u0026 npm install\n```\n\n## run\n### show all commands\n```shell\n$ ts-node app.ts --help\n```\n\n### add todo\n```shell\n$ ts-node app.ts add -t first -b xd # yargs Option\n$ ts-node app.ts add2 second xdd # yargs PositionalOptions, 使用了装饰器\n```\n\n### list todos\n```shell\n$ ts-node app.ts all\n$ ts-node app.ts all2:all2 # 使用了装饰器\n```\n\n### delete todo\n```shell\n$ ts-node app.ts remove -t first\n```\n\n## how it works\n### basic.command.ts\n`basicCommand`函数中的增删改查命令使用的常规的yargs声明及初始化方式，使用`parseAsync`解析中运行时的参数对其进行处理\n\n### test.command.ts\n`TestCommand`类使用了`yargs.CommandModule`，定义好必要的属性后注册到`yargs`中即可生效，参数的定义和解析处理分别在方法`builder`和`handler`中完成\n\n### 装饰器\n`decorator.ts`文件定义了一个类装饰器`Commands`和方法装饰器`Command`，`app.ts`入口中使用`scanner`模拟扫描`decorator.command.ts`中所有的类进行处理；\n\n`@Command`定义单个命令；\n\n`@Commands`定义多个命令，当一个类使用该装饰器时，会自动将所有方法注册为命令，具体可查看代码`Scanner.scan()`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftashuo%2Fyargs-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftashuo%2Fyargs-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftashuo%2Fyargs-example/lists"}