{"id":21533631,"url":"https://github.com/dubisdev/cerebro-command-router","last_synced_at":"2025-03-17T19:44:11.037Z","repository":{"id":45931610,"uuid":"388533415","full_name":"dubisdev/cerebro-command-router","owner":"dubisdev","description":"A tool for CerebroApp developers","archived":false,"fork":false,"pushed_at":"2022-07-06T14:14:37.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T10:40:49.617Z","etag":null,"topics":["cerebro-plugin","cerebroapp","tool"],"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/dubisdev.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":"2021-07-22T16:45:58.000Z","updated_at":"2023-02-28T10:25:35.000Z","dependencies_parsed_at":"2022-08-28T20:20:14.349Z","dependency_job_id":null,"html_url":"https://github.com/dubisdev/cerebro-command-router","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubisdev%2Fcerebro-command-router","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubisdev%2Fcerebro-command-router/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubisdev%2Fcerebro-command-router/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubisdev%2Fcerebro-command-router/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dubisdev","download_url":"https://codeload.github.com/dubisdev/cerebro-command-router/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244101572,"owners_count":20398356,"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":["cerebro-plugin","cerebroapp","tool"],"created_at":"2024-11-24T02:33:54.324Z","updated_at":"2025-03-17T19:44:11.019Z","avatar_url":"https://github.com/dubisdev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cerebro-Command-Router\n\n\u003e A tool for CerebroApp developers\n\n## What's cerebro-command-router?\n\nThis is a utility for developing cerebro plugins.\n\n## Install \u0026 Use\n\n### Install the package in your project:\n\n```sh\nnpm install cerebro-command-router\n# or\nyarn add cerebro-command-router\n```\n\n## Initial configuration\n\n### **Import the CerebroRouter utility:**\n\n```jsx\nimport CerebroRouter from \"cerebro-command-router\";\n\n//or\n\nconst CerebroRouter = require(\"cerebro-command-router\");\n```\n\n### **Configure the router by creating an instance with:**\n\n- `command: string` - The main command of your app (one word)\n- `term: string` - The complete string query (view Cerebro documentation)\n- `display: function` - The cerebro display function (view Cerebro documentation)\n\n```js\nconst myRouter = new CerebroRouter({\n\tcommand: \"your_command_here\",\n\tterm,\n\tdisplay,\n});\n```\n\n### **Create the routes for your subcommands**\n\n```js\n/*\nCerebroRouter.route(command: string,\n\t\t\tdisplayElement: see_cerebro_documentation,\n\t\t\toptions: object)\n*/\n\nmyRouter.route(\"your_first_subcommand\", {\n\ticon: icon,\n\ttitle: `Your title here`,\n\tgetPreview: () =\u003e \u003cOneGreatReactComponent /\u003e,\n});\n\nmyRouter.route(\"your_second_subcommand\", {\n\ticon: icon,\n\ttitle: `Other title here too :)`,\n\tgetPreview: () =\u003e \u003cOtherGreatReactComponent /\u003e,\n});\n```\n\n### The \"Options\" object.\n\nFor now, you can configure one interesting parameter: the autocompletion when you use the `tab key`. By default, when the subcommand is written with subcommand text, if `tab key` is pressed nothing will happen (term = term), but if `autocompleteAll: false` the result when `tab key` is pressed will be only command + subcommand.\n\n#### Example:\n\n#### With autocompleteAll default (true):\n\ncommand + subcommand + some text —\u003e command + subcommand + some text\n\n#### With autocompleteAll false:\n\ncommand + subcommand + some text —\u003e command + subcommand\n\n## **Invalid subcommand routing**\n\nYou can choose whether to show a bad subcommand message or to show nothing. By default, nothing will simply appear. To display a message you can use `CerebroRouter.invalidRoute(displayElement: see_cerebro_documentation)`\n\n```jsx\nmyRouter.invalidRoute({\n\ticon: icon,\n\ttitle: `Invalid Command :( `,\n});\n```\n\n⚠️ This method must be at the end of the plugin (after all the normal subcommand routes)\n\n### **Get the text of a subcommand so that you can work with it**\n\nSometimes, to work with a subcommand, you will need to know the rest of the text that the user has written. For example, in the cerebro-todoist plugin, after the command \"tds new \u003c\u003c rest of text \u003e\u003e\", the rest of the text is added to a note. To do this, you can use the \"getSubCommandText\" function that you can import from the package itself.\n\n```jsx\nimport { getSubCommandText } from \"cerebro-command-router\";\n\n//or\n\nconst { getSubCommandText } = require(\"cerebro-command-router\");\n\nconsole.log(getSubCommandText(\"ex com1 text and emoji 💫\")); //\"text and emoji 💫\"\n```\n\n### Full Example\n\nSome examples are available in the \"Examples\" folder.\nAnother real example can be found in the [cerebro-todoist plugin repository](https://github.com/dubisdev/cerebro-todoist)\n\n## Related\n\n- [Cerebro](http://github.com/cerebroapp/cerebro) – main repo for Cerebro app\n- [Cerebro Plugin Documentation](https://github.com/cerebroapp/cerebro/blob/master/docs/plugins.md)\n\n## License\n\nMIT © [David Jiménez](https://dubis.dev)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdubisdev%2Fcerebro-command-router","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdubisdev%2Fcerebro-command-router","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdubisdev%2Fcerebro-command-router/lists"}