{"id":15278611,"url":"https://github.com/jersou/clite-parser","last_synced_at":"2025-10-23T16:42:44.742Z","repository":{"id":218623340,"uuid":"746533848","full_name":"jersou/clite-parser","owner":"jersou","description":"CliteParser generates CLI from classes (or objects) : each method generates a \"command\", each field generates an \"option\"","archived":false,"fork":false,"pushed_at":"2024-11-07T23:30:24.000Z","size":751,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-20T23:05:26.191Z","etag":null,"topics":["args","class","cli","command-line-tool","deno","nodejs","parser"],"latest_commit_sha":null,"homepage":"","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/jersou.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2024-01-22T07:43:47.000Z","updated_at":"2024-11-07T23:30:16.000Z","dependencies_parsed_at":"2024-01-23T02:44:45.483Z","dependency_job_id":"fd724237-50e7-4fc2-a544-f681a046594c","html_url":"https://github.com/jersou/clite-parser","commit_stats":{"total_commits":67,"total_committers":2,"mean_commits":33.5,"dds":"0.014925373134328401","last_synced_commit":"64697ad89249bf40dfeb5635a9a044a8261eb7d6"},"previous_names":["jersou/clite-parser"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jersou%2Fclite-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jersou%2Fclite-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jersou%2Fclite-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jersou%2Fclite-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jersou","download_url":"https://codeload.github.com/jersou/clite-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252488962,"owners_count":21756242,"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":["args","class","cli","command-line-tool","deno","nodejs","parser"],"created_at":"2024-09-30T12:01:03.879Z","updated_at":"2025-10-23T16:42:44.736Z","avatar_url":"https://github.com/jersou.png","language":"TypeScript","readme":"# CLI lite parser for Node and Deno\n\n[![Clite-parser on NPM](https://img.shields.io/npm/v/clite-parser.svg)](https://npmjs.org/package/clite-parser)\n[![JSR](https://jsr.io/badges/@jersou/clite)](https://jsr.io/@jersou/clite)\n[![JSR Score](https://jsr.io/badges/@jersou/clite/score)](https://jsr.io/@jersou/clite)\n[![Built with the Deno Standard Library](https://img.shields.io/badge/Built_with_std-blue?logo=deno)](https://jsr.io/@std)\n\n**CliteParser generates CLI from classes** (or objects) : each field generates\nan \"option\", each method generates a \"command\" (positional arguments).\n\nJust write your tool as a class, and call Clite with it... Clite will\ndeserialize the command line in your class and launch the right methods or\ndisplay the help... Then you can optionally personalize the displayed help or\nadd aliases (for example) to complete your CLI.\n\n```typescript\n#!/usr/bin/env -S deno run\nimport { cliteRun } from \"jsr:@jersou/clite@0.7.7\";\n// or import { cliteRun } from \"@jersou/clite\"; // after \"deno add @jersou/clite\"\n// or import { cliteRun } from \"clite-parser\"; // after \"npm install clite-parser\" for Node usage\n\nclass Tool {\n  retry = 2; // 2 is the default value, overwrite by \"--retry 8\" by example\n  dryRun = false; // fields are converted to kebab case as global options\n  webUrl = \"none\"; // → --web-url\n\n  main() { // call if : $ ./example-lite-lite.ts main // or if $ ./example-lite-lite.ts\n    console.log(\"main command\", this);\n  }\n\n  up() { // call if : $ ./example-lite-lite.ts up\n    console.log(\"up command\", this);\n  }\n\n  down(force: boolean, timeout: number) { // call if : $ ./example-lite-lite.ts down true 14\n    console.log(\"down command\", { force, timeout }, this);\n  }\n}\n\ncliteRun(Tool); // or cliteRun(new Tool());\n```\n\n## The help is generated automatically:\n\n![help image](./simple-help.png)\n\n\u003c!-- Plain text (without color and styles in markdown):\n$ ./simple.ts --help\nUsage: \u003cTool file\u003e [Options] [--] [command [command args]]\n\nCommands:\n  main                   [default]\n  up\n  down \u003cforce\u003e \u003ctimeout\u003e\n\nOptions:\n -h, --help    Show this help [default: false]\n     --retry                      [default: 2]\n     --dry-run                [default: false]\n     --web-url               [default: \"none\"]\n--\u003e\n\n## Run the commands with options and arguments\n\n```shell\n#             ↓↓↓↓↓↓↓↓↓↓↓↓↓ options ↓↓↓↓↓↓↓↓↓↓↓↓  ↓ command ↓  ↓ cmd args ↓\n$ ./simple.ts --dry-run --web-url=tttt --retry 4     down        true  14\ndown command { force: true, timeout: 14 } Tool { retry: 4, dryRun: true, webUrl: \"tttt\" }\n\n$ ./simple.ts down true 14                     #  ↓↓↓  default options from class init  ↓↓↓\ndown command { force: true, timeout: 14 } Tool { retry: 2, webUrl: \"none\", no_color: undefined }\n\n$ ./simple.ts --dry-run --webUrl=tttt # ← same case of the field name works too : --webUrl or --web-url\nmain command Tool { retry: 2, dryRun: true, webUrl: \"tttt\" } # ← main is the default command\n\n$ deno https://raw.githubusercontent.com/jersou/clite-parser/refs/heads/main/examples/simple.ts --dry-run --web-url tttt --retry 4 down true  14\ndown command { force: true, timeout: 14 } Tool { retry: 4, dryRun: true, webUrl: \"tttt\" }\n```\n\n## Examples\n\nSeveral examples can be found in the [examples/](./examples) folder.\n\n### Full example with decorators (Typescript)\n\nWorks with vanilla typescript or with experimentalDecorators = true\n\n```typescript\nimport { alias, cliteRun, help } from \"jsr:@jersou/clite@0.7.7\";\n\n@help(\"This tool is a little example of CliteParser\") // optional description\nclass Tool {\n  @alias(\"r\") // optional alias -r for --retry\n  retry = 2;\n  @help(\"no changes mode\") // optional description for \"--dry-run\" field\n  dryRun = false; // fields are converted to kebab case as global options\n  webUrl = \"none\"; // → --web-url\n\n  main() {\n    console.log(\"main command\", this);\n  }\n\n  @help(\"create and start\") // optional description for \"up\" command\n  up() {\n    console.log(\"up command\", this);\n  }\n\n  down(force: boolean, timeout: number) {\n    console.log(\"down command\", { force, timeout }, this);\n  }\n}\n\ncliteRun(Tool); // or cliteRun(new Tool());\n```\n\nThe help is generated automatically:\n\n![help image](./with-decorators-help.png)\n\n\u003c!-- Plain text (without color and styles in markdown):\n$ ./with-decorators.ts --help\nThis tool is a little example of CliteParser\n\nUsage: \u003cTool file\u003e [Options] [--] [command [command args]]\n\nCommands:\n  main                   [default]\n  up                     create and start\n  down \u003cforce\u003e \u003ctimeout\u003e\n\nOptions:\n -h, --help    Show this help  [default: false]\n -r, --retry                       [default: 2]\n     --dry-run no changes mode [default: false]\n     --web-url                [default: \"none\"]\n--\u003e\n\n### Full example without decorator (Javascript)\n\n```javascript\nimport { cliteRun } from \"jsr:@jersou/clite@0.7.7\";\n\nclass Tool {\n  _help = \"This tool is a little example of CliteParser\"; // optional description\n\n  _retry_alias = \"r\"; // optional alias -r for --retry\n  retry = 2;\n  _dryRun_help = \"no changes mode\"; // optional description for \"--dry-run\" field\n  dryRun = false; // fields are converted to kebab case as global options\n  webUrl = \"none\"; // → --web-url\n\n  main() {\n    console.log(\"main command\", this);\n  }\n\n  _up_help = \"create and start\"; // optional description for \"up\" command\n  up() {\n    console.log(\"up command\", this);\n  }\n\n  down(force, timeout) {\n    console.log(\"down command\", { force, timeout }, this);\n  }\n}\n\ncliteRun(Tool); // or cliteRun(new Tool());\n```\n\nThe help is generated automatically (same as the previous):\n\n![help image](./without-decorator-help.png)\n\n\u003c!--  Plain text (without color and styles in markdown):\n./without-decorator.mjs --help\nThis tool is a little example of CliteParser\n\nUsage: \u003cTool file\u003e [Options] [--] [command [command args]]\n\nCommands:\n  main                   [default]\n  up                     create and start\n  down \u003cforce\u003e \u003ctimeout\u003e\n\nOptions:\n -h, --help    Show this help  [default: false]\n -r, --retry                       [default: 2]\n     --dry-run no changes mode [default: false]\n     --web-url                [default: \"none\"]\n--\u003e\n\n## `cliteRun()` usage\n\n`cliteRun()` function takes an object or a class as input, and an optional\nconfig, see [CliteRunConfig](#CliteRunConfig) chapter bellow.\n\nExemple : `cliteRun(Tool)` or `cliteRun(new Tool())` or\n`cliteRun(Tool, { noCommand: true })`\n\n## `cliteParse()` usage\n\nSame as `cliteRun()`, but it doesn't run the command, it returns the parsing\n`CliteResult` that contains:\n\n- obj: The input object overwritten with the data from the parsing result\n- command: The command to run from the parsing result\n- commandArgs: The command arguments from the parsing result\n- config: The input CliteRunConfig\n- help: The generated help\n- subcommand: The subcommand CliteResult if the command is a subcommand\n\n## Ignore `_*` and `#*` methods and fields (in the help)\n\nFields and methods that start with \"_\" are ignored.\n\n```typescript\n_privateData = 12;\n_privateMethod() {\n  console.log(\"this method is not visible in the help (starts with '_')\");\n}\n```\n\nNote: this \"private\" method can be run by the CLI, it's useful during the\ndevelopment.\n\nNote2: js private fields `#*` are also ignored :\n\n```typescript\n#privateData = 12;\n#privateMethod() {\n  console.log(\"this method is not visible in the help (starts with '#')\");\n}\n```\n\n## Decorator `@*` or field `_\u003cfield name\u003e_*`\n\nFields and methods can be extended with description, type or aliases using\ndecorators or `_\u003cfield name\u003e_*` field. Decorator don't work with Javascript (not\nin the language) !\n\nIn summary :\n\n- `@help(description: string)` | `_\u003cfield\u003e_help` : add description on\n  class/methods/fields to display in the help\n- `@alias(alias: string)` | `_\u003cfield\u003e_alias` : add alias on method (`-n` for\n  example)\n- `@type(typeHelp: string)` | `_\u003cfield\u003e_type` : type to display in the help\n- `@negatable(help: string | boolean = true)` | `_\u003cfield\u003e_negatable`: enable\n  `--no-\u003coption\u003e` (`--no-dry-run` for example)\n- `@defaultHelp(defaultHelp: string)` | `_\u003cfield\u003e_default` : default to display\n  in the help\n- `@usage(usage: string)` | `_\u003cfield\u003e_usage` : tool usage to display in the help\n- `@hidden()` | `_\u003cfield\u003e_hidden`: to hide in the help\n- `@subcommand()` | `_\u003cfield\u003e_subcommand` : use this field as a subcommand\n- `@noCommand()` | `_\u003cfield\u003e_no_command` : the tool have no command (only the\n  main), process all positional arguments as main() args\n\n### Help description with the `@help` decorator or inline help\n\n```typescript\nimport { cliteRun, help } from \"jsr:@jersou/clite@0.7.7\";\n\n@help(\"This tool is a little example of CliteParser\")\nclass Tool {\n  retry = 2;\n  webUrl = \"none\"; // fields are converted to kebab case as global options\n\n  @help(\"skip colorize\") // optional description for \"no_color\" field\n  no_color?: string | boolean; // → --no-color\n\n  main() {\n    console.log(\"main command\", this);\n  }\n\n  @help(\"create and start\") // optional description for \"up\" command\n  up() {\n    console.log(\"up command\", this);\n  }\n\n  down(force: boolean, timeout: number) {\n    console.log(\"down command\", { force, timeout }, this);\n  }\n}\n\ncliteRun(Tool);\n```\n\nWithout decorator : optional fields `_\u003cfiled or method name\u003e_help` are displayed\nas description in the help :\n\n```typescript\n#!/usr/bin/env -S deno run -A\nimport { cliteRun } from \"jsr:@jersou/clite@0.7.7\";\n\nclass Tool {\n  _help = \"This tool is a little example of CliteParser\"; // optional description\n  retry = 2;\n  webUrl = \"none\"; // fields are converted to kebab case as global options\n  no_color?: string | boolean; // → --no-color\n  _no_color_help = \"skip colorize\"; // optional description for \"no_color\" field\n  _up_help = \"create and start\"; // optional description for \"up\" command\n\n  main() {\n    console.log(\"main command\", this);\n  }\n\n  up() {\n    console.log(\"up command\", this);\n  }\n\n  down(force: boolean, timeout: number) {\n    console.log(\"down command\", { force, timeout }, this);\n  }\n}\n\nif (import.meta.main) { // if the file is imported, do not execute this block\n  cliteRun(Tool);\n}\n```\n\n### Alias\n\nAlias of option can be created, with the `@alias` decorator or with\n`_\u003cfield name\u003e_alias` :\n\n```typescript\n#!/usr/bin/env -S deno run -A\nimport { cliteRun } from \"../clite_parser.ts\";\nimport { alias, help, type } from \"../src/decorators.ts\";\n\nclass Tool {\n  @alias(\"a\")\n  all?: boolean;\n  @alias(\"r\")\n  retry = 2;\n  @alias(\"w\")\n  webUrl = \"none\";\n\n  @alias(\"nb\")\n  @alias(\"n\")\n  @help(\"n \u0026 b\")\n  @type(\"boolean\")\n  no_color?: string | boolean;\n\n  main() {\n    console.log(\"main command\", this);\n  }\n}\n```\n\nProduce the help :\n\n```\n...\nOptions:\n       -h, --help     Show this help [default: false]\n       -a, --all\n       -r, --retry                       [default: 2]\n       -w, --web-url                [default: \"none\"]\n -n, --nb, --no-color n \u0026 b                 [boolean]\n```\n\nShort parameters can be aggregated, `-an` here :\n\n```\n$ ./alias-with-decorator.ts -an -r 8\nmain command Tool { all: true, retry: 8, webUrl: \"none\", no_color: true }\n```\n\n`-an` = `-a -n`\n\nExample without the @alias decorator :\n\n```typescript\nclass Tool {\n  _all_alias = \"a\";\n  all?: boolean;\n  _retry_alias = \"r\";\n  retry = 2;\n  _webUrl_alias = \"w\";\n  webUrl = \"none\";\n\n  _no_color_alias = [\"nb\", \"n\"];\n  _no_color_help = \"n \u0026 b\";\n  _no_color_type = \"boolean\";\n  no_color?: string | boolean;\n\n  main() {\n    console.log(\"main command\", this);\n  }\n}\n```\n\n### `@subcommand` decorator and `_*_subcommand`\n\nUse the field (class or object) as a subcommand :\n\nFull exemple in [examples/git-subcommand.ts](examples/git-subcommand.ts)\n\n```typescript\n// → \u003cTool\u003e [--dry-run] [ [up [--watch] \u003ccount\u003e] | [down [--volumes] \u003cforce\u003e \u003ctimeout\u003e] ]\nclass Up {\n  _clite_parent?: Tool;\n  watch = false;\n  main(_count: number) {\n    console.log(\"Up\", this);\n  }\n}\n\nclass Tool {\n  dryRun = false;\n\n  @subcommand()\n  up = Up;\n\n  @subcommand()\n  down = {\n    volumes: false,\n    main(force: boolean, timeout: number) {\n      console.log(\"Down\", this);\n    },\n  };\n}\n\ncliteRun(new Tool());\n```\n\n```\n./subcommand.ts --help\nUsage: \u003cTool file\u003e [Options] [--] [command [command args]]\n\nCommands:\n  up --help | [sub Options / cmd / args]\n  down --help | [sub Options / cmd / args]\n\nOptions:\n -h, --help    Show this help [default: false]\n     --dry-run                [default: false]\n     --down         [default: [object Object]]\n\n$ ./subcommand.ts down --help\nUsage: \u003cObject file\u003e [Options] [--] [command [command args]]\n\nCommand:\n  main \u003cforce\u003e \u003ctimeout\u003e [default]\n\nOptions:\n -h, --help    Show this help [default: false]\n     --volumes                [default: false]\n```\n\n### @jsonConfig decorator and `_json_config`\n\nEnable configCli: see \"configCli\" chapter below :\n\n`enable \"--config \u003cpath|json string\u003e\" to load json config, Show in the help if it's a string`\n\nIf the value is a string, it will be used in the help for \"--config\"\ndescription.\n\n## Argument parsing\n\nClite use [@std/cli](https://jsr.io/@std/cli/doc/parse-args), based on\n[minimist](https://github.com/minimistjs/minimist).\n\n### Kebab case or the same name\n\nExample : `webUrl` field can be set by `--webUrl` or `--web-url`:\n\n```\n$ ./simple.ts --web-url test \nmain command Tool { retry: 2, dryRun: false, webUrl: \"test\" }\n\n$ ./simple.ts --webUrl test\nmain command Tool { retry: 2, dryRun: false, webUrl: \"test\" }\n```\n\n### several ways to pass parameters\n\nFor example, for an option `-l, --out-limit` from a field `outLimit` with an\nalias `l` :\n\n- `-l=8`\n- `-l 8`\n- `-l8`\n- `--out-limit 8`\n- `--out-limit=8`\n- `--outLimit 8`\n- `--outLimit=8`\n\nAre equivalent.\n\n### Passing boolean\n\n```shell\n$ ./example-lite.ts\nmain command Tool { retry: 2, webUrl: \"none\", no_color: undefined }\n$ ./example-lite.ts --no-color\nmain command Tool { retry: 2, webUrl: \"none\", no_color: true }\n$ ./example-lite.ts --no-color=false\nmain command Tool { retry: 2, webUrl: \"none\", no_color: \"false\" }\n$ ./example-lite.ts --no-color=true\nmain command Tool { retry: 2, webUrl: \"none\", no_color: \"true\" }\n```\n\n### Passing arrays :\n\nUse several times an option will fill the field if it's an array :\n\n```\nclass Tool {\n  @alias(\"a\")\n  arr: string[] = [];\n  ...\n}\n$ ./Tool.ts --arr=aa --arr bb -a=cc -a dd --a ee\n→ arr === [\"aa\", \"bb\", \"cc\", \"dd\", \"ee\"]\n```\n\n### Passing objects :\n\nObject can be deserialized :\n\n```\n--ac.bb aaa --ac.dd.ee v --ac.dd.ff w\n```\n\nwill fill `ac` field with\n\n```\n{ bb: \"aaa\", dd: { ee: \"v\", ff: \"w\" }\n```\n\nExample :\n\n```\nclass Tool {\n  ac = {};\n  ...\n}\n$ ./Tool.ts --ac.bb aaa --ac.dd.ee v --ac.dd.ff w\n→ ac === { bb: \"aaa\", dd: { ee: \"v\", ff: \"w\" } })\n```\n\n### The default command\n\n- If there is only one method/subcommand =\u003e this method is the default\n- If the main method exist =\u003e main is the default\n- else =\u003e no default method\n\n```shell\n$ ./example-lite.ts\nmain command Tool { retry: 2, webUrl: \"none\", no_color: undefined }\n```\n\n## CliteRunConfig\n\n`cliteRun(Tool, \u003c optional CliteRunConfig \u003e )`\n\n```typescript\ntype CliteRunConfig = {\n  args?: string[]; // default : Deno.args or process.argv.slice(2)\n  dontPrintResult?: boolean; // default false : false, print the command return\n  noCommand?: boolean; // no default command : do not run \"main\" methode if no arg\n  printHelpOnError?: boolean; // print the help if an error is thrown and then re-throw the error\n  mainFile?: string; // allows to change the name of the file in the help, instead of the default \u003c{Class name} file\u003e\n  meta?: ImportMeta; // import.meta to use : don't run if the file is imported, and use import.meta.url in the help\n  configCli?: boolean; // enable \"--config \u003cpath|json string\u003e\" to load json config, Show in the help if it's a string\n  dontConvertCmdArgs?: boolean; // don't convert \"true\"/\"false\" to true/false in command arguments, and not to number after --\n};\n```\n\n### Return value\n\nIf the method run by `cliteRun` return a value != undefined, it will be print in\nstdout. If it's a promise, the result of the promise will be awaited.\n\nThis behavior can be disabled with the config :\n`cliteRun(Tool, { dontPrintResult: true })`\n\n### noCommand\n\nNo command in the command line → all positional argument are used as arguments\nof the command.\n\nThe default command is used.\n\n`cliteRun(Tool, { noCommand: true });` → `./example-no-command.ts ---help` give\n:\n\n```\nThis tool is a \"no-command\" example of CliteParser usage\n\nUsage: \u003cTool file\u003e [Options] [--] [args]\n\nOptions:\n  --retry=\u003cRETRY\u003e        (default \"2\")\n  --web-url=\u003cWEB_URL\u003e    web URL ... (default \"none\")\n  --no-color=\u003cNO_COLOR\u003e  skip colorize\n  --help                 Show this help\n```\n\n## Print the help on error\n\nIf printHelpOnError is enabled, the help is print if any error is thrown while\nthe command execution. Else, the help is print only for errors that have\n`{ cause: { clite: true } }`.\n\nIt's useful if a required option is missing, for example.\n\n```typescript\nimport { cliteRun } from \"jsr:@jersou/clite@0.7.7\";\nexport class Tool {\n  throw = \"true\";\n  main() {\n    if (this.throw === \"true\") {\n      throw new Error(\"add --throw=false option !\");\n    }\n    console.log(\"OK !\");\n  }\n}\ncliteRun(Tool, { printHelpOnError: true });\n```\n\nTo print help on specific error only, without `printHelpOnError=true`, use\n`{ cause: { clite: true } }` :\n\n```typescript\nimport { cliteRun } from \"jsr:@jersou/clite@0.7.7\";\nexport class Tool {\n  noThrow = false;\n\n  main() {\n    if (!this.noThrow) {\n      throw new Error(\"add --no-throw option !\", { cause: { clite: true } });\n    }\n    console.log(\"OK !\");\n  }\n}\ncliteRun(Tool);\n```\n\n### configCli : load a json config with `--config \u003cpath | or json string\u003e`\n\nIf `configCli === true` in the CliteRunConfig or `@jsonConfig` is used or\n`_json_config = true`\n\n```\n$ cat ./load-config.ts\n...\ncliteRun(Tool, { configCli: true });\n\n$ ./load-config.ts --help\n...\n     --config  Use this json file or string to read the options [string]\n...\n\n$ ./load-config.ts  down\ndown command { force: undefined, timeout: undefined } Tool { retry: 2, dryRun: false, webUrl: \"none\", config: undefined }\n\n$ cat load-config.json\n{ \"retry\": 44, \"dryRun\": true, \"webUrl\": \"yyy\" }\n\n$ ./load-config.ts --retry 88 --config ./load-config.json down\ndown command { force: undefined, timeout: undefined } Tool {\n  retry: 88,\n  dryRun: true,\n  webUrl: \"yyy\",\n  config: \"./load-config.json\"\n}\n```\n\n### mainFile\n\nAllows to change the name of the file in the help, instead of the default for\nexample `\u003cTool file\u003e`.\n\n```typescript\ncliteRun(Tool, { mainFile: \"my-tool\" });\n```\n\n...will change the usage line in the help :\n\n```\nUsage: my-tool [Options] [--] [command [command args]]\n```\n\n### meta\n\nUse meta to avoid the manual `import.meta.main` check :\n\n```typescript\nif (import.meta.main) { // if the file is imported, do not execute this block\n  cliteRun(Tool);\n}\n```\n\nis equivalent to :\n\n```typescript\ncliteRun(Tool, { meta: import.meta });\n```\n\nThe basename of `import.meta.url` will be used in the generated help, as\n`mainFile`.\n\nThis feature doesn't work with Node (no import.meta.main).\n\n### dontConvertCmdArgs\n\nIf `--` is used and `dontConvertCmdArgs=true`, all command arguments will be\nstrings.\n\n```\n# with dontConvertCmdArgs: true\n$ ./Tool.ts -- main 123 true foo\n → command = main\n → commandArgs = [\"123\", \"true\", \"foo\"]);\n\n# with dontConvertCmdArgs: false (the default)\n$ ./Tool.ts -- main 123 true foo\n → command = main\n → commandArgs = 123, true, \"foo\"]);\n```\n\n## Plain Object\n\nA plain JS Object can be used :\n\n```typescript\nimport { cliteRun } from \"jsr:@jersou/clite@0.7.7\";\n\ncliteRun({\n  retry: 2,\n  main() {\n    console.log(\"main command\", this);\n  },\n  _up_help: \"create and start the services\",\n  up(svc: string, timeout = 10) {\n    console.log(\"up command\", { svc, timeout, retry: this.retry });\n  },\n  down(svc: string) {\n    console.log(\"down command\", { svc, retry: this.retry });\n  },\n});\n```\n\n```shell\n$ ./plain_object_lite.ts --retry=77 up foo 123\nup command { svc: \"foo\", timeout: 123, retry: 77 }\n\n$ /plain_object_lite.ts --help\nUsage: \u003cObject file\u003e [Options] [--] [command [command args]]\n\nCommands:\n  main               [default]\n  up \u003csvc\u003e \u003ctimeout\u003e create and start the services\n  down \u003csvc\u003e\n\nOptions:\n -h, --help  Show this help [default: false]\n     --retry                    [default: 2]\n```\n\n## Node support : `npm install clite-parser` or `npx jsr add @jersou/clite`\n\n### From NPM : `npm install clite-parser`\n\nRun `npm install clite-parser` and then, import with\n`import { cliteRun } from \"clite-parser\";` :\n\n```javascript\nimport { cliteRun } from \"clite-parser\"; // after \"npm install clite-parser\"\nclass Tool { ... }\ncliteRun(Tool);\n```\n\nSee node usage examples :\n\n- [examples/node-npm/dax](examples/node-npm/dax)\n- [examples/node-npm/simple](examples/node-npm/simple)\n- [examples/node-npm/zx](examples/node-npm/zx)\n\n### From JSR : `npx jsr add @jersou/clite`\n\nRun `npx jsr add @jersou/clite` and then, import with\n`import { cliteRun } from \"@jersou/clite\";` :\n\n```javascript\nimport { cliteRun } from \"@jersou/clite\"; // after \"npx jsr add @jersou/clite\"\nclass Tool { ... }\ncliteRun(Tool);\n```\n\n### Node usage examples :\n\n- [examples/node-jsr/dax](examples/node-jsr/dax)\n- [examples/node-jsr/simple](examples/node-jsr/simple)\n- [examples/node-jsr/zx](examples/node-jsr/zx)\n\n## Links\n\n- https://jsr.io/@jersou/clite\n- https://github.com/jersou/clite-parser\n- https://www.npmjs.com/package/clite-parser\n\n## Dependencies (all)\n\n- `@std/cli` : to parse args\n- `@std/fmt` : to log with colors/bold\n- `@std/text` : to change the option case\n- `@std/assert` : for the tests\n\n## Inspiration\n\nProbably inspired by:\n\n- [Bash-utils](https://github.com/jersou/bash-utils#principes) : run bash\n  function from CLI with `utils:run \"$@\"`, created 4 years before Clite,\n- and by [Clap](https://github.com/clap-rs/clap) (with the derive feature) after\n  the development of [mouse-actions](https://github.com/jersou/mouse-actions)\n  (one year before Clite) : deserialize options from CLI to struct.\n\n## Try in a browser\n\nWith [esm.sh](https://code.esm.sh/),\n[playcode.io](https://playcode.io/javascript),\n[jsfiddle.net](https://jsfiddle.net/)) :\n\n```javascript\nimport { cliteParse } from \"https://esm.sh/jsr/@jersou/clite@0.7.7\";\n\nclass Tool {\n  opt = 123;\n  main() {}\n}\n\nconst res = cliteParse(Tool, { args: [\"--opt\", \"78\"] });\nconsole.log(res);\n```\n\n## Comparison with other tools : Yargs, @std/cli (minimist)\n\nThe usual tools rather take a particular configuration of the tool and produce\nan output data **without** a defined model. You need to learn their API to\ndefine the interface you want.\n\n**Clite follows a different approach: it takes the desired model and fills it\naccording to the command line**. If you want to type the parsing output, you\ndon't need to do anything else. No duplicate writing for the CLI config and the\nparsing output model/type.\n\nAnd of course, like classic tools, it also generates the help automatically,\ndetects the non-existent option/order errors, and launches the desired command\nwith its parameters.\n\nA comparison try is made in the\n[examples/cli-tools-diff](examples/cli-tools-diff) folder, it compares :\n\n- Clite : [examples/cli-tools-diff/clite.ts](examples/cli-tools-diff/clite.ts)\n- vs [Yargs](https://github.com/yargs/yargs) :\n  [examples/cli-tools-diff/yargs.ts](examples/cli-tools-diff/yargs.ts)\n- vs [@std/cli](https://jsr.io/@std/cli/doc/parse-args) based on\n  [minimist](https://github.com/minimistjs/minimist) :\n  [examples/cli-tools-diff/std-cli.ts](examples/cli-tools-diff/std-cli.ts)\n\nThese 3 files provide the same CLI :\n\n```\nUsage: \u003cTool file\u003e [Options] [--] [command [command args]]\n\nCommands:\n  main                   [default]\n  up                     create and start\n  down \u003cforce\u003e \u003ctimeout\u003e\n\nOptions:\n -h, --help    Show this help  [default: false]\n -r, --retry                       [default: 2]\n -n, --dry-run no changes mode [default: false]\n     --web-url web url        [default: \"none\"]\n```\n\nThe 3 implementations side by side :\n\n[![diff-600.png](examples/cli-tools-diff/diff-600.png)](examples/cli-tools-diff/diff.png)\n\n## Real case\n\n- The project\n  [Studio-Pack-Generator](https://github.com/jersou/studio-pack-generator) use\n  clite and have\n  [lots of CLI options](https://github.com/jersou/studio-pack-generator?tab=readme-ov-file#cli-usage)\n  generated from\n  [a rather understandable file](https://github.com/jersou/studio-pack-generator/blob/main/studio_pack_generator.ts)\n  (in my opinion, of course).\n- simpler example : [examples/dcpps.ts](examples/dcpps.ts)\n- even simpler : [examples/dcpm.ts](examples/dcpm.ts)\n","funding_links":[],"categories":["Modules"],"sub_categories":["CLI utils"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjersou%2Fclite-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjersou%2Fclite-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjersou%2Fclite-parser/lists"}