{"id":14155800,"url":"https://github.com/lenneTech/gluegun-menu","last_synced_at":"2025-08-06T01:33:42.782Z","repository":{"id":35145469,"uuid":"212632763","full_name":"lenneTech/gluegun-menu","owner":"lenneTech","description":"Menu for gluegun CLIs","archived":false,"fork":false,"pushed_at":"2023-01-08T15:57:33.000Z","size":672,"stargazers_count":27,"open_issues_count":3,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-08-11T15:36:39.658Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lenneTech.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":"2019-10-03T16:59:10.000Z","updated_at":"2024-07-30T19:37:26.000Z","dependencies_parsed_at":"2023-01-15T14:44:52.355Z","dependency_job_id":null,"html_url":"https://github.com/lenneTech/gluegun-menu","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenneTech%2Fgluegun-menu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenneTech%2Fgluegun-menu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenneTech%2Fgluegun-menu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lenneTech%2Fgluegun-menu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lenneTech","download_url":"https://codeload.github.com/lenneTech/gluegun-menu/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":215735862,"owners_count":15923388,"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":"2024-08-17T08:05:00.536Z","updated_at":"2024-08-17T08:06:03.641Z","avatar_url":"https://github.com/lenneTech.png","language":"TypeScript","funding_links":[],"categories":["others","TypeScript"],"sub_categories":[],"readme":"# Gluegun Menu\n\nThe Gluegun Menu is an extension for [Gluegun](https://infinitered.github.io/gluegun) CLIs.\nIt generates an interactive menu structure from the commands of the CLI.\n\n![Gluegun Menu Demo](assets/demo.gif)\n\nThe extension can be integrated into any Gluegun project.\nIt is already integrated in the [lenne.Tech CLI Starter](https://github.com/lenneTech/cli-starter),\nwhich can be initialized comfortably via the [lenne.Tech CLI](https://github.com/lenneTech/cli).\n\n## Integration\n\nIt can be easily integrated into your CLI:\n\n### 1. Install extension:\n\n```bash\n$ npm install @lenne.tech/gluegun-menu\n```\n\n### 2. Integrate extension as plugin:\n\n`src/cli.ts`:\n\n```typescript\n// ...\nconst cli = build()\n  // ...\n  .plugin(__dirname + '/../node_modules/@lenne.tech/gluegun-menu/dist', {\n    commandFilePattern: '*.js',\n    extensionFilePattern: '*.js'\n  })\n  // ...\n  .create();\n// ...\n```\n\n### 3. Prepare main commands\n\n`src/commands/YOUR_COMMAND/YOUR_COMMAND.ts`:\n\n```typescript\nimport { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';\n\n/**\n * YOUR_COMMAND menu\n */\nmodule.exports = {\n  name: 'YOUR_COMMAND',\n  alias: ['YOUR_COMMAND_ALIAS'],\n  description: 'YOUR_DESCRIPTION',\n  hidden: true,\n  run: async (toolbox: GluegunMenuToolbox) =\u003e {\n    await toolbox.menu.showMenu('(PARANT_COMMANDS) YOUR_COMMAND');\n  }\n};\n```\n\n## Parameters of `showMenu`\n\n1. parentCommands?: string  \n   command name OR parent names + command name\n\n2. options?: object\n\n   - level?: number =\u003e Level of the current section (0 = main section)\n   - headline?: string =\u003e Headline for the current section\n   - showHelp?: boolean =\u003e If you want to show the `help` command at the top\n   - hideBack?: boolean =\u003e If you want to hide the `back` command at the bottom\n   - setCache?: boolean =\u003e Re-use these `options` in subsequent menus (doesn't apply for `level`, `headline` or `setCache`)\n   - backLabel?: string =\u003e custom label to indicate `go back` action\n   - cancelLabel?: string =\u003e custom label to indicate `cancel` action\n   - byeMessage?: string =\u003e custom `bye` message\n\nNote: If the options in the main menu are to be used, for example to define the headline,\n`null` or an empty string `''` must be passed as the first parameter:  \n`showMenu(null, {headline: 'Main menu'})`\n\n## Example\n\nExample file structure:\n\n```\nsrc/commands/\n    section1/\n        subsection1/\n            subsection1.ts\n            yyy1.ts\n            yyy2.ts\n        section1.ts\n        xxx1.ts\n        xxx2.ts\n    section2/\n        section2.ts\n        zzz1.ts\n        zzz2.ts\n    brand.ts\n```\n\n`src/commands/brand.ts`:\n\n```typescript\nimport { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';\n\n/**\n * Main menu\n */\nmodule.exports = {\n  name: 'brand',\n  description: 'Welcome to brand CLI',\n  hidden: true,\n  run: async (toolbox: GluegunMenuToolbox) =\u003e {\n    await toolbox.menu.showMenu();\n  }\n};\n```\n\n`src/commands/section1/section1.ts`:\n\n```typescript\nimport { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';\n\n/**\n * Section1 menu\n */\nmodule.exports = {\n  name: 'section1',\n  alias: ['s1'],\n  description: 'Description for section1',\n  hidden: true,\n  run: async (toolbox: GluegunMenuToolbox) =\u003e {\n    await toolbox.menu.showMenu('section1');\n  }\n};\n```\n\n`src/commands/section1/subsection1/subsection1.ts`:\n\n```typescript\nimport { GluegunMenuToolbox } from '@lenne.tech/gluegun-menu';\n\n/**\n * Subsection1 menu\n */\nmodule.exports = {\n  name: 'subsection1',\n  alias: ['sub1'],\n  description: 'Description for subsection1',\n  hidden: true,\n  run: async (toolbox: GluegunMenuToolbox) =\u003e {\n    await toolbox.menu.showMenu('section1 subsection1', { headline: 'Subsection1 commands' });\n  }\n};\n```\n\n## Extensions of the toolbox\n\n### toolbox.menu\n\nThe menu extends the toolbox by the functionality to execute commands via a menu in the terminal (see above).\n\n### toolbox.fromMenu\n\nExtends the toolbox to the possibility to determine during the execution of a command whether the command was\ncalled via the menu.\n\n```typescript\nconst NewCommand: GluegunCommand = {\n  // ...\n  run: async (toolbox: GluegunMenuToolbox) =\u003e {\n    //...\n\n    if (toolbox.fromMenu()) {\n      console.log('I was called via the menu');\n    } else {\n      console.log('I was called via a direct command in the terminal');\n    }\n\n    // ...\n  }\n};\nexport default NewCommand;\n```\n\n## Additional parameter options\n\n### toolbox.parameters.options.fromGluegunMenu\n\nFlag that shows whether the command was called via the menu.\n\n## Thanks\n\nMany thanks to the developers of [Glugun](https://infinitered.github.io/gluegun)\nand all the developers whose packages are used here.\n\nMany thanks also to:\n\n- [pascal-klesse](https://github.com/pascal-klesse) for the support during the development\n- [Tazaf](https://github.com/Tazaf) for the idea to set the `fromGlueguneMenu` flag\n\n## License\n\nMIT - see LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FlenneTech%2Fgluegun-menu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FlenneTech%2Fgluegun-menu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FlenneTech%2Fgluegun-menu/lists"}