{"id":26445235,"url":"https://github.com/zackiles/module-to-cli","last_synced_at":"2025-03-18T11:16:21.519Z","repository":{"id":281648547,"uuid":"945943286","full_name":"zackiles/module-to-cli","owner":"zackiles","description":"Invoke methods on a plain Typescript file through your terminal.","archived":false,"fork":false,"pushed_at":"2025-03-10T11:27:35.000Z","size":260,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-10T12:29:17.943Z","etag":null,"topics":[],"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/zackiles.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","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":"2025-03-10T11:19:33.000Z","updated_at":"2025-03-10T11:27:38.000Z","dependencies_parsed_at":"2025-03-10T12:41:29.101Z","dependency_job_id":null,"html_url":"https://github.com/zackiles/module-to-cli","commit_stats":null,"previous_names":["zackiles/module-to-cli"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fmodule-to-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fmodule-to-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fmodule-to-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zackiles%2Fmodule-to-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zackiles","download_url":"https://codeload.github.com/zackiles/module-to-cli/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244207742,"owners_count":20416109,"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":[],"created_at":"2025-03-18T11:16:20.873Z","updated_at":"2025-03-18T11:16:21.512Z","avatar_url":"https://github.com/zackiles.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Module to CLI\n\n[![JSR](https://jsr.io/badges/@deno-kit/module-to-cli)](https://jsr.io/@deno-kit/module-to-cli)\n[![JSR Score](https://jsr.io/badges/@deno-kit/module-to-cli/score)](https://jsr.io/@deno-kit/module-to-cli)\n[![JSR Scope](https://jsr.io/badges/@deno-kit)](https://jsr.io/@deno-kit)\n\n\u003e Invoke methods on a plain TypeScript file through your terminal\n\nModule to CLI automatically generates a command-line interface for your TypeScript modules. It uses static analysis to detect exported functions, classes, and methods, making them accessible from the terminal with proper argument parsing and help menus.\n\n## Installation\n\n```bash\n# Install from JSR\ndeno add @deno-kit/module-to-cli\n\n# Or use directly via import\nimport moduleToCLI from \"@deno-kit/module-to-cli\";\n```\n\n## Quick Start\n\nLet's say you have a TypeScript module like this:\n\n```typescript\n// math.ts\n/**\n * A collection of math utilities\n */\nexport function add(a: number, b: number): number {\n  return a + b;\n}\n\n/**\n * Math class with various operations\n */\nexport class Calculator {\n  /**\n   * Multiplies two numbers\n   * @param a First number\n   * @param b Second number\n   */\n  multiply(a: number, b: number): number {\n    return a * b;\n  }\n  \n  /**\n   * Raises a number to a power\n   * @param base The base number\n   * @param exponent The exponent\n   */\n  static power(base: number, exponent: number): number {\n    return Math.pow(base, exponent);\n  }\n}\n```\n\nYou can now run methods from this module:\n\n```bash\n# Run a top-level function\ndeno run -A @deno-kit/module-to-cli math.ts add --a=5 --b=3\n\n# Run a static class method\ndeno run -A @deno-kit/module-to-cli math.ts Calculator.power --base=2 --exponent=8\n\n# Run an instance method (with constructor arguments)\ndeno run -A @deno-kit/module-to-cli math.ts Calculator.multiply --a=6 --b=7 --constructor.any=value\n```\n\n## Full Usage\n\nBelow is an expanded example that demonstrates the full capability of the library:\n\n```typescript\n// util.ts\n/**\n * Utility library with various helpers\n * @module Utilities\n */\n\n/**\n * Formats a string with provided values\n * @param template String template with {placeholders}\n * @param values Values to inject into the template\n * @returns Formatted string\n */\nexport function format(template: string, values: Record\u003cstring, string\u003e): string {\n  return template.replace(/{(\\w+)}/g, (_, key) =\u003e values[key] || '');\n}\n\n/**\n * HTTP client with various methods\n */\nexport class HttpClient {\n  private baseUrl: string;\n  private headers: Record\u003cstring, string\u003e;\n  \n  /**\n   * Create a new HTTP client\n   * @param baseUrl The base URL for all requests\n   * @param headers Default headers to include\n   */\n  constructor(baseUrl: string, headers: Record\u003cstring, string\u003e = {}) {\n    this.baseUrl = baseUrl;\n    this.headers = headers;\n  }\n  \n  /**\n   * Send a GET request to the specified endpoint\n   * @param endpoint The API endpoint\n   * @param params Optional query parameters\n   * @returns The response data\n   */\n  async get(endpoint: string, params?: Record\u003cstring, string\u003e): Promise\u003cunknown\u003e {\n    const url = new URL(endpoint, this.baseUrl);\n    if (params) {\n      Object.entries(params).forEach(([key, value]) =\u003e {\n        url.searchParams.append(key, value);\n      });\n    }\n    \n    const response = await fetch(url, { headers: this.headers });\n    return response.json();\n  }\n  \n  /**\n   * Create a pre-configured client\n   * @param config Client configuration\n   */\n  static createClient(config: { url: string, timeout: number }): HttpClient {\n    return new HttpClient(config.url, { 'Timeout': config.timeout.toString() });\n  }\n}\n```\n\nNow you can use the CLI to interact with these methods:\n\n```bash\n# Get help for the module\ndeno run -A @deno-kit/module-to-cli util.ts --help\n\n# Format a string\ndeno run -A @deno-kit/module-to-cli util.ts format --template=\"Hello, {name}!\" --values='{\"name\":\"World\"}'\n\n# Create an HTTP client instance and call a method\ndeno run -A @deno-kit/module-to-cli util.ts HttpClient.get --endpoint=\"/api/users\" --params='{\"limit\":\"10\"}' --constructor.baseUrl=\"https://api.example.com\" --constructor.headers='{\"Authorization\":\"Bearer token\"}'\n\n# Use a static method to create a client\ndeno run -A @deno-kit/module-to-cli util.ts HttpClient.createClient --config='{\"url\":\"https://api.example.com\", \"timeout\":5000}'\n```\n\nThe CLI automatically:\n\n- Parses arguments based on method signatures\n- Converts string inputs to appropriate types (numbers, booleans, objects)\n- Provides help text from JSDoc comments\n- Handles both top-level functions and class methods\n- Supports constructor arguments for instance methods\n\n## Generate Mode\n\nThe library also provides a \"generate\" mode that outputs a JSON or text-based specification of a module:\n\n```bash\n# Generate a specification in text format\ndeno run -A @deno-kit/module-to-cli generate util.ts\n\n# Generate a specification in JSON format\ndeno run -A @deno-kit/module-to-cli generate util.ts --json\n```\n\n\u003e **Example outputs:** You can view sample outputs in [simple-module.golden.txt](https://github.com/zackiles/module-to-cli/blob/main/test/mocks/simple-module.golden.txt) (text format) and [simple-module.golden.jsonc](https://github.com/zackiles/module-to-cli/blob/main/test/mocks/simple-module.golden.jsonc) (JSON format).\n\nThis specification describes all exported functions, classes, methods, parameters, and return types found in the module. The schema represents what the library uses internally to create the CLI interface and help menus.\n\nThis feature is useful for:\n\n- Testing that your module is correctly parsed\n- Creating your own documentation\n- Understanding the structure of a module\n- Generating custom interfaces for your modules\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackiles%2Fmodule-to-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzackiles%2Fmodule-to-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzackiles%2Fmodule-to-cli/lists"}