clawmini 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gemini/settings.json +46 -0
- package/.prettierrc +7 -0
- package/GEMINI.md +11 -0
- package/README.md +137 -0
- package/dist/adapter-discord/index.d.mts +5 -0
- package/dist/adapter-discord/index.d.mts.map +1 -0
- package/dist/adapter-discord/index.mjs +456 -0
- package/dist/adapter-discord/index.mjs.map +1 -0
- package/dist/chats-DKgTeU7i.mjs +91 -0
- package/dist/chats-DKgTeU7i.mjs.map +1 -0
- package/dist/chats-Zd_HXDHx.mjs +29 -0
- package/dist/chats-Zd_HXDHx.mjs.map +1 -0
- package/dist/cli/index.d.mts +1 -0
- package/dist/cli/index.mjs +850 -0
- package/dist/cli/index.mjs.map +1 -0
- package/dist/cli/lite.d.mts +1 -0
- package/dist/cli/lite.mjs +4434 -0
- package/dist/cli/lite.mjs.map +1 -0
- package/dist/daemon/index.d.mts +5 -0
- package/dist/daemon/index.d.mts.map +1 -0
- package/dist/daemon/index.mjs +1222 -0
- package/dist/daemon/index.mjs.map +1 -0
- package/dist/fetch-BjZVyU3Z.mjs +37 -0
- package/dist/fetch-BjZVyU3Z.mjs.map +1 -0
- package/dist/fs-B5wW0oaH.mjs +14 -0
- package/dist/fs-B5wW0oaH.mjs.map +1 -0
- package/dist/lite-Dl7WXyaH.mjs +80 -0
- package/dist/lite-Dl7WXyaH.mjs.map +1 -0
- package/dist/rolldown-runtime-95iHPtFO.mjs +18 -0
- package/dist/web/_app/env.js +1 -0
- package/dist/web/_app/immutable/assets/0.GI4C4dpV.css +1 -0
- package/dist/web/_app/immutable/chunks/B5abRDXp.js +1 -0
- package/dist/web/_app/immutable/chunks/B8yYFADm.js +1 -0
- package/dist/web/_app/immutable/chunks/BPy8HLo7.js +5 -0
- package/dist/web/_app/immutable/chunks/Bi0jeV7Q.js +1 -0
- package/dist/web/_app/immutable/chunks/BmUXQ3wy.js +2 -0
- package/dist/web/_app/immutable/chunks/C3k55nDF.js +1 -0
- package/dist/web/_app/immutable/chunks/COekwvP2.js +1 -0
- package/dist/web/_app/immutable/chunks/CSvS_NwK.js +1 -0
- package/dist/web/_app/immutable/chunks/CpaGRn9L.js +1 -0
- package/dist/web/_app/immutable/chunks/CyNaE55B.js +1 -0
- package/dist/web/_app/immutable/chunks/DG5RZBw-.js +2 -0
- package/dist/web/_app/immutable/chunks/Dc-UOHw9.js +1 -0
- package/dist/web/_app/immutable/chunks/DcrmIfTj.js +1 -0
- package/dist/web/_app/immutable/chunks/ZkLyk0mE.js +1 -0
- package/dist/web/_app/immutable/entry/app.B-vZe7PN.js +2 -0
- package/dist/web/_app/immutable/entry/start.oP1AgKhs.js +1 -0
- package/dist/web/_app/immutable/nodes/0.B5WFN0zw.js +1 -0
- package/dist/web/_app/immutable/nodes/1.D1wtJb2k.js +1 -0
- package/dist/web/_app/immutable/nodes/2.CK3CLC0f.js +1 -0
- package/dist/web/_app/immutable/nodes/3.BB5wCoBf.js +4 -0
- package/dist/web/_app/immutable/nodes/4.Dr2jvAXK.js +1 -0
- package/dist/web/_app/immutable/nodes/5.BJl7oM3b.js +1 -0
- package/dist/web/_app/version.json +1 -0
- package/dist/web/index.html +37 -0
- package/dist/web/robots.txt +3 -0
- package/dist/workspace-CSgfo_2J.mjs +383 -0
- package/dist/workspace-CSgfo_2J.mjs.map +1 -0
- package/docs/01_chats/development_log.md +36 -0
- package/docs/01_chats/notes.md +27 -0
- package/docs/01_chats/prd.md +47 -0
- package/docs/01_chats/questions.md +19 -0
- package/docs/01_chats/tickets.md +67 -0
- package/docs/02_sessions/development_log.md +79 -0
- package/docs/02_sessions/notes.md +40 -0
- package/docs/02_sessions/prd.md +75 -0
- package/docs/02_sessions/questions.md +7 -0
- package/docs/02_sessions/tickets.md +68 -0
- package/docs/03_web_interface/development_log.md +60 -0
- package/docs/03_web_interface/notes.md +29 -0
- package/docs/03_web_interface/prd.md +42 -0
- package/docs/03_web_interface/questions.md +8 -0
- package/docs/03_web_interface/tickets.md +59 -0
- package/docs/04_agents/development_log.md +54 -0
- package/docs/04_agents/notes.md +45 -0
- package/docs/04_agents/prd.md +47 -0
- package/docs/04_agents/questions.md +13 -0
- package/docs/04_agents/tickets.md +107 -0
- package/docs/05_routers/development_log.md +13 -0
- package/docs/05_routers/notes.md +40 -0
- package/docs/05_routers/prd.md +55 -0
- package/docs/05_routers/questions.md +21 -0
- package/docs/05_routers/tickets.md +109 -0
- package/docs/06_agent_templates/development_log.md +38 -0
- package/docs/06_agent_templates/notes.md +25 -0
- package/docs/06_agent_templates/prd.md +34 -0
- package/docs/06_agent_templates/questions.md +11 -0
- package/docs/06_agent_templates/tickets.md +49 -0
- package/docs/06_cron/development_log.md +51 -0
- package/docs/06_cron/notes.md +14 -0
- package/docs/06_cron/prd.md +92 -0
- package/docs/06_cron/questions.md +15 -0
- package/docs/06_cron/tickets.md +75 -0
- package/docs/07_web_chat_ux/development_log.md +30 -0
- package/docs/07_web_chat_ux/notes.md +25 -0
- package/docs/07_web_chat_ux/prd.md +46 -0
- package/docs/07_web_chat_ux/questions.md +7 -0
- package/docs/07_web_chat_ux/tickets.md +48 -0
- package/docs/08_agent_api/development_log.md +52 -0
- package/docs/08_agent_api/notes.md +31 -0
- package/docs/08_agent_api/prd.md +56 -0
- package/docs/08_agent_api/questions.md +14 -0
- package/docs/08_agent_api/tickets.md +104 -0
- package/docs/09_agent_fallbacks/development_log.md +52 -0
- package/docs/09_agent_fallbacks/notes.md +40 -0
- package/docs/09_agent_fallbacks/prd.md +55 -0
- package/docs/09_agent_fallbacks/questions.md +10 -0
- package/docs/09_agent_fallbacks/tickets.md +88 -0
- package/docs/09_discord_adapter/development_log.md +95 -0
- package/docs/09_discord_adapter/notes.md +18 -0
- package/docs/09_discord_adapter/prd.md +57 -0
- package/docs/09_discord_adapter/questions.md +16 -0
- package/docs/09_discord_adapter/tickets.md +116 -0
- package/docs/10_file_attachments/development_log.md +55 -0
- package/docs/10_file_attachments/notes.md +59 -0
- package/docs/10_file_attachments/prd.md +73 -0
- package/docs/10_file_attachments/questions.md +15 -0
- package/docs/10_file_attachments/tickets.md +88 -0
- package/docs/11_message_verbosity/development_log.md +43 -0
- package/docs/11_message_verbosity/notes.md +26 -0
- package/docs/11_message_verbosity/prd.md +44 -0
- package/docs/11_message_verbosity/questions.md +8 -0
- package/docs/11_message_verbosity/tickets.md +33 -0
- package/docs/12_environments/development_log.md +43 -0
- package/docs/12_environments/notes.md +45 -0
- package/docs/12_environments/prd.md +113 -0
- package/docs/12_environments/questions.md +17 -0
- package/docs/12_environments/tickets.md +87 -0
- package/docs/12_setup_flow_improvements/development_log.md +40 -0
- package/docs/12_setup_flow_improvements/notes.md +34 -0
- package/docs/12_setup_flow_improvements/prd.md +35 -0
- package/docs/12_setup_flow_improvements/questions.md +8 -0
- package/docs/12_setup_flow_improvements/tickets.md +122 -0
- package/docs/13_discord_typing_indicators/development_log.md +38 -0
- package/docs/13_discord_typing_indicators/notes.md +18 -0
- package/docs/13_discord_typing_indicators/prd.md +41 -0
- package/docs/13_discord_typing_indicators/questions.md +6 -0
- package/docs/13_discord_typing_indicators/tickets.md +60 -0
- package/docs/14_interruptions/development_log.md +50 -0
- package/docs/14_interruptions/notes.md +38 -0
- package/docs/14_interruptions/prd.md +46 -0
- package/docs/14_interruptions/questions.md +12 -0
- package/docs/14_interruptions/tickets.md +69 -0
- package/docs/15_sandbox_policies/development_log.md +95 -0
- package/docs/15_sandbox_policies/notes.md +33 -0
- package/docs/15_sandbox_policies/prd.md +163 -0
- package/docs/15_sandbox_policies/questions.md +10 -0
- package/docs/15_sandbox_policies/tickets.md +196 -0
- package/docs/CHECKS.md +9 -0
- package/docs/guides/discord_adapter_setup.md +69 -0
- package/docs/guides/sandbox_policies.md +76 -0
- package/eslint.config.js +47 -0
- package/napkin.md +21 -0
- package/package.json +50 -0
- package/scripts/create_worktree.sh +49 -0
- package/scripts/get_pr_comments.sh +36 -0
- package/src/adapter-discord/client.test.ts +65 -0
- package/src/adapter-discord/client.ts +41 -0
- package/src/adapter-discord/config.test.ts +156 -0
- package/src/adapter-discord/config.ts +61 -0
- package/src/adapter-discord/forwarder.test.ts +493 -0
- package/src/adapter-discord/forwarder.ts +246 -0
- package/src/adapter-discord/index.test.ts +399 -0
- package/src/adapter-discord/index.ts +147 -0
- package/src/adapter-discord/state.test.ts +65 -0
- package/src/adapter-discord/state.ts +44 -0
- package/src/cli/client.ts +46 -0
- package/src/cli/commands/agents.ts +138 -0
- package/src/cli/commands/chats.ts +79 -0
- package/src/cli/commands/down.ts +32 -0
- package/src/cli/commands/environments.ts +39 -0
- package/src/cli/commands/export-lite.ts +62 -0
- package/src/cli/commands/init.ts +79 -0
- package/src/cli/commands/jobs.ts +141 -0
- package/src/cli/commands/messages.ts +103 -0
- package/src/cli/commands/up.ts +26 -0
- package/src/cli/commands/web-api/agents.ts +138 -0
- package/src/cli/commands/web-api/chats.ts +213 -0
- package/src/cli/commands/web-api/utils.ts +27 -0
- package/src/cli/commands/web.ts +105 -0
- package/src/cli/e2e/adapter-discord.test.ts +76 -0
- package/src/cli/e2e/agents.test.ts +140 -0
- package/src/cli/e2e/basic.test.ts +43 -0
- package/src/cli/e2e/cron.test.ts +132 -0
- package/src/cli/e2e/daemon.test.ts +293 -0
- package/src/cli/e2e/environments.test.ts +66 -0
- package/src/cli/e2e/export-lite-func.test.ts +155 -0
- package/src/cli/e2e/export-lite.test.ts +51 -0
- package/src/cli/e2e/fallbacks.test.ts +169 -0
- package/src/cli/e2e/global-setup.ts +15 -0
- package/src/cli/e2e/init.test.ts +70 -0
- package/src/cli/e2e/messages.test.ts +294 -0
- package/src/cli/e2e/requests.test.ts +165 -0
- package/src/cli/e2e/utils.ts +66 -0
- package/src/cli/index.test.ts +7 -0
- package/src/cli/index.ts +29 -0
- package/src/cli/lite.ts +247 -0
- package/src/cli/utils.ts +4 -0
- package/src/daemon/auth.test.ts +50 -0
- package/src/daemon/auth.ts +69 -0
- package/src/daemon/chats.ts +26 -0
- package/src/daemon/cron.test.ts +28 -0
- package/src/daemon/cron.ts +159 -0
- package/src/daemon/events.ts +15 -0
- package/src/daemon/index.ts +212 -0
- package/src/daemon/message-agent.test.ts +132 -0
- package/src/daemon/message-extraction.test.ts +166 -0
- package/src/daemon/message-fallbacks.test.ts +313 -0
- package/src/daemon/message-interruption.test.ts +125 -0
- package/src/daemon/message-queue.test.ts +143 -0
- package/src/daemon/message-router.test.ts +106 -0
- package/src/daemon/message-session.test.ts +127 -0
- package/src/daemon/message-test-utils.ts +41 -0
- package/src/daemon/message-typing.test.ts +93 -0
- package/src/daemon/message-verbosity.test.ts +127 -0
- package/src/daemon/message.ts +600 -0
- package/src/daemon/observation.test.ts +118 -0
- package/src/daemon/policy-request-service.test.ts +87 -0
- package/src/daemon/policy-request-service.ts +62 -0
- package/src/daemon/policy-utils.test.ts +138 -0
- package/src/daemon/policy-utils.ts +152 -0
- package/src/daemon/queue.test.ts +89 -0
- package/src/daemon/queue.ts +87 -0
- package/src/daemon/request-store.test.ts +103 -0
- package/src/daemon/request-store.ts +96 -0
- package/src/daemon/router-policy-request.test.ts +99 -0
- package/src/daemon/router.test.ts +380 -0
- package/src/daemon/router.ts +510 -0
- package/src/daemon/routers/slash-command.test.ts +145 -0
- package/src/daemon/routers/slash-command.ts +58 -0
- package/src/daemon/routers/slash-interrupt.test.ts +30 -0
- package/src/daemon/routers/slash-interrupt.ts +7 -0
- package/src/daemon/routers/slash-new.test.ts +59 -0
- package/src/daemon/routers/slash-new.ts +14 -0
- package/src/daemon/routers/slash-policies.test.ts +167 -0
- package/src/daemon/routers/slash-policies.ts +131 -0
- package/src/daemon/routers/slash-stop.test.ts +30 -0
- package/src/daemon/routers/slash-stop.ts +3 -0
- package/src/daemon/routers/types.ts +10 -0
- package/src/daemon/routers/utils.ts +22 -0
- package/src/daemon/routers.test.ts +141 -0
- package/src/daemon/routers.ts +115 -0
- package/src/daemon/utils/spawn.ts +61 -0
- package/src/shared/agent-utils.ts +30 -0
- package/src/shared/chats.test.ts +112 -0
- package/src/shared/chats.ts +164 -0
- package/src/shared/config.test.ts +90 -0
- package/src/shared/config.ts +100 -0
- package/src/shared/event-source.ts +121 -0
- package/src/shared/fetch.ts +45 -0
- package/src/shared/lite.ts +129 -0
- package/src/shared/policies.ts +24 -0
- package/src/shared/utils/env.ts +27 -0
- package/src/shared/utils/fs.ts +13 -0
- package/src/shared/workspace.test.ts +345 -0
- package/src/shared/workspace.ts +500 -0
- package/templates/environments/cladding/env.json +7 -0
- package/templates/environments/macos/env.json +8 -0
- package/templates/environments/macos/sandbox.sb +21 -0
- package/templates/environments/macos-proxy/allowlist.txt +1 -0
- package/templates/environments/macos-proxy/env.json +14 -0
- package/templates/environments/macos-proxy/proxy.mjs +86 -0
- package/templates/environments/macos-proxy/sandbox.sb +34 -0
- package/templates/gemini/settings.json +11 -0
- package/templates/gemini-claw/.gemini/hooks/clawmini-logging.sh +17 -0
- package/templates/gemini-claw/.gemini/settings.json +24 -0
- package/templates/gemini-claw/.gemini/skills/clawmini-jobs/SKILL.md +40 -0
- package/templates/gemini-claw/.gemini/system.md +98 -0
- package/templates/gemini-claw/BOOTSTRAP.md +54 -0
- package/templates/gemini-claw/GEMINI.md +107 -0
- package/templates/gemini-claw/HEARTBEAT.md +3 -0
- package/templates/gemini-claw/MEMORY.md +2 -0
- package/templates/gemini-claw/SOUL.md +42 -0
- package/templates/gemini-claw/TOOLS.md +38 -0
- package/templates/gemini-claw/USER.md +15 -0
- package/templates/gemini-claw/memory/.gitkeep +0 -0
- package/templates/gemini-claw/settings.json +24 -0
- package/templates/opencode/settings.json +11 -0
- package/tsconfig.json +42 -0
- package/tsdown.config.ts +19 -0
- package/vitest.config.ts +9 -0
- package/web/.svelte-kit/ambient.d.ts +382 -0
- package/web/.svelte-kit/generated/client/app.js +35 -0
- package/web/.svelte-kit/generated/client/matchers.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/0.js +3 -0
- package/web/.svelte-kit/generated/client/nodes/1.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/2.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/3.js +1 -0
- package/web/.svelte-kit/generated/client/nodes/4.js +3 -0
- package/web/.svelte-kit/generated/client/nodes/5.js +3 -0
- package/web/.svelte-kit/generated/client-optimized/app.js +35 -0
- package/web/.svelte-kit/generated/client-optimized/matchers.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/0.js +3 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/1.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/2.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/3.js +1 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/4.js +3 -0
- package/web/.svelte-kit/generated/client-optimized/nodes/5.js +3 -0
- package/web/.svelte-kit/generated/root.js +3 -0
- package/web/.svelte-kit/generated/root.svelte +68 -0
- package/web/.svelte-kit/generated/server/internal.js +53 -0
- package/web/.svelte-kit/non-ambient.d.ts +46 -0
- package/web/.svelte-kit/output/client/.vite/manifest.json +251 -0
- package/web/.svelte-kit/output/client/_app/immutable/assets/0.GI4C4dpV.css +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/B5abRDXp.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/B8yYFADm.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/BPy8HLo7.js +5 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/Bi0jeV7Q.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/BmUXQ3wy.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/C3k55nDF.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/COekwvP2.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CSvS_NwK.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CpaGRn9L.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/CyNaE55B.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DG5RZBw-.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/Dc-UOHw9.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/DcrmIfTj.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/chunks/ZkLyk0mE.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/entry/app.B-vZe7PN.js +2 -0
- package/web/.svelte-kit/output/client/_app/immutable/entry/start.oP1AgKhs.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/0.B5WFN0zw.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/1.D1wtJb2k.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/2.CK3CLC0f.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/3.BB5wCoBf.js +4 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/4.Dr2jvAXK.js +1 -0
- package/web/.svelte-kit/output/client/_app/immutable/nodes/5.BJl7oM3b.js +1 -0
- package/web/.svelte-kit/output/client/_app/version.json +1 -0
- package/web/.svelte-kit/output/client/robots.txt +3 -0
- package/web/.svelte-kit/output/prerendered/dependencies/_app/env.js +1 -0
- package/web/.svelte-kit/output/server/.vite/manifest.json +215 -0
- package/web/.svelte-kit/output/server/_app/immutable/assets/_layout.GI4C4dpV.css +1 -0
- package/web/.svelte-kit/output/server/chunks/Icon.js +153 -0
- package/web/.svelte-kit/output/server/chunks/bot.js +2753 -0
- package/web/.svelte-kit/output/server/chunks/client.js +47 -0
- package/web/.svelte-kit/output/server/chunks/environment.js +34 -0
- package/web/.svelte-kit/output/server/chunks/exports.js +231 -0
- package/web/.svelte-kit/output/server/chunks/false.js +4 -0
- package/web/.svelte-kit/output/server/chunks/index-server.js +20 -0
- package/web/.svelte-kit/output/server/chunks/index.js +24 -0
- package/web/.svelte-kit/output/server/chunks/internal.js +133 -0
- package/web/.svelte-kit/output/server/chunks/plus.js +81 -0
- package/web/.svelte-kit/output/server/chunks/root.js +4076 -0
- package/web/.svelte-kit/output/server/chunks/shared.js +789 -0
- package/web/.svelte-kit/output/server/chunks/utils.js +43 -0
- package/web/.svelte-kit/output/server/entries/fallbacks/error.svelte.js +11 -0
- package/web/.svelte-kit/output/server/entries/pages/_layout.svelte.js +3944 -0
- package/web/.svelte-kit/output/server/entries/pages/_layout.ts.js +28 -0
- package/web/.svelte-kit/output/server/entries/pages/_page.svelte.js +7 -0
- package/web/.svelte-kit/output/server/entries/pages/agents/_page.svelte.js +379 -0
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/_page.svelte.js +292 -0
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/_page.ts.js +17 -0
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/settings/_page.svelte.js +259 -0
- package/web/.svelte-kit/output/server/entries/pages/chats/_id_/settings/_page.ts.js +17 -0
- package/web/.svelte-kit/output/server/index.js +3748 -0
- package/web/.svelte-kit/output/server/internal.js +14 -0
- package/web/.svelte-kit/output/server/manifest-full.js +63 -0
- package/web/.svelte-kit/output/server/manifest.js +63 -0
- package/web/.svelte-kit/output/server/nodes/0.js +13 -0
- package/web/.svelte-kit/output/server/nodes/1.js +8 -0
- package/web/.svelte-kit/output/server/nodes/2.js +8 -0
- package/web/.svelte-kit/output/server/nodes/3.js +8 -0
- package/web/.svelte-kit/output/server/nodes/4.js +13 -0
- package/web/.svelte-kit/output/server/nodes/5.js +13 -0
- package/web/.svelte-kit/output/server/remote-entry.js +557 -0
- package/web/.svelte-kit/tsconfig.json +67 -0
- package/web/.svelte-kit/types/route_meta_data.json +17 -0
- package/web/.svelte-kit/types/src/routes/$types.d.ts +26 -0
- package/web/.svelte-kit/types/src/routes/agents/$types.d.ts +18 -0
- package/web/.svelte-kit/types/src/routes/chats/[id]/$types.d.ts +21 -0
- package/web/.svelte-kit/types/src/routes/chats/[id]/proxy+page.ts +20 -0
- package/web/.svelte-kit/types/src/routes/chats/[id]/settings/$types.d.ts +21 -0
- package/web/.svelte-kit/types/src/routes/chats/[id]/settings/proxy+page.ts +19 -0
- package/web/.svelte-kit/types/src/routes/proxy+layout.ts +35 -0
- package/web/README.md +42 -0
- package/web/components.json +16 -0
- package/web/package.json +41 -0
- package/web/src/app.css +121 -0
- package/web/src/app.d.ts +13 -0
- package/web/src/app.html +11 -0
- package/web/src/demo.spec.ts +7 -0
- package/web/src/lib/app-state.svelte.ts +3 -0
- package/web/src/lib/assets/favicon.svg +1 -0
- package/web/src/lib/components/app/app-sidebar-test-wrapper.svelte +10 -0
- package/web/src/lib/components/app/app-sidebar.svelte +171 -0
- package/web/src/lib/components/app/app-sidebar.svelte.spec.ts +13 -0
- package/web/src/lib/components/ui/button/button.svelte +82 -0
- package/web/src/lib/components/ui/button/index.ts +17 -0
- package/web/src/lib/components/ui/dialog/dialog-close.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog-content.svelte +45 -0
- package/web/src/lib/components/ui/dialog/dialog-description.svelte +17 -0
- package/web/src/lib/components/ui/dialog/dialog-footer.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-header.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-overlay.svelte +20 -0
- package/web/src/lib/components/ui/dialog/dialog-portal.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog-title.svelte +17 -0
- package/web/src/lib/components/ui/dialog/dialog-trigger.svelte +7 -0
- package/web/src/lib/components/ui/dialog/dialog.svelte +7 -0
- package/web/src/lib/components/ui/dialog/index.ts +34 -0
- package/web/src/lib/components/ui/input/index.ts +7 -0
- package/web/src/lib/components/ui/input/input.svelte +52 -0
- package/web/src/lib/components/ui/separator/index.ts +7 -0
- package/web/src/lib/components/ui/separator/separator.svelte +21 -0
- package/web/src/lib/components/ui/sheet/index.ts +34 -0
- package/web/src/lib/components/ui/sheet/sheet-close.svelte +7 -0
- package/web/src/lib/components/ui/sheet/sheet-content.svelte +60 -0
- package/web/src/lib/components/ui/sheet/sheet-description.svelte +17 -0
- package/web/src/lib/components/ui/sheet/sheet-footer.svelte +20 -0
- package/web/src/lib/components/ui/sheet/sheet-header.svelte +20 -0
- package/web/src/lib/components/ui/sheet/sheet-overlay.svelte +20 -0
- package/web/src/lib/components/ui/sheet/sheet-portal.svelte +7 -0
- package/web/src/lib/components/ui/sheet/sheet-title.svelte +17 -0
- package/web/src/lib/components/ui/sheet/sheet-trigger.svelte +7 -0
- package/web/src/lib/components/ui/sheet/sheet.svelte +7 -0
- package/web/src/lib/components/ui/sidebar/constants.ts +6 -0
- package/web/src/lib/components/ui/sidebar/context.svelte.ts +79 -0
- package/web/src/lib/components/ui/sidebar/index.ts +75 -0
- package/web/src/lib/components/ui/sidebar/sidebar-content.svelte +24 -0
- package/web/src/lib/components/ui/sidebar/sidebar-footer.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-group-action.svelte +36 -0
- package/web/src/lib/components/ui/sidebar/sidebar-group-content.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-group-label.svelte +34 -0
- package/web/src/lib/components/ui/sidebar/sidebar-group.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-header.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-input.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-inset.svelte +24 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-action.svelte +43 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-badge.svelte +29 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-button.svelte +103 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-item.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-skeleton.svelte +36 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-sub-button.svelte +43 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-sub-item.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu-sub.svelte +25 -0
- package/web/src/lib/components/ui/sidebar/sidebar-menu.svelte +21 -0
- package/web/src/lib/components/ui/sidebar/sidebar-provider.svelte +53 -0
- package/web/src/lib/components/ui/sidebar/sidebar-rail.svelte +36 -0
- package/web/src/lib/components/ui/sidebar/sidebar-separator.svelte +19 -0
- package/web/src/lib/components/ui/sidebar/sidebar-trigger.svelte +35 -0
- package/web/src/lib/components/ui/sidebar/sidebar.svelte +104 -0
- package/web/src/lib/components/ui/skeleton/index.ts +7 -0
- package/web/src/lib/components/ui/skeleton/skeleton.svelte +17 -0
- package/web/src/lib/components/ui/switch/index.ts +7 -0
- package/web/src/lib/components/ui/switch/switch.svelte +29 -0
- package/web/src/lib/components/ui/textarea/index.ts +7 -0
- package/web/src/lib/components/ui/textarea/textarea.svelte +23 -0
- package/web/src/lib/components/ui/tooltip/index.ts +19 -0
- package/web/src/lib/components/ui/tooltip/tooltip-content.svelte +52 -0
- package/web/src/lib/components/ui/tooltip/tooltip-portal.svelte +7 -0
- package/web/src/lib/components/ui/tooltip/tooltip-provider.svelte +7 -0
- package/web/src/lib/components/ui/tooltip/tooltip-trigger.svelte +7 -0
- package/web/src/lib/components/ui/tooltip/tooltip.svelte +7 -0
- package/web/src/lib/hooks/is-mobile.svelte.ts +9 -0
- package/web/src/lib/index.ts +1 -0
- package/web/src/lib/types.ts +23 -0
- package/web/src/lib/utils.ts +13 -0
- package/web/src/routes/+layout.svelte +67 -0
- package/web/src/routes/+layout.ts +34 -0
- package/web/src/routes/+page.svelte +7 -0
- package/web/src/routes/agents/+page.svelte +206 -0
- package/web/src/routes/chats/[id]/+page.svelte +406 -0
- package/web/src/routes/chats/[id]/+page.ts +19 -0
- package/web/src/routes/chats/[id]/page.svelte.spec.ts +102 -0
- package/web/src/routes/chats/[id]/settings/+page.svelte +165 -0
- package/web/src/routes/chats/[id]/settings/+page.ts +18 -0
- package/web/src/routes/page.svelte.spec.ts +13 -0
- package/web/static/robots.txt +3 -0
- package/web/svelte.config.js +21 -0
- package/web/tsconfig.json +20 -0
- package/web/vite.config.ts +41 -0
|
@@ -0,0 +1,4434 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
var __create$2 = Object.create;
|
|
6
|
+
var __defProp$2 = Object.defineProperty;
|
|
7
|
+
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
|
8
|
+
var __getOwnPropNames$2 = Object.getOwnPropertyNames;
|
|
9
|
+
var __getProtoOf$2 = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
12
|
+
var __copyProps$2 = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (var keys = __getOwnPropNames$2(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
15
|
+
key = keys[i];
|
|
16
|
+
if (!__hasOwnProp$2.call(to, key) && key !== except) {
|
|
17
|
+
__defProp$2(to, key, {
|
|
18
|
+
get: ((k) => from[k]).bind(null, key),
|
|
19
|
+
enumerable: !(desc = __getOwnPropDesc$2(from, key)) || desc.enumerable
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toESM$2 = (mod, isNodeMode, target) => (target = mod != null ? __create$2(__getProtoOf$2(mod)) : {}, __copyProps$2(isNodeMode || !mod || !mod.__esModule ? __defProp$2(target, "default", {
|
|
27
|
+
value: mod,
|
|
28
|
+
enumerable: true
|
|
29
|
+
}) : target, mod));
|
|
30
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region node_modules/commander/lib/error.js
|
|
34
|
+
var require_error = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
35
|
+
/**
|
|
36
|
+
* CommanderError class
|
|
37
|
+
*/
|
|
38
|
+
var CommanderError = class extends Error {
|
|
39
|
+
/**
|
|
40
|
+
* Constructs the CommanderError class
|
|
41
|
+
* @param {number} exitCode suggested exit code which could be used with process.exit
|
|
42
|
+
* @param {string} code an id string representing the error
|
|
43
|
+
* @param {string} message human-readable description of the error
|
|
44
|
+
*/
|
|
45
|
+
constructor(exitCode, code, message) {
|
|
46
|
+
super(message);
|
|
47
|
+
Error.captureStackTrace(this, this.constructor);
|
|
48
|
+
this.name = this.constructor.name;
|
|
49
|
+
this.code = code;
|
|
50
|
+
this.exitCode = exitCode;
|
|
51
|
+
this.nestedError = void 0;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* InvalidArgumentError class
|
|
56
|
+
*/
|
|
57
|
+
var InvalidArgumentError = class extends CommanderError {
|
|
58
|
+
/**
|
|
59
|
+
* Constructs the InvalidArgumentError class
|
|
60
|
+
* @param {string} [message] explanation of why argument is invalid
|
|
61
|
+
*/
|
|
62
|
+
constructor(message) {
|
|
63
|
+
super(1, "commander.invalidArgument", message);
|
|
64
|
+
Error.captureStackTrace(this, this.constructor);
|
|
65
|
+
this.name = this.constructor.name;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
exports.CommanderError = CommanderError;
|
|
69
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
70
|
+
}));
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region node_modules/commander/lib/argument.js
|
|
74
|
+
var require_argument = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
75
|
+
const { InvalidArgumentError } = require_error();
|
|
76
|
+
var Argument = class {
|
|
77
|
+
/**
|
|
78
|
+
* Initialize a new command argument with the given name and description.
|
|
79
|
+
* The default is that the argument is required, and you can explicitly
|
|
80
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
81
|
+
*
|
|
82
|
+
* @param {string} name
|
|
83
|
+
* @param {string} [description]
|
|
84
|
+
*/
|
|
85
|
+
constructor(name, description) {
|
|
86
|
+
this.description = description || "";
|
|
87
|
+
this.variadic = false;
|
|
88
|
+
this.parseArg = void 0;
|
|
89
|
+
this.defaultValue = void 0;
|
|
90
|
+
this.defaultValueDescription = void 0;
|
|
91
|
+
this.argChoices = void 0;
|
|
92
|
+
switch (name[0]) {
|
|
93
|
+
case "<":
|
|
94
|
+
this.required = true;
|
|
95
|
+
this._name = name.slice(1, -1);
|
|
96
|
+
break;
|
|
97
|
+
case "[":
|
|
98
|
+
this.required = false;
|
|
99
|
+
this._name = name.slice(1, -1);
|
|
100
|
+
break;
|
|
101
|
+
default:
|
|
102
|
+
this.required = true;
|
|
103
|
+
this._name = name;
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
if (this._name.endsWith("...")) {
|
|
107
|
+
this.variadic = true;
|
|
108
|
+
this._name = this._name.slice(0, -3);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Return argument name.
|
|
113
|
+
*
|
|
114
|
+
* @return {string}
|
|
115
|
+
*/
|
|
116
|
+
name() {
|
|
117
|
+
return this._name;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* @package
|
|
121
|
+
*/
|
|
122
|
+
_collectValue(value, previous) {
|
|
123
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) return [value];
|
|
124
|
+
previous.push(value);
|
|
125
|
+
return previous;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
129
|
+
*
|
|
130
|
+
* @param {*} value
|
|
131
|
+
* @param {string} [description]
|
|
132
|
+
* @return {Argument}
|
|
133
|
+
*/
|
|
134
|
+
default(value, description) {
|
|
135
|
+
this.defaultValue = value;
|
|
136
|
+
this.defaultValueDescription = description;
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Set the custom handler for processing CLI command arguments into argument values.
|
|
141
|
+
*
|
|
142
|
+
* @param {Function} [fn]
|
|
143
|
+
* @return {Argument}
|
|
144
|
+
*/
|
|
145
|
+
argParser(fn) {
|
|
146
|
+
this.parseArg = fn;
|
|
147
|
+
return this;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Only allow argument value to be one of choices.
|
|
151
|
+
*
|
|
152
|
+
* @param {string[]} values
|
|
153
|
+
* @return {Argument}
|
|
154
|
+
*/
|
|
155
|
+
choices(values) {
|
|
156
|
+
this.argChoices = values.slice();
|
|
157
|
+
this.parseArg = (arg, previous) => {
|
|
158
|
+
if (!this.argChoices.includes(arg)) throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
159
|
+
if (this.variadic) return this._collectValue(arg, previous);
|
|
160
|
+
return arg;
|
|
161
|
+
};
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Make argument required.
|
|
166
|
+
*
|
|
167
|
+
* @returns {Argument}
|
|
168
|
+
*/
|
|
169
|
+
argRequired() {
|
|
170
|
+
this.required = true;
|
|
171
|
+
return this;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Make argument optional.
|
|
175
|
+
*
|
|
176
|
+
* @returns {Argument}
|
|
177
|
+
*/
|
|
178
|
+
argOptional() {
|
|
179
|
+
this.required = false;
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
/**
|
|
184
|
+
* Takes an argument and returns its human readable equivalent for help usage.
|
|
185
|
+
*
|
|
186
|
+
* @param {Argument} arg
|
|
187
|
+
* @return {string}
|
|
188
|
+
* @private
|
|
189
|
+
*/
|
|
190
|
+
function humanReadableArgName(arg) {
|
|
191
|
+
const nameOutput = arg.name() + (arg.variadic === true ? "..." : "");
|
|
192
|
+
return arg.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
|
|
193
|
+
}
|
|
194
|
+
exports.Argument = Argument;
|
|
195
|
+
exports.humanReadableArgName = humanReadableArgName;
|
|
196
|
+
}));
|
|
197
|
+
|
|
198
|
+
//#endregion
|
|
199
|
+
//#region node_modules/commander/lib/help.js
|
|
200
|
+
var require_help = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
201
|
+
const { humanReadableArgName } = require_argument();
|
|
202
|
+
/**
|
|
203
|
+
* TypeScript import types for JSDoc, used by Visual Studio Code IntelliSense and `npm run typescript-checkJS`
|
|
204
|
+
* https://www.typescriptlang.org/docs/handbook/jsdoc-supported-types.html#import-types
|
|
205
|
+
* @typedef { import("./argument.js").Argument } Argument
|
|
206
|
+
* @typedef { import("./command.js").Command } Command
|
|
207
|
+
* @typedef { import("./option.js").Option } Option
|
|
208
|
+
*/
|
|
209
|
+
var Help = class {
|
|
210
|
+
constructor() {
|
|
211
|
+
this.helpWidth = void 0;
|
|
212
|
+
this.minWidthToWrap = 40;
|
|
213
|
+
this.sortSubcommands = false;
|
|
214
|
+
this.sortOptions = false;
|
|
215
|
+
this.showGlobalOptions = false;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* prepareContext is called by Commander after applying overrides from `Command.configureHelp()`
|
|
219
|
+
* and just before calling `formatHelp()`.
|
|
220
|
+
*
|
|
221
|
+
* Commander just uses the helpWidth and the rest is provided for optional use by more complex subclasses.
|
|
222
|
+
*
|
|
223
|
+
* @param {{ error?: boolean, helpWidth?: number, outputHasColors?: boolean }} contextOptions
|
|
224
|
+
*/
|
|
225
|
+
prepareContext(contextOptions) {
|
|
226
|
+
this.helpWidth = this.helpWidth ?? contextOptions.helpWidth ?? 80;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one.
|
|
230
|
+
*
|
|
231
|
+
* @param {Command} cmd
|
|
232
|
+
* @returns {Command[]}
|
|
233
|
+
*/
|
|
234
|
+
visibleCommands(cmd) {
|
|
235
|
+
const visibleCommands = cmd.commands.filter((cmd) => !cmd._hidden);
|
|
236
|
+
const helpCommand = cmd._getHelpCommand();
|
|
237
|
+
if (helpCommand && !helpCommand._hidden) visibleCommands.push(helpCommand);
|
|
238
|
+
if (this.sortSubcommands) visibleCommands.sort((a, b) => {
|
|
239
|
+
return a.name().localeCompare(b.name());
|
|
240
|
+
});
|
|
241
|
+
return visibleCommands;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Compare options for sort.
|
|
245
|
+
*
|
|
246
|
+
* @param {Option} a
|
|
247
|
+
* @param {Option} b
|
|
248
|
+
* @returns {number}
|
|
249
|
+
*/
|
|
250
|
+
compareOptions(a, b) {
|
|
251
|
+
const getSortKey = (option) => {
|
|
252
|
+
return option.short ? option.short.replace(/^-/, "") : option.long.replace(/^--/, "");
|
|
253
|
+
};
|
|
254
|
+
return getSortKey(a).localeCompare(getSortKey(b));
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one.
|
|
258
|
+
*
|
|
259
|
+
* @param {Command} cmd
|
|
260
|
+
* @returns {Option[]}
|
|
261
|
+
*/
|
|
262
|
+
visibleOptions(cmd) {
|
|
263
|
+
const visibleOptions = cmd.options.filter((option) => !option.hidden);
|
|
264
|
+
const helpOption = cmd._getHelpOption();
|
|
265
|
+
if (helpOption && !helpOption.hidden) {
|
|
266
|
+
const removeShort = helpOption.short && cmd._findOption(helpOption.short);
|
|
267
|
+
const removeLong = helpOption.long && cmd._findOption(helpOption.long);
|
|
268
|
+
if (!removeShort && !removeLong) visibleOptions.push(helpOption);
|
|
269
|
+
else if (helpOption.long && !removeLong) visibleOptions.push(cmd.createOption(helpOption.long, helpOption.description));
|
|
270
|
+
else if (helpOption.short && !removeShort) visibleOptions.push(cmd.createOption(helpOption.short, helpOption.description));
|
|
271
|
+
}
|
|
272
|
+
if (this.sortOptions) visibleOptions.sort(this.compareOptions);
|
|
273
|
+
return visibleOptions;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Get an array of the visible global options. (Not including help.)
|
|
277
|
+
*
|
|
278
|
+
* @param {Command} cmd
|
|
279
|
+
* @returns {Option[]}
|
|
280
|
+
*/
|
|
281
|
+
visibleGlobalOptions(cmd) {
|
|
282
|
+
if (!this.showGlobalOptions) return [];
|
|
283
|
+
const globalOptions = [];
|
|
284
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) {
|
|
285
|
+
const visibleOptions = ancestorCmd.options.filter((option) => !option.hidden);
|
|
286
|
+
globalOptions.push(...visibleOptions);
|
|
287
|
+
}
|
|
288
|
+
if (this.sortOptions) globalOptions.sort(this.compareOptions);
|
|
289
|
+
return globalOptions;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Get an array of the arguments if any have a description.
|
|
293
|
+
*
|
|
294
|
+
* @param {Command} cmd
|
|
295
|
+
* @returns {Argument[]}
|
|
296
|
+
*/
|
|
297
|
+
visibleArguments(cmd) {
|
|
298
|
+
if (cmd._argsDescription) cmd.registeredArguments.forEach((argument) => {
|
|
299
|
+
argument.description = argument.description || cmd._argsDescription[argument.name()] || "";
|
|
300
|
+
});
|
|
301
|
+
if (cmd.registeredArguments.find((argument) => argument.description)) return cmd.registeredArguments;
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Get the command term to show in the list of subcommands.
|
|
306
|
+
*
|
|
307
|
+
* @param {Command} cmd
|
|
308
|
+
* @returns {string}
|
|
309
|
+
*/
|
|
310
|
+
subcommandTerm(cmd) {
|
|
311
|
+
const args = cmd.registeredArguments.map((arg) => humanReadableArgName(arg)).join(" ");
|
|
312
|
+
return cmd._name + (cmd._aliases[0] ? "|" + cmd._aliases[0] : "") + (cmd.options.length ? " [options]" : "") + (args ? " " + args : "");
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Get the option term to show in the list of options.
|
|
316
|
+
*
|
|
317
|
+
* @param {Option} option
|
|
318
|
+
* @returns {string}
|
|
319
|
+
*/
|
|
320
|
+
optionTerm(option) {
|
|
321
|
+
return option.flags;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Get the argument term to show in the list of arguments.
|
|
325
|
+
*
|
|
326
|
+
* @param {Argument} argument
|
|
327
|
+
* @returns {string}
|
|
328
|
+
*/
|
|
329
|
+
argumentTerm(argument) {
|
|
330
|
+
return argument.name();
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Get the longest command term length.
|
|
334
|
+
*
|
|
335
|
+
* @param {Command} cmd
|
|
336
|
+
* @param {Help} helper
|
|
337
|
+
* @returns {number}
|
|
338
|
+
*/
|
|
339
|
+
longestSubcommandTermLength(cmd, helper) {
|
|
340
|
+
return helper.visibleCommands(cmd).reduce((max, command) => {
|
|
341
|
+
return Math.max(max, this.displayWidth(helper.styleSubcommandTerm(helper.subcommandTerm(command))));
|
|
342
|
+
}, 0);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Get the longest option term length.
|
|
346
|
+
*
|
|
347
|
+
* @param {Command} cmd
|
|
348
|
+
* @param {Help} helper
|
|
349
|
+
* @returns {number}
|
|
350
|
+
*/
|
|
351
|
+
longestOptionTermLength(cmd, helper) {
|
|
352
|
+
return helper.visibleOptions(cmd).reduce((max, option) => {
|
|
353
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
354
|
+
}, 0);
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Get the longest global option term length.
|
|
358
|
+
*
|
|
359
|
+
* @param {Command} cmd
|
|
360
|
+
* @param {Help} helper
|
|
361
|
+
* @returns {number}
|
|
362
|
+
*/
|
|
363
|
+
longestGlobalOptionTermLength(cmd, helper) {
|
|
364
|
+
return helper.visibleGlobalOptions(cmd).reduce((max, option) => {
|
|
365
|
+
return Math.max(max, this.displayWidth(helper.styleOptionTerm(helper.optionTerm(option))));
|
|
366
|
+
}, 0);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Get the longest argument term length.
|
|
370
|
+
*
|
|
371
|
+
* @param {Command} cmd
|
|
372
|
+
* @param {Help} helper
|
|
373
|
+
* @returns {number}
|
|
374
|
+
*/
|
|
375
|
+
longestArgumentTermLength(cmd, helper) {
|
|
376
|
+
return helper.visibleArguments(cmd).reduce((max, argument) => {
|
|
377
|
+
return Math.max(max, this.displayWidth(helper.styleArgumentTerm(helper.argumentTerm(argument))));
|
|
378
|
+
}, 0);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Get the command usage to be displayed at the top of the built-in help.
|
|
382
|
+
*
|
|
383
|
+
* @param {Command} cmd
|
|
384
|
+
* @returns {string}
|
|
385
|
+
*/
|
|
386
|
+
commandUsage(cmd) {
|
|
387
|
+
let cmdName = cmd._name;
|
|
388
|
+
if (cmd._aliases[0]) cmdName = cmdName + "|" + cmd._aliases[0];
|
|
389
|
+
let ancestorCmdNames = "";
|
|
390
|
+
for (let ancestorCmd = cmd.parent; ancestorCmd; ancestorCmd = ancestorCmd.parent) ancestorCmdNames = ancestorCmd.name() + " " + ancestorCmdNames;
|
|
391
|
+
return ancestorCmdNames + cmdName + " " + cmd.usage();
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Get the description for the command.
|
|
395
|
+
*
|
|
396
|
+
* @param {Command} cmd
|
|
397
|
+
* @returns {string}
|
|
398
|
+
*/
|
|
399
|
+
commandDescription(cmd) {
|
|
400
|
+
return cmd.description();
|
|
401
|
+
}
|
|
402
|
+
/**
|
|
403
|
+
* Get the subcommand summary to show in the list of subcommands.
|
|
404
|
+
* (Fallback to description for backwards compatibility.)
|
|
405
|
+
*
|
|
406
|
+
* @param {Command} cmd
|
|
407
|
+
* @returns {string}
|
|
408
|
+
*/
|
|
409
|
+
subcommandDescription(cmd) {
|
|
410
|
+
return cmd.summary() || cmd.description();
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Get the option description to show in the list of options.
|
|
414
|
+
*
|
|
415
|
+
* @param {Option} option
|
|
416
|
+
* @return {string}
|
|
417
|
+
*/
|
|
418
|
+
optionDescription(option) {
|
|
419
|
+
const extraInfo = [];
|
|
420
|
+
if (option.argChoices) extraInfo.push(`choices: ${option.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
421
|
+
if (option.defaultValue !== void 0) {
|
|
422
|
+
if (option.required || option.optional || option.isBoolean() && typeof option.defaultValue === "boolean") extraInfo.push(`default: ${option.defaultValueDescription || JSON.stringify(option.defaultValue)}`);
|
|
423
|
+
}
|
|
424
|
+
if (option.presetArg !== void 0 && option.optional) extraInfo.push(`preset: ${JSON.stringify(option.presetArg)}`);
|
|
425
|
+
if (option.envVar !== void 0) extraInfo.push(`env: ${option.envVar}`);
|
|
426
|
+
if (extraInfo.length > 0) {
|
|
427
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
428
|
+
if (option.description) return `${option.description} ${extraDescription}`;
|
|
429
|
+
return extraDescription;
|
|
430
|
+
}
|
|
431
|
+
return option.description;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Get the argument description to show in the list of arguments.
|
|
435
|
+
*
|
|
436
|
+
* @param {Argument} argument
|
|
437
|
+
* @return {string}
|
|
438
|
+
*/
|
|
439
|
+
argumentDescription(argument) {
|
|
440
|
+
const extraInfo = [];
|
|
441
|
+
if (argument.argChoices) extraInfo.push(`choices: ${argument.argChoices.map((choice) => JSON.stringify(choice)).join(", ")}`);
|
|
442
|
+
if (argument.defaultValue !== void 0) extraInfo.push(`default: ${argument.defaultValueDescription || JSON.stringify(argument.defaultValue)}`);
|
|
443
|
+
if (extraInfo.length > 0) {
|
|
444
|
+
const extraDescription = `(${extraInfo.join(", ")})`;
|
|
445
|
+
if (argument.description) return `${argument.description} ${extraDescription}`;
|
|
446
|
+
return extraDescription;
|
|
447
|
+
}
|
|
448
|
+
return argument.description;
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Format a list of items, given a heading and an array of formatted items.
|
|
452
|
+
*
|
|
453
|
+
* @param {string} heading
|
|
454
|
+
* @param {string[]} items
|
|
455
|
+
* @param {Help} helper
|
|
456
|
+
* @returns string[]
|
|
457
|
+
*/
|
|
458
|
+
formatItemList(heading, items, helper) {
|
|
459
|
+
if (items.length === 0) return [];
|
|
460
|
+
return [
|
|
461
|
+
helper.styleTitle(heading),
|
|
462
|
+
...items,
|
|
463
|
+
""
|
|
464
|
+
];
|
|
465
|
+
}
|
|
466
|
+
/**
|
|
467
|
+
* Group items by their help group heading.
|
|
468
|
+
*
|
|
469
|
+
* @param {Command[] | Option[]} unsortedItems
|
|
470
|
+
* @param {Command[] | Option[]} visibleItems
|
|
471
|
+
* @param {Function} getGroup
|
|
472
|
+
* @returns {Map<string, Command[] | Option[]>}
|
|
473
|
+
*/
|
|
474
|
+
groupItems(unsortedItems, visibleItems, getGroup) {
|
|
475
|
+
const result = /* @__PURE__ */ new Map();
|
|
476
|
+
unsortedItems.forEach((item) => {
|
|
477
|
+
const group = getGroup(item);
|
|
478
|
+
if (!result.has(group)) result.set(group, []);
|
|
479
|
+
});
|
|
480
|
+
visibleItems.forEach((item) => {
|
|
481
|
+
const group = getGroup(item);
|
|
482
|
+
if (!result.has(group)) result.set(group, []);
|
|
483
|
+
result.get(group).push(item);
|
|
484
|
+
});
|
|
485
|
+
return result;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Generate the built-in help text.
|
|
489
|
+
*
|
|
490
|
+
* @param {Command} cmd
|
|
491
|
+
* @param {Help} helper
|
|
492
|
+
* @returns {string}
|
|
493
|
+
*/
|
|
494
|
+
formatHelp(cmd, helper) {
|
|
495
|
+
const termWidth = helper.padWidth(cmd, helper);
|
|
496
|
+
const helpWidth = helper.helpWidth ?? 80;
|
|
497
|
+
function callFormatItem(term, description) {
|
|
498
|
+
return helper.formatItem(term, termWidth, description, helper);
|
|
499
|
+
}
|
|
500
|
+
let output = [`${helper.styleTitle("Usage:")} ${helper.styleUsage(helper.commandUsage(cmd))}`, ""];
|
|
501
|
+
const commandDescription = helper.commandDescription(cmd);
|
|
502
|
+
if (commandDescription.length > 0) output = output.concat([helper.boxWrap(helper.styleCommandDescription(commandDescription), helpWidth), ""]);
|
|
503
|
+
const argumentList = helper.visibleArguments(cmd).map((argument) => {
|
|
504
|
+
return callFormatItem(helper.styleArgumentTerm(helper.argumentTerm(argument)), helper.styleArgumentDescription(helper.argumentDescription(argument)));
|
|
505
|
+
});
|
|
506
|
+
output = output.concat(this.formatItemList("Arguments:", argumentList, helper));
|
|
507
|
+
this.groupItems(cmd.options, helper.visibleOptions(cmd), (option) => option.helpGroupHeading ?? "Options:").forEach((options, group) => {
|
|
508
|
+
const optionList = options.map((option) => {
|
|
509
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
510
|
+
});
|
|
511
|
+
output = output.concat(this.formatItemList(group, optionList, helper));
|
|
512
|
+
});
|
|
513
|
+
if (helper.showGlobalOptions) {
|
|
514
|
+
const globalOptionList = helper.visibleGlobalOptions(cmd).map((option) => {
|
|
515
|
+
return callFormatItem(helper.styleOptionTerm(helper.optionTerm(option)), helper.styleOptionDescription(helper.optionDescription(option)));
|
|
516
|
+
});
|
|
517
|
+
output = output.concat(this.formatItemList("Global Options:", globalOptionList, helper));
|
|
518
|
+
}
|
|
519
|
+
this.groupItems(cmd.commands, helper.visibleCommands(cmd), (sub) => sub.helpGroup() || "Commands:").forEach((commands, group) => {
|
|
520
|
+
const commandList = commands.map((sub) => {
|
|
521
|
+
return callFormatItem(helper.styleSubcommandTerm(helper.subcommandTerm(sub)), helper.styleSubcommandDescription(helper.subcommandDescription(sub)));
|
|
522
|
+
});
|
|
523
|
+
output = output.concat(this.formatItemList(group, commandList, helper));
|
|
524
|
+
});
|
|
525
|
+
return output.join("\n");
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations.
|
|
529
|
+
*
|
|
530
|
+
* @param {string} str
|
|
531
|
+
* @returns {number}
|
|
532
|
+
*/
|
|
533
|
+
displayWidth(str) {
|
|
534
|
+
return stripColor(str).length;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* Style the title for displaying in the help. Called with 'Usage:', 'Options:', etc.
|
|
538
|
+
*
|
|
539
|
+
* @param {string} str
|
|
540
|
+
* @returns {string}
|
|
541
|
+
*/
|
|
542
|
+
styleTitle(str) {
|
|
543
|
+
return str;
|
|
544
|
+
}
|
|
545
|
+
styleUsage(str) {
|
|
546
|
+
return str.split(" ").map((word) => {
|
|
547
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
548
|
+
if (word === "[command]") return this.styleSubcommandText(word);
|
|
549
|
+
if (word[0] === "[" || word[0] === "<") return this.styleArgumentText(word);
|
|
550
|
+
return this.styleCommandText(word);
|
|
551
|
+
}).join(" ");
|
|
552
|
+
}
|
|
553
|
+
styleCommandDescription(str) {
|
|
554
|
+
return this.styleDescriptionText(str);
|
|
555
|
+
}
|
|
556
|
+
styleOptionDescription(str) {
|
|
557
|
+
return this.styleDescriptionText(str);
|
|
558
|
+
}
|
|
559
|
+
styleSubcommandDescription(str) {
|
|
560
|
+
return this.styleDescriptionText(str);
|
|
561
|
+
}
|
|
562
|
+
styleArgumentDescription(str) {
|
|
563
|
+
return this.styleDescriptionText(str);
|
|
564
|
+
}
|
|
565
|
+
styleDescriptionText(str) {
|
|
566
|
+
return str;
|
|
567
|
+
}
|
|
568
|
+
styleOptionTerm(str) {
|
|
569
|
+
return this.styleOptionText(str);
|
|
570
|
+
}
|
|
571
|
+
styleSubcommandTerm(str) {
|
|
572
|
+
return str.split(" ").map((word) => {
|
|
573
|
+
if (word === "[options]") return this.styleOptionText(word);
|
|
574
|
+
if (word[0] === "[" || word[0] === "<") return this.styleArgumentText(word);
|
|
575
|
+
return this.styleSubcommandText(word);
|
|
576
|
+
}).join(" ");
|
|
577
|
+
}
|
|
578
|
+
styleArgumentTerm(str) {
|
|
579
|
+
return this.styleArgumentText(str);
|
|
580
|
+
}
|
|
581
|
+
styleOptionText(str) {
|
|
582
|
+
return str;
|
|
583
|
+
}
|
|
584
|
+
styleArgumentText(str) {
|
|
585
|
+
return str;
|
|
586
|
+
}
|
|
587
|
+
styleSubcommandText(str) {
|
|
588
|
+
return str;
|
|
589
|
+
}
|
|
590
|
+
styleCommandText(str) {
|
|
591
|
+
return str;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
594
|
+
* Calculate the pad width from the maximum term length.
|
|
595
|
+
*
|
|
596
|
+
* @param {Command} cmd
|
|
597
|
+
* @param {Help} helper
|
|
598
|
+
* @returns {number}
|
|
599
|
+
*/
|
|
600
|
+
padWidth(cmd, helper) {
|
|
601
|
+
return Math.max(helper.longestOptionTermLength(cmd, helper), helper.longestGlobalOptionTermLength(cmd, helper), helper.longestSubcommandTermLength(cmd, helper), helper.longestArgumentTermLength(cmd, helper));
|
|
602
|
+
}
|
|
603
|
+
/**
|
|
604
|
+
* Detect manually wrapped and indented strings by checking for line break followed by whitespace.
|
|
605
|
+
*
|
|
606
|
+
* @param {string} str
|
|
607
|
+
* @returns {boolean}
|
|
608
|
+
*/
|
|
609
|
+
preformatted(str) {
|
|
610
|
+
return /\n[^\S\r\n]/.test(str);
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
|
|
614
|
+
*
|
|
615
|
+
* So "TTT", 5, "DDD DDDD DD DDD" might be formatted for this.helpWidth=17 like so:
|
|
616
|
+
* TTT DDD DDDD
|
|
617
|
+
* DD DDD
|
|
618
|
+
*
|
|
619
|
+
* @param {string} term
|
|
620
|
+
* @param {number} termWidth
|
|
621
|
+
* @param {string} description
|
|
622
|
+
* @param {Help} helper
|
|
623
|
+
* @returns {string}
|
|
624
|
+
*/
|
|
625
|
+
formatItem(term, termWidth, description, helper) {
|
|
626
|
+
const itemIndent = 2;
|
|
627
|
+
const itemIndentStr = " ".repeat(itemIndent);
|
|
628
|
+
if (!description) return itemIndentStr + term;
|
|
629
|
+
const paddedTerm = term.padEnd(termWidth + term.length - helper.displayWidth(term));
|
|
630
|
+
const spacerWidth = 2;
|
|
631
|
+
const remainingWidth = (this.helpWidth ?? 80) - termWidth - spacerWidth - itemIndent;
|
|
632
|
+
let formattedDescription;
|
|
633
|
+
if (remainingWidth < this.minWidthToWrap || helper.preformatted(description)) formattedDescription = description;
|
|
634
|
+
else formattedDescription = helper.boxWrap(description, remainingWidth).replace(/\n/g, "\n" + " ".repeat(termWidth + spacerWidth));
|
|
635
|
+
return itemIndentStr + paddedTerm + " ".repeat(spacerWidth) + formattedDescription.replace(/\n/g, `\n${itemIndentStr}`);
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Wrap a string at whitespace, preserving existing line breaks.
|
|
639
|
+
* Wrapping is skipped if the width is less than `minWidthToWrap`.
|
|
640
|
+
*
|
|
641
|
+
* @param {string} str
|
|
642
|
+
* @param {number} width
|
|
643
|
+
* @returns {string}
|
|
644
|
+
*/
|
|
645
|
+
boxWrap(str, width) {
|
|
646
|
+
if (width < this.minWidthToWrap) return str;
|
|
647
|
+
const rawLines = str.split(/\r\n|\n/);
|
|
648
|
+
const chunkPattern = /[\s]*[^\s]+/g;
|
|
649
|
+
const wrappedLines = [];
|
|
650
|
+
rawLines.forEach((line) => {
|
|
651
|
+
const chunks = line.match(chunkPattern);
|
|
652
|
+
if (chunks === null) {
|
|
653
|
+
wrappedLines.push("");
|
|
654
|
+
return;
|
|
655
|
+
}
|
|
656
|
+
let sumChunks = [chunks.shift()];
|
|
657
|
+
let sumWidth = this.displayWidth(sumChunks[0]);
|
|
658
|
+
chunks.forEach((chunk) => {
|
|
659
|
+
const visibleWidth = this.displayWidth(chunk);
|
|
660
|
+
if (sumWidth + visibleWidth <= width) {
|
|
661
|
+
sumChunks.push(chunk);
|
|
662
|
+
sumWidth += visibleWidth;
|
|
663
|
+
return;
|
|
664
|
+
}
|
|
665
|
+
wrappedLines.push(sumChunks.join(""));
|
|
666
|
+
const nextChunk = chunk.trimStart();
|
|
667
|
+
sumChunks = [nextChunk];
|
|
668
|
+
sumWidth = this.displayWidth(nextChunk);
|
|
669
|
+
});
|
|
670
|
+
wrappedLines.push(sumChunks.join(""));
|
|
671
|
+
});
|
|
672
|
+
return wrappedLines.join("\n");
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
/**
|
|
676
|
+
* Strip style ANSI escape sequences from the string. In particular, SGR (Select Graphic Rendition) codes.
|
|
677
|
+
*
|
|
678
|
+
* @param {string} str
|
|
679
|
+
* @returns {string}
|
|
680
|
+
* @package
|
|
681
|
+
*/
|
|
682
|
+
function stripColor(str) {
|
|
683
|
+
return str.replace(/\x1b\[\d*(;\d*)*m/g, "");
|
|
684
|
+
}
|
|
685
|
+
exports.Help = Help;
|
|
686
|
+
exports.stripColor = stripColor;
|
|
687
|
+
}));
|
|
688
|
+
|
|
689
|
+
//#endregion
|
|
690
|
+
//#region node_modules/commander/lib/option.js
|
|
691
|
+
var require_option = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
692
|
+
const { InvalidArgumentError } = require_error();
|
|
693
|
+
var Option = class {
|
|
694
|
+
/**
|
|
695
|
+
* Initialize a new `Option` with the given `flags` and `description`.
|
|
696
|
+
*
|
|
697
|
+
* @param {string} flags
|
|
698
|
+
* @param {string} [description]
|
|
699
|
+
*/
|
|
700
|
+
constructor(flags, description) {
|
|
701
|
+
this.flags = flags;
|
|
702
|
+
this.description = description || "";
|
|
703
|
+
this.required = flags.includes("<");
|
|
704
|
+
this.optional = flags.includes("[");
|
|
705
|
+
this.variadic = /\w\.\.\.[>\]]$/.test(flags);
|
|
706
|
+
this.mandatory = false;
|
|
707
|
+
const optionFlags = splitOptionFlags(flags);
|
|
708
|
+
this.short = optionFlags.shortFlag;
|
|
709
|
+
this.long = optionFlags.longFlag;
|
|
710
|
+
this.negate = false;
|
|
711
|
+
if (this.long) this.negate = this.long.startsWith("--no-");
|
|
712
|
+
this.defaultValue = void 0;
|
|
713
|
+
this.defaultValueDescription = void 0;
|
|
714
|
+
this.presetArg = void 0;
|
|
715
|
+
this.envVar = void 0;
|
|
716
|
+
this.parseArg = void 0;
|
|
717
|
+
this.hidden = false;
|
|
718
|
+
this.argChoices = void 0;
|
|
719
|
+
this.conflictsWith = [];
|
|
720
|
+
this.implied = void 0;
|
|
721
|
+
this.helpGroupHeading = void 0;
|
|
722
|
+
}
|
|
723
|
+
/**
|
|
724
|
+
* Set the default value, and optionally supply the description to be displayed in the help.
|
|
725
|
+
*
|
|
726
|
+
* @param {*} value
|
|
727
|
+
* @param {string} [description]
|
|
728
|
+
* @return {Option}
|
|
729
|
+
*/
|
|
730
|
+
default(value, description) {
|
|
731
|
+
this.defaultValue = value;
|
|
732
|
+
this.defaultValueDescription = description;
|
|
733
|
+
return this;
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Preset to use when option used without option-argument, especially optional but also boolean and negated.
|
|
737
|
+
* The custom processing (parseArg) is called.
|
|
738
|
+
*
|
|
739
|
+
* @example
|
|
740
|
+
* new Option('--color').default('GREYSCALE').preset('RGB');
|
|
741
|
+
* new Option('--donate [amount]').preset('20').argParser(parseFloat);
|
|
742
|
+
*
|
|
743
|
+
* @param {*} arg
|
|
744
|
+
* @return {Option}
|
|
745
|
+
*/
|
|
746
|
+
preset(arg) {
|
|
747
|
+
this.presetArg = arg;
|
|
748
|
+
return this;
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Add option name(s) that conflict with this option.
|
|
752
|
+
* An error will be displayed if conflicting options are found during parsing.
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* new Option('--rgb').conflicts('cmyk');
|
|
756
|
+
* new Option('--js').conflicts(['ts', 'jsx']);
|
|
757
|
+
*
|
|
758
|
+
* @param {(string | string[])} names
|
|
759
|
+
* @return {Option}
|
|
760
|
+
*/
|
|
761
|
+
conflicts(names) {
|
|
762
|
+
this.conflictsWith = this.conflictsWith.concat(names);
|
|
763
|
+
return this;
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Specify implied option values for when this option is set and the implied options are not.
|
|
767
|
+
*
|
|
768
|
+
* The custom processing (parseArg) is not called on the implied values.
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
* program
|
|
772
|
+
* .addOption(new Option('--log', 'write logging information to file'))
|
|
773
|
+
* .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
|
|
774
|
+
*
|
|
775
|
+
* @param {object} impliedOptionValues
|
|
776
|
+
* @return {Option}
|
|
777
|
+
*/
|
|
778
|
+
implies(impliedOptionValues) {
|
|
779
|
+
let newImplied = impliedOptionValues;
|
|
780
|
+
if (typeof impliedOptionValues === "string") newImplied = { [impliedOptionValues]: true };
|
|
781
|
+
this.implied = Object.assign(this.implied || {}, newImplied);
|
|
782
|
+
return this;
|
|
783
|
+
}
|
|
784
|
+
/**
|
|
785
|
+
* Set environment variable to check for option value.
|
|
786
|
+
*
|
|
787
|
+
* An environment variable is only used if when processed the current option value is
|
|
788
|
+
* undefined, or the source of the current value is 'default' or 'config' or 'env'.
|
|
789
|
+
*
|
|
790
|
+
* @param {string} name
|
|
791
|
+
* @return {Option}
|
|
792
|
+
*/
|
|
793
|
+
env(name) {
|
|
794
|
+
this.envVar = name;
|
|
795
|
+
return this;
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Set the custom handler for processing CLI option arguments into option values.
|
|
799
|
+
*
|
|
800
|
+
* @param {Function} [fn]
|
|
801
|
+
* @return {Option}
|
|
802
|
+
*/
|
|
803
|
+
argParser(fn) {
|
|
804
|
+
this.parseArg = fn;
|
|
805
|
+
return this;
|
|
806
|
+
}
|
|
807
|
+
/**
|
|
808
|
+
* Whether the option is mandatory and must have a value after parsing.
|
|
809
|
+
*
|
|
810
|
+
* @param {boolean} [mandatory=true]
|
|
811
|
+
* @return {Option}
|
|
812
|
+
*/
|
|
813
|
+
makeOptionMandatory(mandatory = true) {
|
|
814
|
+
this.mandatory = !!mandatory;
|
|
815
|
+
return this;
|
|
816
|
+
}
|
|
817
|
+
/**
|
|
818
|
+
* Hide option in help.
|
|
819
|
+
*
|
|
820
|
+
* @param {boolean} [hide=true]
|
|
821
|
+
* @return {Option}
|
|
822
|
+
*/
|
|
823
|
+
hideHelp(hide = true) {
|
|
824
|
+
this.hidden = !!hide;
|
|
825
|
+
return this;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* @package
|
|
829
|
+
*/
|
|
830
|
+
_collectValue(value, previous) {
|
|
831
|
+
if (previous === this.defaultValue || !Array.isArray(previous)) return [value];
|
|
832
|
+
previous.push(value);
|
|
833
|
+
return previous;
|
|
834
|
+
}
|
|
835
|
+
/**
|
|
836
|
+
* Only allow option value to be one of choices.
|
|
837
|
+
*
|
|
838
|
+
* @param {string[]} values
|
|
839
|
+
* @return {Option}
|
|
840
|
+
*/
|
|
841
|
+
choices(values) {
|
|
842
|
+
this.argChoices = values.slice();
|
|
843
|
+
this.parseArg = (arg, previous) => {
|
|
844
|
+
if (!this.argChoices.includes(arg)) throw new InvalidArgumentError(`Allowed choices are ${this.argChoices.join(", ")}.`);
|
|
845
|
+
if (this.variadic) return this._collectValue(arg, previous);
|
|
846
|
+
return arg;
|
|
847
|
+
};
|
|
848
|
+
return this;
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Return option name.
|
|
852
|
+
*
|
|
853
|
+
* @return {string}
|
|
854
|
+
*/
|
|
855
|
+
name() {
|
|
856
|
+
if (this.long) return this.long.replace(/^--/, "");
|
|
857
|
+
return this.short.replace(/^-/, "");
|
|
858
|
+
}
|
|
859
|
+
/**
|
|
860
|
+
* Return option name, in a camelcase format that can be used
|
|
861
|
+
* as an object attribute key.
|
|
862
|
+
*
|
|
863
|
+
* @return {string}
|
|
864
|
+
*/
|
|
865
|
+
attributeName() {
|
|
866
|
+
if (this.negate) return camelcase(this.name().replace(/^no-/, ""));
|
|
867
|
+
return camelcase(this.name());
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
* Set the help group heading.
|
|
871
|
+
*
|
|
872
|
+
* @param {string} heading
|
|
873
|
+
* @return {Option}
|
|
874
|
+
*/
|
|
875
|
+
helpGroup(heading) {
|
|
876
|
+
this.helpGroupHeading = heading;
|
|
877
|
+
return this;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Check if `arg` matches the short or long flag.
|
|
881
|
+
*
|
|
882
|
+
* @param {string} arg
|
|
883
|
+
* @return {boolean}
|
|
884
|
+
* @package
|
|
885
|
+
*/
|
|
886
|
+
is(arg) {
|
|
887
|
+
return this.short === arg || this.long === arg;
|
|
888
|
+
}
|
|
889
|
+
/**
|
|
890
|
+
* Return whether a boolean option.
|
|
891
|
+
*
|
|
892
|
+
* Options are one of boolean, negated, required argument, or optional argument.
|
|
893
|
+
*
|
|
894
|
+
* @return {boolean}
|
|
895
|
+
* @package
|
|
896
|
+
*/
|
|
897
|
+
isBoolean() {
|
|
898
|
+
return !this.required && !this.optional && !this.negate;
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
/**
|
|
902
|
+
* This class is to make it easier to work with dual options, without changing the existing
|
|
903
|
+
* implementation. We support separate dual options for separate positive and negative options,
|
|
904
|
+
* like `--build` and `--no-build`, which share a single option value. This works nicely for some
|
|
905
|
+
* use cases, but is tricky for others where we want separate behaviours despite
|
|
906
|
+
* the single shared option value.
|
|
907
|
+
*/
|
|
908
|
+
var DualOptions = class {
|
|
909
|
+
/**
|
|
910
|
+
* @param {Option[]} options
|
|
911
|
+
*/
|
|
912
|
+
constructor(options) {
|
|
913
|
+
this.positiveOptions = /* @__PURE__ */ new Map();
|
|
914
|
+
this.negativeOptions = /* @__PURE__ */ new Map();
|
|
915
|
+
this.dualOptions = /* @__PURE__ */ new Set();
|
|
916
|
+
options.forEach((option) => {
|
|
917
|
+
if (option.negate) this.negativeOptions.set(option.attributeName(), option);
|
|
918
|
+
else this.positiveOptions.set(option.attributeName(), option);
|
|
919
|
+
});
|
|
920
|
+
this.negativeOptions.forEach((value, key) => {
|
|
921
|
+
if (this.positiveOptions.has(key)) this.dualOptions.add(key);
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
/**
|
|
925
|
+
* Did the value come from the option, and not from possible matching dual option?
|
|
926
|
+
*
|
|
927
|
+
* @param {*} value
|
|
928
|
+
* @param {Option} option
|
|
929
|
+
* @returns {boolean}
|
|
930
|
+
*/
|
|
931
|
+
valueFromOption(value, option) {
|
|
932
|
+
const optionKey = option.attributeName();
|
|
933
|
+
if (!this.dualOptions.has(optionKey)) return true;
|
|
934
|
+
const preset = this.negativeOptions.get(optionKey).presetArg;
|
|
935
|
+
const negativeValue = preset !== void 0 ? preset : false;
|
|
936
|
+
return option.negate === (negativeValue === value);
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
/**
|
|
940
|
+
* Convert string from kebab-case to camelCase.
|
|
941
|
+
*
|
|
942
|
+
* @param {string} str
|
|
943
|
+
* @return {string}
|
|
944
|
+
* @private
|
|
945
|
+
*/
|
|
946
|
+
function camelcase(str) {
|
|
947
|
+
return str.split("-").reduce((str, word) => {
|
|
948
|
+
return str + word[0].toUpperCase() + word.slice(1);
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
/**
|
|
952
|
+
* Split the short and long flag out of something like '-m,--mixed <value>'
|
|
953
|
+
*
|
|
954
|
+
* @private
|
|
955
|
+
*/
|
|
956
|
+
function splitOptionFlags(flags) {
|
|
957
|
+
let shortFlag;
|
|
958
|
+
let longFlag;
|
|
959
|
+
const shortFlagExp = /^-[^-]$/;
|
|
960
|
+
const longFlagExp = /^--[^-]/;
|
|
961
|
+
const flagParts = flags.split(/[ |,]+/).concat("guard");
|
|
962
|
+
if (shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
963
|
+
if (longFlagExp.test(flagParts[0])) longFlag = flagParts.shift();
|
|
964
|
+
if (!shortFlag && shortFlagExp.test(flagParts[0])) shortFlag = flagParts.shift();
|
|
965
|
+
if (!shortFlag && longFlagExp.test(flagParts[0])) {
|
|
966
|
+
shortFlag = longFlag;
|
|
967
|
+
longFlag = flagParts.shift();
|
|
968
|
+
}
|
|
969
|
+
if (flagParts[0].startsWith("-")) {
|
|
970
|
+
const unsupportedFlag = flagParts[0];
|
|
971
|
+
const baseError = `option creation failed due to '${unsupportedFlag}' in option flags '${flags}'`;
|
|
972
|
+
if (/^-[^-][^-]/.test(unsupportedFlag)) throw new Error(`${baseError}
|
|
973
|
+
- a short flag is a single dash and a single character
|
|
974
|
+
- either use a single dash and a single character (for a short flag)
|
|
975
|
+
- or use a double dash for a long option (and can have two, like '--ws, --workspace')`);
|
|
976
|
+
if (shortFlagExp.test(unsupportedFlag)) throw new Error(`${baseError}
|
|
977
|
+
- too many short flags`);
|
|
978
|
+
if (longFlagExp.test(unsupportedFlag)) throw new Error(`${baseError}
|
|
979
|
+
- too many long flags`);
|
|
980
|
+
throw new Error(`${baseError}
|
|
981
|
+
- unrecognised flag format`);
|
|
982
|
+
}
|
|
983
|
+
if (shortFlag === void 0 && longFlag === void 0) throw new Error(`option creation failed due to no flags found in '${flags}'.`);
|
|
984
|
+
return {
|
|
985
|
+
shortFlag,
|
|
986
|
+
longFlag
|
|
987
|
+
};
|
|
988
|
+
}
|
|
989
|
+
exports.Option = Option;
|
|
990
|
+
exports.DualOptions = DualOptions;
|
|
991
|
+
}));
|
|
992
|
+
|
|
993
|
+
//#endregion
|
|
994
|
+
//#region node_modules/commander/lib/suggestSimilar.js
|
|
995
|
+
var require_suggestSimilar = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
996
|
+
const maxDistance = 3;
|
|
997
|
+
function editDistance(a, b) {
|
|
998
|
+
if (Math.abs(a.length - b.length) > maxDistance) return Math.max(a.length, b.length);
|
|
999
|
+
const d = [];
|
|
1000
|
+
for (let i = 0; i <= a.length; i++) d[i] = [i];
|
|
1001
|
+
for (let j = 0; j <= b.length; j++) d[0][j] = j;
|
|
1002
|
+
for (let j = 1; j <= b.length; j++) for (let i = 1; i <= a.length; i++) {
|
|
1003
|
+
let cost = 1;
|
|
1004
|
+
if (a[i - 1] === b[j - 1]) cost = 0;
|
|
1005
|
+
else cost = 1;
|
|
1006
|
+
d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
|
|
1007
|
+
if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
|
|
1008
|
+
}
|
|
1009
|
+
return d[a.length][b.length];
|
|
1010
|
+
}
|
|
1011
|
+
/**
|
|
1012
|
+
* Find close matches, restricted to same number of edits.
|
|
1013
|
+
*
|
|
1014
|
+
* @param {string} word
|
|
1015
|
+
* @param {string[]} candidates
|
|
1016
|
+
* @returns {string}
|
|
1017
|
+
*/
|
|
1018
|
+
function suggestSimilar(word, candidates) {
|
|
1019
|
+
if (!candidates || candidates.length === 0) return "";
|
|
1020
|
+
candidates = Array.from(new Set(candidates));
|
|
1021
|
+
const searchingOptions = word.startsWith("--");
|
|
1022
|
+
if (searchingOptions) {
|
|
1023
|
+
word = word.slice(2);
|
|
1024
|
+
candidates = candidates.map((candidate) => candidate.slice(2));
|
|
1025
|
+
}
|
|
1026
|
+
let similar = [];
|
|
1027
|
+
let bestDistance = maxDistance;
|
|
1028
|
+
const minSimilarity = .4;
|
|
1029
|
+
candidates.forEach((candidate) => {
|
|
1030
|
+
if (candidate.length <= 1) return;
|
|
1031
|
+
const distance = editDistance(word, candidate);
|
|
1032
|
+
const length = Math.max(word.length, candidate.length);
|
|
1033
|
+
if ((length - distance) / length > minSimilarity) {
|
|
1034
|
+
if (distance < bestDistance) {
|
|
1035
|
+
bestDistance = distance;
|
|
1036
|
+
similar = [candidate];
|
|
1037
|
+
} else if (distance === bestDistance) similar.push(candidate);
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
similar.sort((a, b) => a.localeCompare(b));
|
|
1041
|
+
if (searchingOptions) similar = similar.map((candidate) => `--${candidate}`);
|
|
1042
|
+
if (similar.length > 1) return `\n(Did you mean one of ${similar.join(", ")}?)`;
|
|
1043
|
+
if (similar.length === 1) return `\n(Did you mean ${similar[0]}?)`;
|
|
1044
|
+
return "";
|
|
1045
|
+
}
|
|
1046
|
+
exports.suggestSimilar = suggestSimilar;
|
|
1047
|
+
}));
|
|
1048
|
+
|
|
1049
|
+
//#endregion
|
|
1050
|
+
//#region node_modules/commander/lib/command.js
|
|
1051
|
+
var require_command = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1052
|
+
const EventEmitter = __require("node:events").EventEmitter;
|
|
1053
|
+
const childProcess = __require("node:child_process");
|
|
1054
|
+
const path = __require("node:path");
|
|
1055
|
+
const fs = __require("node:fs");
|
|
1056
|
+
const process$1 = __require("node:process");
|
|
1057
|
+
const { Argument, humanReadableArgName } = require_argument();
|
|
1058
|
+
const { CommanderError } = require_error();
|
|
1059
|
+
const { Help, stripColor } = require_help();
|
|
1060
|
+
const { Option, DualOptions } = require_option();
|
|
1061
|
+
const { suggestSimilar } = require_suggestSimilar();
|
|
1062
|
+
var Command = class Command extends EventEmitter {
|
|
1063
|
+
/**
|
|
1064
|
+
* Initialize a new `Command`.
|
|
1065
|
+
*
|
|
1066
|
+
* @param {string} [name]
|
|
1067
|
+
*/
|
|
1068
|
+
constructor(name) {
|
|
1069
|
+
super();
|
|
1070
|
+
/** @type {Command[]} */
|
|
1071
|
+
this.commands = [];
|
|
1072
|
+
/** @type {Option[]} */
|
|
1073
|
+
this.options = [];
|
|
1074
|
+
this.parent = null;
|
|
1075
|
+
this._allowUnknownOption = false;
|
|
1076
|
+
this._allowExcessArguments = false;
|
|
1077
|
+
/** @type {Argument[]} */
|
|
1078
|
+
this.registeredArguments = [];
|
|
1079
|
+
this._args = this.registeredArguments;
|
|
1080
|
+
/** @type {string[]} */
|
|
1081
|
+
this.args = [];
|
|
1082
|
+
this.rawArgs = [];
|
|
1083
|
+
this.processedArgs = [];
|
|
1084
|
+
this._scriptPath = null;
|
|
1085
|
+
this._name = name || "";
|
|
1086
|
+
this._optionValues = {};
|
|
1087
|
+
this._optionValueSources = {};
|
|
1088
|
+
this._storeOptionsAsProperties = false;
|
|
1089
|
+
this._actionHandler = null;
|
|
1090
|
+
this._executableHandler = false;
|
|
1091
|
+
this._executableFile = null;
|
|
1092
|
+
this._executableDir = null;
|
|
1093
|
+
this._defaultCommandName = null;
|
|
1094
|
+
this._exitCallback = null;
|
|
1095
|
+
this._aliases = [];
|
|
1096
|
+
this._combineFlagAndOptionalValue = true;
|
|
1097
|
+
this._description = "";
|
|
1098
|
+
this._summary = "";
|
|
1099
|
+
this._argsDescription = void 0;
|
|
1100
|
+
this._enablePositionalOptions = false;
|
|
1101
|
+
this._passThroughOptions = false;
|
|
1102
|
+
this._lifeCycleHooks = {};
|
|
1103
|
+
/** @type {(boolean | string)} */
|
|
1104
|
+
this._showHelpAfterError = false;
|
|
1105
|
+
this._showSuggestionAfterError = true;
|
|
1106
|
+
this._savedState = null;
|
|
1107
|
+
this._outputConfiguration = {
|
|
1108
|
+
writeOut: (str) => process$1.stdout.write(str),
|
|
1109
|
+
writeErr: (str) => process$1.stderr.write(str),
|
|
1110
|
+
outputError: (str, write) => write(str),
|
|
1111
|
+
getOutHelpWidth: () => process$1.stdout.isTTY ? process$1.stdout.columns : void 0,
|
|
1112
|
+
getErrHelpWidth: () => process$1.stderr.isTTY ? process$1.stderr.columns : void 0,
|
|
1113
|
+
getOutHasColors: () => useColor() ?? (process$1.stdout.isTTY && process$1.stdout.hasColors?.()),
|
|
1114
|
+
getErrHasColors: () => useColor() ?? (process$1.stderr.isTTY && process$1.stderr.hasColors?.()),
|
|
1115
|
+
stripColor: (str) => stripColor(str)
|
|
1116
|
+
};
|
|
1117
|
+
this._hidden = false;
|
|
1118
|
+
/** @type {(Option | null | undefined)} */
|
|
1119
|
+
this._helpOption = void 0;
|
|
1120
|
+
this._addImplicitHelpCommand = void 0;
|
|
1121
|
+
/** @type {Command} */
|
|
1122
|
+
this._helpCommand = void 0;
|
|
1123
|
+
this._helpConfiguration = {};
|
|
1124
|
+
/** @type {string | undefined} */
|
|
1125
|
+
this._helpGroupHeading = void 0;
|
|
1126
|
+
/** @type {string | undefined} */
|
|
1127
|
+
this._defaultCommandGroup = void 0;
|
|
1128
|
+
/** @type {string | undefined} */
|
|
1129
|
+
this._defaultOptionGroup = void 0;
|
|
1130
|
+
}
|
|
1131
|
+
/**
|
|
1132
|
+
* Copy settings that are useful to have in common across root command and subcommands.
|
|
1133
|
+
*
|
|
1134
|
+
* (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
|
|
1135
|
+
*
|
|
1136
|
+
* @param {Command} sourceCommand
|
|
1137
|
+
* @return {Command} `this` command for chaining
|
|
1138
|
+
*/
|
|
1139
|
+
copyInheritedSettings(sourceCommand) {
|
|
1140
|
+
this._outputConfiguration = sourceCommand._outputConfiguration;
|
|
1141
|
+
this._helpOption = sourceCommand._helpOption;
|
|
1142
|
+
this._helpCommand = sourceCommand._helpCommand;
|
|
1143
|
+
this._helpConfiguration = sourceCommand._helpConfiguration;
|
|
1144
|
+
this._exitCallback = sourceCommand._exitCallback;
|
|
1145
|
+
this._storeOptionsAsProperties = sourceCommand._storeOptionsAsProperties;
|
|
1146
|
+
this._combineFlagAndOptionalValue = sourceCommand._combineFlagAndOptionalValue;
|
|
1147
|
+
this._allowExcessArguments = sourceCommand._allowExcessArguments;
|
|
1148
|
+
this._enablePositionalOptions = sourceCommand._enablePositionalOptions;
|
|
1149
|
+
this._showHelpAfterError = sourceCommand._showHelpAfterError;
|
|
1150
|
+
this._showSuggestionAfterError = sourceCommand._showSuggestionAfterError;
|
|
1151
|
+
return this;
|
|
1152
|
+
}
|
|
1153
|
+
/**
|
|
1154
|
+
* @returns {Command[]}
|
|
1155
|
+
* @private
|
|
1156
|
+
*/
|
|
1157
|
+
_getCommandAndAncestors() {
|
|
1158
|
+
const result = [];
|
|
1159
|
+
for (let command = this; command; command = command.parent) result.push(command);
|
|
1160
|
+
return result;
|
|
1161
|
+
}
|
|
1162
|
+
/**
|
|
1163
|
+
* Define a command.
|
|
1164
|
+
*
|
|
1165
|
+
* There are two styles of command: pay attention to where to put the description.
|
|
1166
|
+
*
|
|
1167
|
+
* @example
|
|
1168
|
+
* // Command implemented using action handler (description is supplied separately to `.command`)
|
|
1169
|
+
* program
|
|
1170
|
+
* .command('clone <source> [destination]')
|
|
1171
|
+
* .description('clone a repository into a newly created directory')
|
|
1172
|
+
* .action((source, destination) => {
|
|
1173
|
+
* console.log('clone command called');
|
|
1174
|
+
* });
|
|
1175
|
+
*
|
|
1176
|
+
* // Command implemented using separate executable file (description is second parameter to `.command`)
|
|
1177
|
+
* program
|
|
1178
|
+
* .command('start <service>', 'start named service')
|
|
1179
|
+
* .command('stop [service]', 'stop named service, or all if no name supplied');
|
|
1180
|
+
*
|
|
1181
|
+
* @param {string} nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...`
|
|
1182
|
+
* @param {(object | string)} [actionOptsOrExecDesc] - configuration options (for action), or description (for executable)
|
|
1183
|
+
* @param {object} [execOpts] - configuration options (for executable)
|
|
1184
|
+
* @return {Command} returns new command for action handler, or `this` for executable command
|
|
1185
|
+
*/
|
|
1186
|
+
command(nameAndArgs, actionOptsOrExecDesc, execOpts) {
|
|
1187
|
+
let desc = actionOptsOrExecDesc;
|
|
1188
|
+
let opts = execOpts;
|
|
1189
|
+
if (typeof desc === "object" && desc !== null) {
|
|
1190
|
+
opts = desc;
|
|
1191
|
+
desc = null;
|
|
1192
|
+
}
|
|
1193
|
+
opts = opts || {};
|
|
1194
|
+
const [, name, args] = nameAndArgs.match(/([^ ]+) *(.*)/);
|
|
1195
|
+
const cmd = this.createCommand(name);
|
|
1196
|
+
if (desc) {
|
|
1197
|
+
cmd.description(desc);
|
|
1198
|
+
cmd._executableHandler = true;
|
|
1199
|
+
}
|
|
1200
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
1201
|
+
cmd._hidden = !!(opts.noHelp || opts.hidden);
|
|
1202
|
+
cmd._executableFile = opts.executableFile || null;
|
|
1203
|
+
if (args) cmd.arguments(args);
|
|
1204
|
+
this._registerCommand(cmd);
|
|
1205
|
+
cmd.parent = this;
|
|
1206
|
+
cmd.copyInheritedSettings(this);
|
|
1207
|
+
if (desc) return this;
|
|
1208
|
+
return cmd;
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Factory routine to create a new unattached command.
|
|
1212
|
+
*
|
|
1213
|
+
* See .command() for creating an attached subcommand, which uses this routine to
|
|
1214
|
+
* create the command. You can override createCommand to customise subcommands.
|
|
1215
|
+
*
|
|
1216
|
+
* @param {string} [name]
|
|
1217
|
+
* @return {Command} new command
|
|
1218
|
+
*/
|
|
1219
|
+
createCommand(name) {
|
|
1220
|
+
return new Command(name);
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* You can customise the help with a subclass of Help by overriding createHelp,
|
|
1224
|
+
* or by overriding Help properties using configureHelp().
|
|
1225
|
+
*
|
|
1226
|
+
* @return {Help}
|
|
1227
|
+
*/
|
|
1228
|
+
createHelp() {
|
|
1229
|
+
return Object.assign(new Help(), this.configureHelp());
|
|
1230
|
+
}
|
|
1231
|
+
/**
|
|
1232
|
+
* You can customise the help by overriding Help properties using configureHelp(),
|
|
1233
|
+
* or with a subclass of Help by overriding createHelp().
|
|
1234
|
+
*
|
|
1235
|
+
* @param {object} [configuration] - configuration options
|
|
1236
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1237
|
+
*/
|
|
1238
|
+
configureHelp(configuration) {
|
|
1239
|
+
if (configuration === void 0) return this._helpConfiguration;
|
|
1240
|
+
this._helpConfiguration = configuration;
|
|
1241
|
+
return this;
|
|
1242
|
+
}
|
|
1243
|
+
/**
|
|
1244
|
+
* The default output goes to stdout and stderr. You can customise this for special
|
|
1245
|
+
* applications. You can also customise the display of errors by overriding outputError.
|
|
1246
|
+
*
|
|
1247
|
+
* The configuration properties are all functions:
|
|
1248
|
+
*
|
|
1249
|
+
* // change how output being written, defaults to stdout and stderr
|
|
1250
|
+
* writeOut(str)
|
|
1251
|
+
* writeErr(str)
|
|
1252
|
+
* // change how output being written for errors, defaults to writeErr
|
|
1253
|
+
* outputError(str, write) // used for displaying errors and not used for displaying help
|
|
1254
|
+
* // specify width for wrapping help
|
|
1255
|
+
* getOutHelpWidth()
|
|
1256
|
+
* getErrHelpWidth()
|
|
1257
|
+
* // color support, currently only used with Help
|
|
1258
|
+
* getOutHasColors()
|
|
1259
|
+
* getErrHasColors()
|
|
1260
|
+
* stripColor() // used to remove ANSI escape codes if output does not have colors
|
|
1261
|
+
*
|
|
1262
|
+
* @param {object} [configuration] - configuration options
|
|
1263
|
+
* @return {(Command | object)} `this` command for chaining, or stored configuration
|
|
1264
|
+
*/
|
|
1265
|
+
configureOutput(configuration) {
|
|
1266
|
+
if (configuration === void 0) return this._outputConfiguration;
|
|
1267
|
+
this._outputConfiguration = {
|
|
1268
|
+
...this._outputConfiguration,
|
|
1269
|
+
...configuration
|
|
1270
|
+
};
|
|
1271
|
+
return this;
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Display the help or a custom message after an error occurs.
|
|
1275
|
+
*
|
|
1276
|
+
* @param {(boolean|string)} [displayHelp]
|
|
1277
|
+
* @return {Command} `this` command for chaining
|
|
1278
|
+
*/
|
|
1279
|
+
showHelpAfterError(displayHelp = true) {
|
|
1280
|
+
if (typeof displayHelp !== "string") displayHelp = !!displayHelp;
|
|
1281
|
+
this._showHelpAfterError = displayHelp;
|
|
1282
|
+
return this;
|
|
1283
|
+
}
|
|
1284
|
+
/**
|
|
1285
|
+
* Display suggestion of similar commands for unknown commands, or options for unknown options.
|
|
1286
|
+
*
|
|
1287
|
+
* @param {boolean} [displaySuggestion]
|
|
1288
|
+
* @return {Command} `this` command for chaining
|
|
1289
|
+
*/
|
|
1290
|
+
showSuggestionAfterError(displaySuggestion = true) {
|
|
1291
|
+
this._showSuggestionAfterError = !!displaySuggestion;
|
|
1292
|
+
return this;
|
|
1293
|
+
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Add a prepared subcommand.
|
|
1296
|
+
*
|
|
1297
|
+
* See .command() for creating an attached subcommand which inherits settings from its parent.
|
|
1298
|
+
*
|
|
1299
|
+
* @param {Command} cmd - new subcommand
|
|
1300
|
+
* @param {object} [opts] - configuration options
|
|
1301
|
+
* @return {Command} `this` command for chaining
|
|
1302
|
+
*/
|
|
1303
|
+
addCommand(cmd, opts) {
|
|
1304
|
+
if (!cmd._name) throw new Error(`Command passed to .addCommand() must have a name
|
|
1305
|
+
- specify the name in Command constructor or using .name()`);
|
|
1306
|
+
opts = opts || {};
|
|
1307
|
+
if (opts.isDefault) this._defaultCommandName = cmd._name;
|
|
1308
|
+
if (opts.noHelp || opts.hidden) cmd._hidden = true;
|
|
1309
|
+
this._registerCommand(cmd);
|
|
1310
|
+
cmd.parent = this;
|
|
1311
|
+
cmd._checkForBrokenPassThrough();
|
|
1312
|
+
return this;
|
|
1313
|
+
}
|
|
1314
|
+
/**
|
|
1315
|
+
* Factory routine to create a new unattached argument.
|
|
1316
|
+
*
|
|
1317
|
+
* See .argument() for creating an attached argument, which uses this routine to
|
|
1318
|
+
* create the argument. You can override createArgument to return a custom argument.
|
|
1319
|
+
*
|
|
1320
|
+
* @param {string} name
|
|
1321
|
+
* @param {string} [description]
|
|
1322
|
+
* @return {Argument} new argument
|
|
1323
|
+
*/
|
|
1324
|
+
createArgument(name, description) {
|
|
1325
|
+
return new Argument(name, description);
|
|
1326
|
+
}
|
|
1327
|
+
/**
|
|
1328
|
+
* Define argument syntax for command.
|
|
1329
|
+
*
|
|
1330
|
+
* The default is that the argument is required, and you can explicitly
|
|
1331
|
+
* indicate this with <> around the name. Put [] around the name for an optional argument.
|
|
1332
|
+
*
|
|
1333
|
+
* @example
|
|
1334
|
+
* program.argument('<input-file>');
|
|
1335
|
+
* program.argument('[output-file]');
|
|
1336
|
+
*
|
|
1337
|
+
* @param {string} name
|
|
1338
|
+
* @param {string} [description]
|
|
1339
|
+
* @param {(Function|*)} [parseArg] - custom argument processing function or default value
|
|
1340
|
+
* @param {*} [defaultValue]
|
|
1341
|
+
* @return {Command} `this` command for chaining
|
|
1342
|
+
*/
|
|
1343
|
+
argument(name, description, parseArg, defaultValue) {
|
|
1344
|
+
const argument = this.createArgument(name, description);
|
|
1345
|
+
if (typeof parseArg === "function") argument.default(defaultValue).argParser(parseArg);
|
|
1346
|
+
else argument.default(parseArg);
|
|
1347
|
+
this.addArgument(argument);
|
|
1348
|
+
return this;
|
|
1349
|
+
}
|
|
1350
|
+
/**
|
|
1351
|
+
* Define argument syntax for command, adding multiple at once (without descriptions).
|
|
1352
|
+
*
|
|
1353
|
+
* See also .argument().
|
|
1354
|
+
*
|
|
1355
|
+
* @example
|
|
1356
|
+
* program.arguments('<cmd> [env]');
|
|
1357
|
+
*
|
|
1358
|
+
* @param {string} names
|
|
1359
|
+
* @return {Command} `this` command for chaining
|
|
1360
|
+
*/
|
|
1361
|
+
arguments(names) {
|
|
1362
|
+
names.trim().split(/ +/).forEach((detail) => {
|
|
1363
|
+
this.argument(detail);
|
|
1364
|
+
});
|
|
1365
|
+
return this;
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Define argument syntax for command, adding a prepared argument.
|
|
1369
|
+
*
|
|
1370
|
+
* @param {Argument} argument
|
|
1371
|
+
* @return {Command} `this` command for chaining
|
|
1372
|
+
*/
|
|
1373
|
+
addArgument(argument) {
|
|
1374
|
+
const previousArgument = this.registeredArguments.slice(-1)[0];
|
|
1375
|
+
if (previousArgument?.variadic) throw new Error(`only the last argument can be variadic '${previousArgument.name()}'`);
|
|
1376
|
+
if (argument.required && argument.defaultValue !== void 0 && argument.parseArg === void 0) throw new Error(`a default value for a required argument is never used: '${argument.name()}'`);
|
|
1377
|
+
this.registeredArguments.push(argument);
|
|
1378
|
+
return this;
|
|
1379
|
+
}
|
|
1380
|
+
/**
|
|
1381
|
+
* Customise or override default help command. By default a help command is automatically added if your command has subcommands.
|
|
1382
|
+
*
|
|
1383
|
+
* @example
|
|
1384
|
+
* program.helpCommand('help [cmd]');
|
|
1385
|
+
* program.helpCommand('help [cmd]', 'show help');
|
|
1386
|
+
* program.helpCommand(false); // suppress default help command
|
|
1387
|
+
* program.helpCommand(true); // add help command even if no subcommands
|
|
1388
|
+
*
|
|
1389
|
+
* @param {string|boolean} enableOrNameAndArgs - enable with custom name and/or arguments, or boolean to override whether added
|
|
1390
|
+
* @param {string} [description] - custom description
|
|
1391
|
+
* @return {Command} `this` command for chaining
|
|
1392
|
+
*/
|
|
1393
|
+
helpCommand(enableOrNameAndArgs, description) {
|
|
1394
|
+
if (typeof enableOrNameAndArgs === "boolean") {
|
|
1395
|
+
this._addImplicitHelpCommand = enableOrNameAndArgs;
|
|
1396
|
+
if (enableOrNameAndArgs && this._defaultCommandGroup) this._initCommandGroup(this._getHelpCommand());
|
|
1397
|
+
return this;
|
|
1398
|
+
}
|
|
1399
|
+
const [, helpName, helpArgs] = (enableOrNameAndArgs ?? "help [command]").match(/([^ ]+) *(.*)/);
|
|
1400
|
+
const helpDescription = description ?? "display help for command";
|
|
1401
|
+
const helpCommand = this.createCommand(helpName);
|
|
1402
|
+
helpCommand.helpOption(false);
|
|
1403
|
+
if (helpArgs) helpCommand.arguments(helpArgs);
|
|
1404
|
+
if (helpDescription) helpCommand.description(helpDescription);
|
|
1405
|
+
this._addImplicitHelpCommand = true;
|
|
1406
|
+
this._helpCommand = helpCommand;
|
|
1407
|
+
if (enableOrNameAndArgs || description) this._initCommandGroup(helpCommand);
|
|
1408
|
+
return this;
|
|
1409
|
+
}
|
|
1410
|
+
/**
|
|
1411
|
+
* Add prepared custom help command.
|
|
1412
|
+
*
|
|
1413
|
+
* @param {(Command|string|boolean)} helpCommand - custom help command, or deprecated enableOrNameAndArgs as for `.helpCommand()`
|
|
1414
|
+
* @param {string} [deprecatedDescription] - deprecated custom description used with custom name only
|
|
1415
|
+
* @return {Command} `this` command for chaining
|
|
1416
|
+
*/
|
|
1417
|
+
addHelpCommand(helpCommand, deprecatedDescription) {
|
|
1418
|
+
if (typeof helpCommand !== "object") {
|
|
1419
|
+
this.helpCommand(helpCommand, deprecatedDescription);
|
|
1420
|
+
return this;
|
|
1421
|
+
}
|
|
1422
|
+
this._addImplicitHelpCommand = true;
|
|
1423
|
+
this._helpCommand = helpCommand;
|
|
1424
|
+
this._initCommandGroup(helpCommand);
|
|
1425
|
+
return this;
|
|
1426
|
+
}
|
|
1427
|
+
/**
|
|
1428
|
+
* Lazy create help command.
|
|
1429
|
+
*
|
|
1430
|
+
* @return {(Command|null)}
|
|
1431
|
+
* @package
|
|
1432
|
+
*/
|
|
1433
|
+
_getHelpCommand() {
|
|
1434
|
+
if (this._addImplicitHelpCommand ?? (this.commands.length && !this._actionHandler && !this._findCommand("help"))) {
|
|
1435
|
+
if (this._helpCommand === void 0) this.helpCommand(void 0, void 0);
|
|
1436
|
+
return this._helpCommand;
|
|
1437
|
+
}
|
|
1438
|
+
return null;
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Add hook for life cycle event.
|
|
1442
|
+
*
|
|
1443
|
+
* @param {string} event
|
|
1444
|
+
* @param {Function} listener
|
|
1445
|
+
* @return {Command} `this` command for chaining
|
|
1446
|
+
*/
|
|
1447
|
+
hook(event, listener) {
|
|
1448
|
+
const allowedValues = [
|
|
1449
|
+
"preSubcommand",
|
|
1450
|
+
"preAction",
|
|
1451
|
+
"postAction"
|
|
1452
|
+
];
|
|
1453
|
+
if (!allowedValues.includes(event)) throw new Error(`Unexpected value for event passed to hook : '${event}'.
|
|
1454
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
1455
|
+
if (this._lifeCycleHooks[event]) this._lifeCycleHooks[event].push(listener);
|
|
1456
|
+
else this._lifeCycleHooks[event] = [listener];
|
|
1457
|
+
return this;
|
|
1458
|
+
}
|
|
1459
|
+
/**
|
|
1460
|
+
* Register callback to use as replacement for calling process.exit.
|
|
1461
|
+
*
|
|
1462
|
+
* @param {Function} [fn] optional callback which will be passed a CommanderError, defaults to throwing
|
|
1463
|
+
* @return {Command} `this` command for chaining
|
|
1464
|
+
*/
|
|
1465
|
+
exitOverride(fn) {
|
|
1466
|
+
if (fn) this._exitCallback = fn;
|
|
1467
|
+
else this._exitCallback = (err) => {
|
|
1468
|
+
if (err.code !== "commander.executeSubCommandAsync") throw err;
|
|
1469
|
+
};
|
|
1470
|
+
return this;
|
|
1471
|
+
}
|
|
1472
|
+
/**
|
|
1473
|
+
* Call process.exit, and _exitCallback if defined.
|
|
1474
|
+
*
|
|
1475
|
+
* @param {number} exitCode exit code for using with process.exit
|
|
1476
|
+
* @param {string} code an id string representing the error
|
|
1477
|
+
* @param {string} message human-readable description of the error
|
|
1478
|
+
* @return never
|
|
1479
|
+
* @private
|
|
1480
|
+
*/
|
|
1481
|
+
_exit(exitCode, code, message) {
|
|
1482
|
+
if (this._exitCallback) this._exitCallback(new CommanderError(exitCode, code, message));
|
|
1483
|
+
process$1.exit(exitCode);
|
|
1484
|
+
}
|
|
1485
|
+
/**
|
|
1486
|
+
* Register callback `fn` for the command.
|
|
1487
|
+
*
|
|
1488
|
+
* @example
|
|
1489
|
+
* program
|
|
1490
|
+
* .command('serve')
|
|
1491
|
+
* .description('start service')
|
|
1492
|
+
* .action(function() {
|
|
1493
|
+
* // do work here
|
|
1494
|
+
* });
|
|
1495
|
+
*
|
|
1496
|
+
* @param {Function} fn
|
|
1497
|
+
* @return {Command} `this` command for chaining
|
|
1498
|
+
*/
|
|
1499
|
+
action(fn) {
|
|
1500
|
+
const listener = (args) => {
|
|
1501
|
+
const expectedArgsCount = this.registeredArguments.length;
|
|
1502
|
+
const actionArgs = args.slice(0, expectedArgsCount);
|
|
1503
|
+
if (this._storeOptionsAsProperties) actionArgs[expectedArgsCount] = this;
|
|
1504
|
+
else actionArgs[expectedArgsCount] = this.opts();
|
|
1505
|
+
actionArgs.push(this);
|
|
1506
|
+
return fn.apply(this, actionArgs);
|
|
1507
|
+
};
|
|
1508
|
+
this._actionHandler = listener;
|
|
1509
|
+
return this;
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Factory routine to create a new unattached option.
|
|
1513
|
+
*
|
|
1514
|
+
* See .option() for creating an attached option, which uses this routine to
|
|
1515
|
+
* create the option. You can override createOption to return a custom option.
|
|
1516
|
+
*
|
|
1517
|
+
* @param {string} flags
|
|
1518
|
+
* @param {string} [description]
|
|
1519
|
+
* @return {Option} new option
|
|
1520
|
+
*/
|
|
1521
|
+
createOption(flags, description) {
|
|
1522
|
+
return new Option(flags, description);
|
|
1523
|
+
}
|
|
1524
|
+
/**
|
|
1525
|
+
* Wrap parseArgs to catch 'commander.invalidArgument'.
|
|
1526
|
+
*
|
|
1527
|
+
* @param {(Option | Argument)} target
|
|
1528
|
+
* @param {string} value
|
|
1529
|
+
* @param {*} previous
|
|
1530
|
+
* @param {string} invalidArgumentMessage
|
|
1531
|
+
* @private
|
|
1532
|
+
*/
|
|
1533
|
+
_callParseArg(target, value, previous, invalidArgumentMessage) {
|
|
1534
|
+
try {
|
|
1535
|
+
return target.parseArg(value, previous);
|
|
1536
|
+
} catch (err) {
|
|
1537
|
+
if (err.code === "commander.invalidArgument") {
|
|
1538
|
+
const message = `${invalidArgumentMessage} ${err.message}`;
|
|
1539
|
+
this.error(message, {
|
|
1540
|
+
exitCode: err.exitCode,
|
|
1541
|
+
code: err.code
|
|
1542
|
+
});
|
|
1543
|
+
}
|
|
1544
|
+
throw err;
|
|
1545
|
+
}
|
|
1546
|
+
}
|
|
1547
|
+
/**
|
|
1548
|
+
* Check for option flag conflicts.
|
|
1549
|
+
* Register option if no conflicts found, or throw on conflict.
|
|
1550
|
+
*
|
|
1551
|
+
* @param {Option} option
|
|
1552
|
+
* @private
|
|
1553
|
+
*/
|
|
1554
|
+
_registerOption(option) {
|
|
1555
|
+
const matchingOption = option.short && this._findOption(option.short) || option.long && this._findOption(option.long);
|
|
1556
|
+
if (matchingOption) {
|
|
1557
|
+
const matchingFlag = option.long && this._findOption(option.long) ? option.long : option.short;
|
|
1558
|
+
throw new Error(`Cannot add option '${option.flags}'${this._name && ` to command '${this._name}'`} due to conflicting flag '${matchingFlag}'
|
|
1559
|
+
- already used by option '${matchingOption.flags}'`);
|
|
1560
|
+
}
|
|
1561
|
+
this._initOptionGroup(option);
|
|
1562
|
+
this.options.push(option);
|
|
1563
|
+
}
|
|
1564
|
+
/**
|
|
1565
|
+
* Check for command name and alias conflicts with existing commands.
|
|
1566
|
+
* Register command if no conflicts found, or throw on conflict.
|
|
1567
|
+
*
|
|
1568
|
+
* @param {Command} command
|
|
1569
|
+
* @private
|
|
1570
|
+
*/
|
|
1571
|
+
_registerCommand(command) {
|
|
1572
|
+
const knownBy = (cmd) => {
|
|
1573
|
+
return [cmd.name()].concat(cmd.aliases());
|
|
1574
|
+
};
|
|
1575
|
+
const alreadyUsed = knownBy(command).find((name) => this._findCommand(name));
|
|
1576
|
+
if (alreadyUsed) {
|
|
1577
|
+
const existingCmd = knownBy(this._findCommand(alreadyUsed)).join("|");
|
|
1578
|
+
const newCmd = knownBy(command).join("|");
|
|
1579
|
+
throw new Error(`cannot add command '${newCmd}' as already have command '${existingCmd}'`);
|
|
1580
|
+
}
|
|
1581
|
+
this._initCommandGroup(command);
|
|
1582
|
+
this.commands.push(command);
|
|
1583
|
+
}
|
|
1584
|
+
/**
|
|
1585
|
+
* Add an option.
|
|
1586
|
+
*
|
|
1587
|
+
* @param {Option} option
|
|
1588
|
+
* @return {Command} `this` command for chaining
|
|
1589
|
+
*/
|
|
1590
|
+
addOption(option) {
|
|
1591
|
+
this._registerOption(option);
|
|
1592
|
+
const oname = option.name();
|
|
1593
|
+
const name = option.attributeName();
|
|
1594
|
+
if (option.negate) {
|
|
1595
|
+
const positiveLongFlag = option.long.replace(/^--no-/, "--");
|
|
1596
|
+
if (!this._findOption(positiveLongFlag)) this.setOptionValueWithSource(name, option.defaultValue === void 0 ? true : option.defaultValue, "default");
|
|
1597
|
+
} else if (option.defaultValue !== void 0) this.setOptionValueWithSource(name, option.defaultValue, "default");
|
|
1598
|
+
const handleOptionValue = (val, invalidValueMessage, valueSource) => {
|
|
1599
|
+
if (val == null && option.presetArg !== void 0) val = option.presetArg;
|
|
1600
|
+
const oldValue = this.getOptionValue(name);
|
|
1601
|
+
if (val !== null && option.parseArg) val = this._callParseArg(option, val, oldValue, invalidValueMessage);
|
|
1602
|
+
else if (val !== null && option.variadic) val = option._collectValue(val, oldValue);
|
|
1603
|
+
if (val == null) if (option.negate) val = false;
|
|
1604
|
+
else if (option.isBoolean() || option.optional) val = true;
|
|
1605
|
+
else val = "";
|
|
1606
|
+
this.setOptionValueWithSource(name, val, valueSource);
|
|
1607
|
+
};
|
|
1608
|
+
this.on("option:" + oname, (val) => {
|
|
1609
|
+
handleOptionValue(val, `error: option '${option.flags}' argument '${val}' is invalid.`, "cli");
|
|
1610
|
+
});
|
|
1611
|
+
if (option.envVar) this.on("optionEnv:" + oname, (val) => {
|
|
1612
|
+
handleOptionValue(val, `error: option '${option.flags}' value '${val}' from env '${option.envVar}' is invalid.`, "env");
|
|
1613
|
+
});
|
|
1614
|
+
return this;
|
|
1615
|
+
}
|
|
1616
|
+
/**
|
|
1617
|
+
* Internal implementation shared by .option() and .requiredOption()
|
|
1618
|
+
*
|
|
1619
|
+
* @return {Command} `this` command for chaining
|
|
1620
|
+
* @private
|
|
1621
|
+
*/
|
|
1622
|
+
_optionEx(config, flags, description, fn, defaultValue) {
|
|
1623
|
+
if (typeof flags === "object" && flags instanceof Option) throw new Error("To add an Option object use addOption() instead of option() or requiredOption()");
|
|
1624
|
+
const option = this.createOption(flags, description);
|
|
1625
|
+
option.makeOptionMandatory(!!config.mandatory);
|
|
1626
|
+
if (typeof fn === "function") option.default(defaultValue).argParser(fn);
|
|
1627
|
+
else if (fn instanceof RegExp) {
|
|
1628
|
+
const regex = fn;
|
|
1629
|
+
fn = (val, def) => {
|
|
1630
|
+
const m = regex.exec(val);
|
|
1631
|
+
return m ? m[0] : def;
|
|
1632
|
+
};
|
|
1633
|
+
option.default(defaultValue).argParser(fn);
|
|
1634
|
+
} else option.default(fn);
|
|
1635
|
+
return this.addOption(option);
|
|
1636
|
+
}
|
|
1637
|
+
/**
|
|
1638
|
+
* Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
|
|
1639
|
+
*
|
|
1640
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space. A required
|
|
1641
|
+
* option-argument is indicated by `<>` and an optional option-argument by `[]`.
|
|
1642
|
+
*
|
|
1643
|
+
* See the README for more details, and see also addOption() and requiredOption().
|
|
1644
|
+
*
|
|
1645
|
+
* @example
|
|
1646
|
+
* program
|
|
1647
|
+
* .option('-p, --pepper', 'add pepper')
|
|
1648
|
+
* .option('--pt, --pizza-type <TYPE>', 'type of pizza') // required option-argument
|
|
1649
|
+
* .option('-c, --cheese [CHEESE]', 'add extra cheese', 'mozzarella') // optional option-argument with default
|
|
1650
|
+
* .option('-t, --tip <VALUE>', 'add tip to purchase cost', parseFloat) // custom parse function
|
|
1651
|
+
*
|
|
1652
|
+
* @param {string} flags
|
|
1653
|
+
* @param {string} [description]
|
|
1654
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
1655
|
+
* @param {*} [defaultValue]
|
|
1656
|
+
* @return {Command} `this` command for chaining
|
|
1657
|
+
*/
|
|
1658
|
+
option(flags, description, parseArg, defaultValue) {
|
|
1659
|
+
return this._optionEx({}, flags, description, parseArg, defaultValue);
|
|
1660
|
+
}
|
|
1661
|
+
/**
|
|
1662
|
+
* Add a required option which must have a value after parsing. This usually means
|
|
1663
|
+
* the option must be specified on the command line. (Otherwise the same as .option().)
|
|
1664
|
+
*
|
|
1665
|
+
* The `flags` string contains the short and/or long flags, separated by comma, a pipe or space.
|
|
1666
|
+
*
|
|
1667
|
+
* @param {string} flags
|
|
1668
|
+
* @param {string} [description]
|
|
1669
|
+
* @param {(Function|*)} [parseArg] - custom option processing function or default value
|
|
1670
|
+
* @param {*} [defaultValue]
|
|
1671
|
+
* @return {Command} `this` command for chaining
|
|
1672
|
+
*/
|
|
1673
|
+
requiredOption(flags, description, parseArg, defaultValue) {
|
|
1674
|
+
return this._optionEx({ mandatory: true }, flags, description, parseArg, defaultValue);
|
|
1675
|
+
}
|
|
1676
|
+
/**
|
|
1677
|
+
* Alter parsing of short flags with optional values.
|
|
1678
|
+
*
|
|
1679
|
+
* @example
|
|
1680
|
+
* // for `.option('-f,--flag [value]'):
|
|
1681
|
+
* program.combineFlagAndOptionalValue(true); // `-f80` is treated like `--flag=80`, this is the default behaviour
|
|
1682
|
+
* program.combineFlagAndOptionalValue(false) // `-fb` is treated like `-f -b`
|
|
1683
|
+
*
|
|
1684
|
+
* @param {boolean} [combine] - if `true` or omitted, an optional value can be specified directly after the flag.
|
|
1685
|
+
* @return {Command} `this` command for chaining
|
|
1686
|
+
*/
|
|
1687
|
+
combineFlagAndOptionalValue(combine = true) {
|
|
1688
|
+
this._combineFlagAndOptionalValue = !!combine;
|
|
1689
|
+
return this;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Allow unknown options on the command line.
|
|
1693
|
+
*
|
|
1694
|
+
* @param {boolean} [allowUnknown] - if `true` or omitted, no error will be thrown for unknown options.
|
|
1695
|
+
* @return {Command} `this` command for chaining
|
|
1696
|
+
*/
|
|
1697
|
+
allowUnknownOption(allowUnknown = true) {
|
|
1698
|
+
this._allowUnknownOption = !!allowUnknown;
|
|
1699
|
+
return this;
|
|
1700
|
+
}
|
|
1701
|
+
/**
|
|
1702
|
+
* Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
|
|
1703
|
+
*
|
|
1704
|
+
* @param {boolean} [allowExcess] - if `true` or omitted, no error will be thrown for excess arguments.
|
|
1705
|
+
* @return {Command} `this` command for chaining
|
|
1706
|
+
*/
|
|
1707
|
+
allowExcessArguments(allowExcess = true) {
|
|
1708
|
+
this._allowExcessArguments = !!allowExcess;
|
|
1709
|
+
return this;
|
|
1710
|
+
}
|
|
1711
|
+
/**
|
|
1712
|
+
* Enable positional options. Positional means global options are specified before subcommands which lets
|
|
1713
|
+
* subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
|
|
1714
|
+
* The default behaviour is non-positional and global options may appear anywhere on the command line.
|
|
1715
|
+
*
|
|
1716
|
+
* @param {boolean} [positional]
|
|
1717
|
+
* @return {Command} `this` command for chaining
|
|
1718
|
+
*/
|
|
1719
|
+
enablePositionalOptions(positional = true) {
|
|
1720
|
+
this._enablePositionalOptions = !!positional;
|
|
1721
|
+
return this;
|
|
1722
|
+
}
|
|
1723
|
+
/**
|
|
1724
|
+
* Pass through options that come after command-arguments rather than treat them as command-options,
|
|
1725
|
+
* so actual command-options come before command-arguments. Turning this on for a subcommand requires
|
|
1726
|
+
* positional options to have been enabled on the program (parent commands).
|
|
1727
|
+
* The default behaviour is non-positional and options may appear before or after command-arguments.
|
|
1728
|
+
*
|
|
1729
|
+
* @param {boolean} [passThrough] for unknown options.
|
|
1730
|
+
* @return {Command} `this` command for chaining
|
|
1731
|
+
*/
|
|
1732
|
+
passThroughOptions(passThrough = true) {
|
|
1733
|
+
this._passThroughOptions = !!passThrough;
|
|
1734
|
+
this._checkForBrokenPassThrough();
|
|
1735
|
+
return this;
|
|
1736
|
+
}
|
|
1737
|
+
/**
|
|
1738
|
+
* @private
|
|
1739
|
+
*/
|
|
1740
|
+
_checkForBrokenPassThrough() {
|
|
1741
|
+
if (this.parent && this._passThroughOptions && !this.parent._enablePositionalOptions) throw new Error(`passThroughOptions cannot be used for '${this._name}' without turning on enablePositionalOptions for parent command(s)`);
|
|
1742
|
+
}
|
|
1743
|
+
/**
|
|
1744
|
+
* Whether to store option values as properties on command object,
|
|
1745
|
+
* or store separately (specify false). In both cases the option values can be accessed using .opts().
|
|
1746
|
+
*
|
|
1747
|
+
* @param {boolean} [storeAsProperties=true]
|
|
1748
|
+
* @return {Command} `this` command for chaining
|
|
1749
|
+
*/
|
|
1750
|
+
storeOptionsAsProperties(storeAsProperties = true) {
|
|
1751
|
+
if (this.options.length) throw new Error("call .storeOptionsAsProperties() before adding options");
|
|
1752
|
+
if (Object.keys(this._optionValues).length) throw new Error("call .storeOptionsAsProperties() before setting option values");
|
|
1753
|
+
this._storeOptionsAsProperties = !!storeAsProperties;
|
|
1754
|
+
return this;
|
|
1755
|
+
}
|
|
1756
|
+
/**
|
|
1757
|
+
* Retrieve option value.
|
|
1758
|
+
*
|
|
1759
|
+
* @param {string} key
|
|
1760
|
+
* @return {object} value
|
|
1761
|
+
*/
|
|
1762
|
+
getOptionValue(key) {
|
|
1763
|
+
if (this._storeOptionsAsProperties) return this[key];
|
|
1764
|
+
return this._optionValues[key];
|
|
1765
|
+
}
|
|
1766
|
+
/**
|
|
1767
|
+
* Store option value.
|
|
1768
|
+
*
|
|
1769
|
+
* @param {string} key
|
|
1770
|
+
* @param {object} value
|
|
1771
|
+
* @return {Command} `this` command for chaining
|
|
1772
|
+
*/
|
|
1773
|
+
setOptionValue(key, value) {
|
|
1774
|
+
return this.setOptionValueWithSource(key, value, void 0);
|
|
1775
|
+
}
|
|
1776
|
+
/**
|
|
1777
|
+
* Store option value and where the value came from.
|
|
1778
|
+
*
|
|
1779
|
+
* @param {string} key
|
|
1780
|
+
* @param {object} value
|
|
1781
|
+
* @param {string} source - expected values are default/config/env/cli/implied
|
|
1782
|
+
* @return {Command} `this` command for chaining
|
|
1783
|
+
*/
|
|
1784
|
+
setOptionValueWithSource(key, value, source) {
|
|
1785
|
+
if (this._storeOptionsAsProperties) this[key] = value;
|
|
1786
|
+
else this._optionValues[key] = value;
|
|
1787
|
+
this._optionValueSources[key] = source;
|
|
1788
|
+
return this;
|
|
1789
|
+
}
|
|
1790
|
+
/**
|
|
1791
|
+
* Get source of option value.
|
|
1792
|
+
* Expected values are default | config | env | cli | implied
|
|
1793
|
+
*
|
|
1794
|
+
* @param {string} key
|
|
1795
|
+
* @return {string}
|
|
1796
|
+
*/
|
|
1797
|
+
getOptionValueSource(key) {
|
|
1798
|
+
return this._optionValueSources[key];
|
|
1799
|
+
}
|
|
1800
|
+
/**
|
|
1801
|
+
* Get source of option value. See also .optsWithGlobals().
|
|
1802
|
+
* Expected values are default | config | env | cli | implied
|
|
1803
|
+
*
|
|
1804
|
+
* @param {string} key
|
|
1805
|
+
* @return {string}
|
|
1806
|
+
*/
|
|
1807
|
+
getOptionValueSourceWithGlobals(key) {
|
|
1808
|
+
let source;
|
|
1809
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
1810
|
+
if (cmd.getOptionValueSource(key) !== void 0) source = cmd.getOptionValueSource(key);
|
|
1811
|
+
});
|
|
1812
|
+
return source;
|
|
1813
|
+
}
|
|
1814
|
+
/**
|
|
1815
|
+
* Get user arguments from implied or explicit arguments.
|
|
1816
|
+
* Side-effects: set _scriptPath if args included script. Used for default program name, and subcommand searches.
|
|
1817
|
+
*
|
|
1818
|
+
* @private
|
|
1819
|
+
*/
|
|
1820
|
+
_prepareUserArgs(argv, parseOptions) {
|
|
1821
|
+
if (argv !== void 0 && !Array.isArray(argv)) throw new Error("first parameter to parse must be array or undefined");
|
|
1822
|
+
parseOptions = parseOptions || {};
|
|
1823
|
+
if (argv === void 0 && parseOptions.from === void 0) {
|
|
1824
|
+
if (process$1.versions?.electron) parseOptions.from = "electron";
|
|
1825
|
+
const execArgv = process$1.execArgv ?? [];
|
|
1826
|
+
if (execArgv.includes("-e") || execArgv.includes("--eval") || execArgv.includes("-p") || execArgv.includes("--print")) parseOptions.from = "eval";
|
|
1827
|
+
}
|
|
1828
|
+
if (argv === void 0) argv = process$1.argv;
|
|
1829
|
+
this.rawArgs = argv.slice();
|
|
1830
|
+
let userArgs;
|
|
1831
|
+
switch (parseOptions.from) {
|
|
1832
|
+
case void 0:
|
|
1833
|
+
case "node":
|
|
1834
|
+
this._scriptPath = argv[1];
|
|
1835
|
+
userArgs = argv.slice(2);
|
|
1836
|
+
break;
|
|
1837
|
+
case "electron":
|
|
1838
|
+
if (process$1.defaultApp) {
|
|
1839
|
+
this._scriptPath = argv[1];
|
|
1840
|
+
userArgs = argv.slice(2);
|
|
1841
|
+
} else userArgs = argv.slice(1);
|
|
1842
|
+
break;
|
|
1843
|
+
case "user":
|
|
1844
|
+
userArgs = argv.slice(0);
|
|
1845
|
+
break;
|
|
1846
|
+
case "eval":
|
|
1847
|
+
userArgs = argv.slice(1);
|
|
1848
|
+
break;
|
|
1849
|
+
default: throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
|
|
1850
|
+
}
|
|
1851
|
+
if (!this._name && this._scriptPath) this.nameFromFilename(this._scriptPath);
|
|
1852
|
+
this._name = this._name || "program";
|
|
1853
|
+
return userArgs;
|
|
1854
|
+
}
|
|
1855
|
+
/**
|
|
1856
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
1857
|
+
*
|
|
1858
|
+
* Use parseAsync instead of parse if any of your action handlers are async.
|
|
1859
|
+
*
|
|
1860
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
1861
|
+
*
|
|
1862
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
1863
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
1864
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
1865
|
+
* - `'user'`: just user arguments
|
|
1866
|
+
*
|
|
1867
|
+
* @example
|
|
1868
|
+
* program.parse(); // parse process.argv and auto-detect electron and special node flags
|
|
1869
|
+
* program.parse(process.argv); // assume argv[0] is app and argv[1] is script
|
|
1870
|
+
* program.parse(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
1871
|
+
*
|
|
1872
|
+
* @param {string[]} [argv] - optional, defaults to process.argv
|
|
1873
|
+
* @param {object} [parseOptions] - optionally specify style of options with from: node/user/electron
|
|
1874
|
+
* @param {string} [parseOptions.from] - where the args are from: 'node', 'user', 'electron'
|
|
1875
|
+
* @return {Command} `this` command for chaining
|
|
1876
|
+
*/
|
|
1877
|
+
parse(argv, parseOptions) {
|
|
1878
|
+
this._prepareForParse();
|
|
1879
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1880
|
+
this._parseCommand([], userArgs);
|
|
1881
|
+
return this;
|
|
1882
|
+
}
|
|
1883
|
+
/**
|
|
1884
|
+
* Parse `argv`, setting options and invoking commands when defined.
|
|
1885
|
+
*
|
|
1886
|
+
* Call with no parameters to parse `process.argv`. Detects Electron and special node options like `node --eval`. Easy mode!
|
|
1887
|
+
*
|
|
1888
|
+
* Or call with an array of strings to parse, and optionally where the user arguments start by specifying where the arguments are `from`:
|
|
1889
|
+
* - `'node'`: default, `argv[0]` is the application and `argv[1]` is the script being run, with user arguments after that
|
|
1890
|
+
* - `'electron'`: `argv[0]` is the application and `argv[1]` varies depending on whether the electron application is packaged
|
|
1891
|
+
* - `'user'`: just user arguments
|
|
1892
|
+
*
|
|
1893
|
+
* @example
|
|
1894
|
+
* await program.parseAsync(); // parse process.argv and auto-detect electron and special node flags
|
|
1895
|
+
* await program.parseAsync(process.argv); // assume argv[0] is app and argv[1] is script
|
|
1896
|
+
* await program.parseAsync(my-args, { from: 'user' }); // just user supplied arguments, nothing special about argv[0]
|
|
1897
|
+
*
|
|
1898
|
+
* @param {string[]} [argv]
|
|
1899
|
+
* @param {object} [parseOptions]
|
|
1900
|
+
* @param {string} parseOptions.from - where the args are from: 'node', 'user', 'electron'
|
|
1901
|
+
* @return {Promise}
|
|
1902
|
+
*/
|
|
1903
|
+
async parseAsync(argv, parseOptions) {
|
|
1904
|
+
this._prepareForParse();
|
|
1905
|
+
const userArgs = this._prepareUserArgs(argv, parseOptions);
|
|
1906
|
+
await this._parseCommand([], userArgs);
|
|
1907
|
+
return this;
|
|
1908
|
+
}
|
|
1909
|
+
_prepareForParse() {
|
|
1910
|
+
if (this._savedState === null) this.saveStateBeforeParse();
|
|
1911
|
+
else this.restoreStateBeforeParse();
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
|
|
1915
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
1916
|
+
*
|
|
1917
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state saved.
|
|
1918
|
+
*/
|
|
1919
|
+
saveStateBeforeParse() {
|
|
1920
|
+
this._savedState = {
|
|
1921
|
+
_name: this._name,
|
|
1922
|
+
_optionValues: { ...this._optionValues },
|
|
1923
|
+
_optionValueSources: { ...this._optionValueSources }
|
|
1924
|
+
};
|
|
1925
|
+
}
|
|
1926
|
+
/**
|
|
1927
|
+
* Restore state before parse for calls after the first.
|
|
1928
|
+
* Not usually called directly, but available for subclasses to save their custom state.
|
|
1929
|
+
*
|
|
1930
|
+
* This is called in a lazy way. Only commands used in parsing chain will have state restored.
|
|
1931
|
+
*/
|
|
1932
|
+
restoreStateBeforeParse() {
|
|
1933
|
+
if (this._storeOptionsAsProperties) throw new Error(`Can not call parse again when storeOptionsAsProperties is true.
|
|
1934
|
+
- either make a new Command for each call to parse, or stop storing options as properties`);
|
|
1935
|
+
this._name = this._savedState._name;
|
|
1936
|
+
this._scriptPath = null;
|
|
1937
|
+
this.rawArgs = [];
|
|
1938
|
+
this._optionValues = { ...this._savedState._optionValues };
|
|
1939
|
+
this._optionValueSources = { ...this._savedState._optionValueSources };
|
|
1940
|
+
this.args = [];
|
|
1941
|
+
this.processedArgs = [];
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* Throw if expected executable is missing. Add lots of help for author.
|
|
1945
|
+
*
|
|
1946
|
+
* @param {string} executableFile
|
|
1947
|
+
* @param {string} executableDir
|
|
1948
|
+
* @param {string} subcommandName
|
|
1949
|
+
*/
|
|
1950
|
+
_checkForMissingExecutable(executableFile, executableDir, subcommandName) {
|
|
1951
|
+
if (fs.existsSync(executableFile)) return;
|
|
1952
|
+
const executableMissing = `'${executableFile}' does not exist
|
|
1953
|
+
- if '${subcommandName}' is not meant to be an executable command, remove description parameter from '.command()' and use '.description()' instead
|
|
1954
|
+
- if the default executable name is not suitable, use the executableFile option to supply a custom name or path
|
|
1955
|
+
- ${executableDir ? `searched for local subcommand relative to directory '${executableDir}'` : "no directory for search for local subcommand, use .executableDir() to supply a custom directory"}`;
|
|
1956
|
+
throw new Error(executableMissing);
|
|
1957
|
+
}
|
|
1958
|
+
/**
|
|
1959
|
+
* Execute a sub-command executable.
|
|
1960
|
+
*
|
|
1961
|
+
* @private
|
|
1962
|
+
*/
|
|
1963
|
+
_executeSubCommand(subcommand, args) {
|
|
1964
|
+
args = args.slice();
|
|
1965
|
+
let launchWithNode = false;
|
|
1966
|
+
const sourceExt = [
|
|
1967
|
+
".js",
|
|
1968
|
+
".ts",
|
|
1969
|
+
".tsx",
|
|
1970
|
+
".mjs",
|
|
1971
|
+
".cjs"
|
|
1972
|
+
];
|
|
1973
|
+
function findFile(baseDir, baseName) {
|
|
1974
|
+
const localBin = path.resolve(baseDir, baseName);
|
|
1975
|
+
if (fs.existsSync(localBin)) return localBin;
|
|
1976
|
+
if (sourceExt.includes(path.extname(baseName))) return void 0;
|
|
1977
|
+
const foundExt = sourceExt.find((ext) => fs.existsSync(`${localBin}${ext}`));
|
|
1978
|
+
if (foundExt) return `${localBin}${foundExt}`;
|
|
1979
|
+
}
|
|
1980
|
+
this._checkForMissingMandatoryOptions();
|
|
1981
|
+
this._checkForConflictingOptions();
|
|
1982
|
+
let executableFile = subcommand._executableFile || `${this._name}-${subcommand._name}`;
|
|
1983
|
+
let executableDir = this._executableDir || "";
|
|
1984
|
+
if (this._scriptPath) {
|
|
1985
|
+
let resolvedScriptPath;
|
|
1986
|
+
try {
|
|
1987
|
+
resolvedScriptPath = fs.realpathSync(this._scriptPath);
|
|
1988
|
+
} catch {
|
|
1989
|
+
resolvedScriptPath = this._scriptPath;
|
|
1990
|
+
}
|
|
1991
|
+
executableDir = path.resolve(path.dirname(resolvedScriptPath), executableDir);
|
|
1992
|
+
}
|
|
1993
|
+
if (executableDir) {
|
|
1994
|
+
let localFile = findFile(executableDir, executableFile);
|
|
1995
|
+
if (!localFile && !subcommand._executableFile && this._scriptPath) {
|
|
1996
|
+
const legacyName = path.basename(this._scriptPath, path.extname(this._scriptPath));
|
|
1997
|
+
if (legacyName !== this._name) localFile = findFile(executableDir, `${legacyName}-${subcommand._name}`);
|
|
1998
|
+
}
|
|
1999
|
+
executableFile = localFile || executableFile;
|
|
2000
|
+
}
|
|
2001
|
+
launchWithNode = sourceExt.includes(path.extname(executableFile));
|
|
2002
|
+
let proc;
|
|
2003
|
+
if (process$1.platform !== "win32") if (launchWithNode) {
|
|
2004
|
+
args.unshift(executableFile);
|
|
2005
|
+
args = incrementNodeInspectorPort(process$1.execArgv).concat(args);
|
|
2006
|
+
proc = childProcess.spawn(process$1.argv[0], args, { stdio: "inherit" });
|
|
2007
|
+
} else proc = childProcess.spawn(executableFile, args, { stdio: "inherit" });
|
|
2008
|
+
else {
|
|
2009
|
+
this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
2010
|
+
args.unshift(executableFile);
|
|
2011
|
+
args = incrementNodeInspectorPort(process$1.execArgv).concat(args);
|
|
2012
|
+
proc = childProcess.spawn(process$1.execPath, args, { stdio: "inherit" });
|
|
2013
|
+
}
|
|
2014
|
+
if (!proc.killed) [
|
|
2015
|
+
"SIGUSR1",
|
|
2016
|
+
"SIGUSR2",
|
|
2017
|
+
"SIGTERM",
|
|
2018
|
+
"SIGINT",
|
|
2019
|
+
"SIGHUP"
|
|
2020
|
+
].forEach((signal) => {
|
|
2021
|
+
process$1.on(signal, () => {
|
|
2022
|
+
if (proc.killed === false && proc.exitCode === null) proc.kill(signal);
|
|
2023
|
+
});
|
|
2024
|
+
});
|
|
2025
|
+
const exitCallback = this._exitCallback;
|
|
2026
|
+
proc.on("close", (code) => {
|
|
2027
|
+
code = code ?? 1;
|
|
2028
|
+
if (!exitCallback) process$1.exit(code);
|
|
2029
|
+
else exitCallback(new CommanderError(code, "commander.executeSubCommandAsync", "(close)"));
|
|
2030
|
+
});
|
|
2031
|
+
proc.on("error", (err) => {
|
|
2032
|
+
if (err.code === "ENOENT") this._checkForMissingExecutable(executableFile, executableDir, subcommand._name);
|
|
2033
|
+
else if (err.code === "EACCES") throw new Error(`'${executableFile}' not executable`);
|
|
2034
|
+
if (!exitCallback) process$1.exit(1);
|
|
2035
|
+
else {
|
|
2036
|
+
const wrappedError = new CommanderError(1, "commander.executeSubCommandAsync", "(error)");
|
|
2037
|
+
wrappedError.nestedError = err;
|
|
2038
|
+
exitCallback(wrappedError);
|
|
2039
|
+
}
|
|
2040
|
+
});
|
|
2041
|
+
this.runningCommand = proc;
|
|
2042
|
+
}
|
|
2043
|
+
/**
|
|
2044
|
+
* @private
|
|
2045
|
+
*/
|
|
2046
|
+
_dispatchSubcommand(commandName, operands, unknown) {
|
|
2047
|
+
const subCommand = this._findCommand(commandName);
|
|
2048
|
+
if (!subCommand) this.help({ error: true });
|
|
2049
|
+
subCommand._prepareForParse();
|
|
2050
|
+
let promiseChain;
|
|
2051
|
+
promiseChain = this._chainOrCallSubCommandHook(promiseChain, subCommand, "preSubcommand");
|
|
2052
|
+
promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2053
|
+
if (subCommand._executableHandler) this._executeSubCommand(subCommand, operands.concat(unknown));
|
|
2054
|
+
else return subCommand._parseCommand(operands, unknown);
|
|
2055
|
+
});
|
|
2056
|
+
return promiseChain;
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Invoke help directly if possible, or dispatch if necessary.
|
|
2060
|
+
* e.g. help foo
|
|
2061
|
+
*
|
|
2062
|
+
* @private
|
|
2063
|
+
*/
|
|
2064
|
+
_dispatchHelpCommand(subcommandName) {
|
|
2065
|
+
if (!subcommandName) this.help();
|
|
2066
|
+
const subCommand = this._findCommand(subcommandName);
|
|
2067
|
+
if (subCommand && !subCommand._executableHandler) subCommand.help();
|
|
2068
|
+
return this._dispatchSubcommand(subcommandName, [], [this._getHelpOption()?.long ?? this._getHelpOption()?.short ?? "--help"]);
|
|
2069
|
+
}
|
|
2070
|
+
/**
|
|
2071
|
+
* Check this.args against expected this.registeredArguments.
|
|
2072
|
+
*
|
|
2073
|
+
* @private
|
|
2074
|
+
*/
|
|
2075
|
+
_checkNumberOfArguments() {
|
|
2076
|
+
this.registeredArguments.forEach((arg, i) => {
|
|
2077
|
+
if (arg.required && this.args[i] == null) this.missingArgument(arg.name());
|
|
2078
|
+
});
|
|
2079
|
+
if (this.registeredArguments.length > 0 && this.registeredArguments[this.registeredArguments.length - 1].variadic) return;
|
|
2080
|
+
if (this.args.length > this.registeredArguments.length) this._excessArguments(this.args);
|
|
2081
|
+
}
|
|
2082
|
+
/**
|
|
2083
|
+
* Process this.args using this.registeredArguments and save as this.processedArgs!
|
|
2084
|
+
*
|
|
2085
|
+
* @private
|
|
2086
|
+
*/
|
|
2087
|
+
_processArguments() {
|
|
2088
|
+
const myParseArg = (argument, value, previous) => {
|
|
2089
|
+
let parsedValue = value;
|
|
2090
|
+
if (value !== null && argument.parseArg) {
|
|
2091
|
+
const invalidValueMessage = `error: command-argument value '${value}' is invalid for argument '${argument.name()}'.`;
|
|
2092
|
+
parsedValue = this._callParseArg(argument, value, previous, invalidValueMessage);
|
|
2093
|
+
}
|
|
2094
|
+
return parsedValue;
|
|
2095
|
+
};
|
|
2096
|
+
this._checkNumberOfArguments();
|
|
2097
|
+
const processedArgs = [];
|
|
2098
|
+
this.registeredArguments.forEach((declaredArg, index) => {
|
|
2099
|
+
let value = declaredArg.defaultValue;
|
|
2100
|
+
if (declaredArg.variadic) {
|
|
2101
|
+
if (index < this.args.length) {
|
|
2102
|
+
value = this.args.slice(index);
|
|
2103
|
+
if (declaredArg.parseArg) value = value.reduce((processed, v) => {
|
|
2104
|
+
return myParseArg(declaredArg, v, processed);
|
|
2105
|
+
}, declaredArg.defaultValue);
|
|
2106
|
+
} else if (value === void 0) value = [];
|
|
2107
|
+
} else if (index < this.args.length) {
|
|
2108
|
+
value = this.args[index];
|
|
2109
|
+
if (declaredArg.parseArg) value = myParseArg(declaredArg, value, declaredArg.defaultValue);
|
|
2110
|
+
}
|
|
2111
|
+
processedArgs[index] = value;
|
|
2112
|
+
});
|
|
2113
|
+
this.processedArgs = processedArgs;
|
|
2114
|
+
}
|
|
2115
|
+
/**
|
|
2116
|
+
* Once we have a promise we chain, but call synchronously until then.
|
|
2117
|
+
*
|
|
2118
|
+
* @param {(Promise|undefined)} promise
|
|
2119
|
+
* @param {Function} fn
|
|
2120
|
+
* @return {(Promise|undefined)}
|
|
2121
|
+
* @private
|
|
2122
|
+
*/
|
|
2123
|
+
_chainOrCall(promise, fn) {
|
|
2124
|
+
if (promise?.then && typeof promise.then === "function") return promise.then(() => fn());
|
|
2125
|
+
return fn();
|
|
2126
|
+
}
|
|
2127
|
+
/**
|
|
2128
|
+
*
|
|
2129
|
+
* @param {(Promise|undefined)} promise
|
|
2130
|
+
* @param {string} event
|
|
2131
|
+
* @return {(Promise|undefined)}
|
|
2132
|
+
* @private
|
|
2133
|
+
*/
|
|
2134
|
+
_chainOrCallHooks(promise, event) {
|
|
2135
|
+
let result = promise;
|
|
2136
|
+
const hooks = [];
|
|
2137
|
+
this._getCommandAndAncestors().reverse().filter((cmd) => cmd._lifeCycleHooks[event] !== void 0).forEach((hookedCommand) => {
|
|
2138
|
+
hookedCommand._lifeCycleHooks[event].forEach((callback) => {
|
|
2139
|
+
hooks.push({
|
|
2140
|
+
hookedCommand,
|
|
2141
|
+
callback
|
|
2142
|
+
});
|
|
2143
|
+
});
|
|
2144
|
+
});
|
|
2145
|
+
if (event === "postAction") hooks.reverse();
|
|
2146
|
+
hooks.forEach((hookDetail) => {
|
|
2147
|
+
result = this._chainOrCall(result, () => {
|
|
2148
|
+
return hookDetail.callback(hookDetail.hookedCommand, this);
|
|
2149
|
+
});
|
|
2150
|
+
});
|
|
2151
|
+
return result;
|
|
2152
|
+
}
|
|
2153
|
+
/**
|
|
2154
|
+
*
|
|
2155
|
+
* @param {(Promise|undefined)} promise
|
|
2156
|
+
* @param {Command} subCommand
|
|
2157
|
+
* @param {string} event
|
|
2158
|
+
* @return {(Promise|undefined)}
|
|
2159
|
+
* @private
|
|
2160
|
+
*/
|
|
2161
|
+
_chainOrCallSubCommandHook(promise, subCommand, event) {
|
|
2162
|
+
let result = promise;
|
|
2163
|
+
if (this._lifeCycleHooks[event] !== void 0) this._lifeCycleHooks[event].forEach((hook) => {
|
|
2164
|
+
result = this._chainOrCall(result, () => {
|
|
2165
|
+
return hook(this, subCommand);
|
|
2166
|
+
});
|
|
2167
|
+
});
|
|
2168
|
+
return result;
|
|
2169
|
+
}
|
|
2170
|
+
/**
|
|
2171
|
+
* Process arguments in context of this command.
|
|
2172
|
+
* Returns action result, in case it is a promise.
|
|
2173
|
+
*
|
|
2174
|
+
* @private
|
|
2175
|
+
*/
|
|
2176
|
+
_parseCommand(operands, unknown) {
|
|
2177
|
+
const parsed = this.parseOptions(unknown);
|
|
2178
|
+
this._parseOptionsEnv();
|
|
2179
|
+
this._parseOptionsImplied();
|
|
2180
|
+
operands = operands.concat(parsed.operands);
|
|
2181
|
+
unknown = parsed.unknown;
|
|
2182
|
+
this.args = operands.concat(unknown);
|
|
2183
|
+
if (operands && this._findCommand(operands[0])) return this._dispatchSubcommand(operands[0], operands.slice(1), unknown);
|
|
2184
|
+
if (this._getHelpCommand() && operands[0] === this._getHelpCommand().name()) return this._dispatchHelpCommand(operands[1]);
|
|
2185
|
+
if (this._defaultCommandName) {
|
|
2186
|
+
this._outputHelpIfRequested(unknown);
|
|
2187
|
+
return this._dispatchSubcommand(this._defaultCommandName, operands, unknown);
|
|
2188
|
+
}
|
|
2189
|
+
if (this.commands.length && this.args.length === 0 && !this._actionHandler && !this._defaultCommandName) this.help({ error: true });
|
|
2190
|
+
this._outputHelpIfRequested(parsed.unknown);
|
|
2191
|
+
this._checkForMissingMandatoryOptions();
|
|
2192
|
+
this._checkForConflictingOptions();
|
|
2193
|
+
const checkForUnknownOptions = () => {
|
|
2194
|
+
if (parsed.unknown.length > 0) this.unknownOption(parsed.unknown[0]);
|
|
2195
|
+
};
|
|
2196
|
+
const commandEvent = `command:${this.name()}`;
|
|
2197
|
+
if (this._actionHandler) {
|
|
2198
|
+
checkForUnknownOptions();
|
|
2199
|
+
this._processArguments();
|
|
2200
|
+
let promiseChain;
|
|
2201
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "preAction");
|
|
2202
|
+
promiseChain = this._chainOrCall(promiseChain, () => this._actionHandler(this.processedArgs));
|
|
2203
|
+
if (this.parent) promiseChain = this._chainOrCall(promiseChain, () => {
|
|
2204
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2205
|
+
});
|
|
2206
|
+
promiseChain = this._chainOrCallHooks(promiseChain, "postAction");
|
|
2207
|
+
return promiseChain;
|
|
2208
|
+
}
|
|
2209
|
+
if (this.parent?.listenerCount(commandEvent)) {
|
|
2210
|
+
checkForUnknownOptions();
|
|
2211
|
+
this._processArguments();
|
|
2212
|
+
this.parent.emit(commandEvent, operands, unknown);
|
|
2213
|
+
} else if (operands.length) {
|
|
2214
|
+
if (this._findCommand("*")) return this._dispatchSubcommand("*", operands, unknown);
|
|
2215
|
+
if (this.listenerCount("command:*")) this.emit("command:*", operands, unknown);
|
|
2216
|
+
else if (this.commands.length) this.unknownCommand();
|
|
2217
|
+
else {
|
|
2218
|
+
checkForUnknownOptions();
|
|
2219
|
+
this._processArguments();
|
|
2220
|
+
}
|
|
2221
|
+
} else if (this.commands.length) {
|
|
2222
|
+
checkForUnknownOptions();
|
|
2223
|
+
this.help({ error: true });
|
|
2224
|
+
} else {
|
|
2225
|
+
checkForUnknownOptions();
|
|
2226
|
+
this._processArguments();
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
/**
|
|
2230
|
+
* Find matching command.
|
|
2231
|
+
*
|
|
2232
|
+
* @private
|
|
2233
|
+
* @return {Command | undefined}
|
|
2234
|
+
*/
|
|
2235
|
+
_findCommand(name) {
|
|
2236
|
+
if (!name) return void 0;
|
|
2237
|
+
return this.commands.find((cmd) => cmd._name === name || cmd._aliases.includes(name));
|
|
2238
|
+
}
|
|
2239
|
+
/**
|
|
2240
|
+
* Return an option matching `arg` if any.
|
|
2241
|
+
*
|
|
2242
|
+
* @param {string} arg
|
|
2243
|
+
* @return {Option}
|
|
2244
|
+
* @package
|
|
2245
|
+
*/
|
|
2246
|
+
_findOption(arg) {
|
|
2247
|
+
return this.options.find((option) => option.is(arg));
|
|
2248
|
+
}
|
|
2249
|
+
/**
|
|
2250
|
+
* Display an error message if a mandatory option does not have a value.
|
|
2251
|
+
* Called after checking for help flags in leaf subcommand.
|
|
2252
|
+
*
|
|
2253
|
+
* @private
|
|
2254
|
+
*/
|
|
2255
|
+
_checkForMissingMandatoryOptions() {
|
|
2256
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2257
|
+
cmd.options.forEach((anOption) => {
|
|
2258
|
+
if (anOption.mandatory && cmd.getOptionValue(anOption.attributeName()) === void 0) cmd.missingMandatoryOptionValue(anOption);
|
|
2259
|
+
});
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* Display an error message if conflicting options are used together in this.
|
|
2264
|
+
*
|
|
2265
|
+
* @private
|
|
2266
|
+
*/
|
|
2267
|
+
_checkForConflictingLocalOptions() {
|
|
2268
|
+
const definedNonDefaultOptions = this.options.filter((option) => {
|
|
2269
|
+
const optionKey = option.attributeName();
|
|
2270
|
+
if (this.getOptionValue(optionKey) === void 0) return false;
|
|
2271
|
+
return this.getOptionValueSource(optionKey) !== "default";
|
|
2272
|
+
});
|
|
2273
|
+
definedNonDefaultOptions.filter((option) => option.conflictsWith.length > 0).forEach((option) => {
|
|
2274
|
+
const conflictingAndDefined = definedNonDefaultOptions.find((defined) => option.conflictsWith.includes(defined.attributeName()));
|
|
2275
|
+
if (conflictingAndDefined) this._conflictingOption(option, conflictingAndDefined);
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2278
|
+
/**
|
|
2279
|
+
* Display an error message if conflicting options are used together.
|
|
2280
|
+
* Called after checking for help flags in leaf subcommand.
|
|
2281
|
+
*
|
|
2282
|
+
* @private
|
|
2283
|
+
*/
|
|
2284
|
+
_checkForConflictingOptions() {
|
|
2285
|
+
this._getCommandAndAncestors().forEach((cmd) => {
|
|
2286
|
+
cmd._checkForConflictingLocalOptions();
|
|
2287
|
+
});
|
|
2288
|
+
}
|
|
2289
|
+
/**
|
|
2290
|
+
* Parse options from `argv` removing known options,
|
|
2291
|
+
* and return argv split into operands and unknown arguments.
|
|
2292
|
+
*
|
|
2293
|
+
* Side effects: modifies command by storing options. Does not reset state if called again.
|
|
2294
|
+
*
|
|
2295
|
+
* Examples:
|
|
2296
|
+
*
|
|
2297
|
+
* argv => operands, unknown
|
|
2298
|
+
* --known kkk op => [op], []
|
|
2299
|
+
* op --known kkk => [op], []
|
|
2300
|
+
* sub --unknown uuu op => [sub], [--unknown uuu op]
|
|
2301
|
+
* sub -- --unknown uuu op => [sub --unknown uuu op], []
|
|
2302
|
+
*
|
|
2303
|
+
* @param {string[]} args
|
|
2304
|
+
* @return {{operands: string[], unknown: string[]}}
|
|
2305
|
+
*/
|
|
2306
|
+
parseOptions(args) {
|
|
2307
|
+
const operands = [];
|
|
2308
|
+
const unknown = [];
|
|
2309
|
+
let dest = operands;
|
|
2310
|
+
function maybeOption(arg) {
|
|
2311
|
+
return arg.length > 1 && arg[0] === "-";
|
|
2312
|
+
}
|
|
2313
|
+
const negativeNumberArg = (arg) => {
|
|
2314
|
+
if (!/^-(\d+|\d*\.\d+)(e[+-]?\d+)?$/.test(arg)) return false;
|
|
2315
|
+
return !this._getCommandAndAncestors().some((cmd) => cmd.options.map((opt) => opt.short).some((short) => /^-\d$/.test(short)));
|
|
2316
|
+
};
|
|
2317
|
+
let activeVariadicOption = null;
|
|
2318
|
+
let activeGroup = null;
|
|
2319
|
+
let i = 0;
|
|
2320
|
+
while (i < args.length || activeGroup) {
|
|
2321
|
+
const arg = activeGroup ?? args[i++];
|
|
2322
|
+
activeGroup = null;
|
|
2323
|
+
if (arg === "--") {
|
|
2324
|
+
if (dest === unknown) dest.push(arg);
|
|
2325
|
+
dest.push(...args.slice(i));
|
|
2326
|
+
break;
|
|
2327
|
+
}
|
|
2328
|
+
if (activeVariadicOption && (!maybeOption(arg) || negativeNumberArg(arg))) {
|
|
2329
|
+
this.emit(`option:${activeVariadicOption.name()}`, arg);
|
|
2330
|
+
continue;
|
|
2331
|
+
}
|
|
2332
|
+
activeVariadicOption = null;
|
|
2333
|
+
if (maybeOption(arg)) {
|
|
2334
|
+
const option = this._findOption(arg);
|
|
2335
|
+
if (option) {
|
|
2336
|
+
if (option.required) {
|
|
2337
|
+
const value = args[i++];
|
|
2338
|
+
if (value === void 0) this.optionMissingArgument(option);
|
|
2339
|
+
this.emit(`option:${option.name()}`, value);
|
|
2340
|
+
} else if (option.optional) {
|
|
2341
|
+
let value = null;
|
|
2342
|
+
if (i < args.length && (!maybeOption(args[i]) || negativeNumberArg(args[i]))) value = args[i++];
|
|
2343
|
+
this.emit(`option:${option.name()}`, value);
|
|
2344
|
+
} else this.emit(`option:${option.name()}`);
|
|
2345
|
+
activeVariadicOption = option.variadic ? option : null;
|
|
2346
|
+
continue;
|
|
2347
|
+
}
|
|
2348
|
+
}
|
|
2349
|
+
if (arg.length > 2 && arg[0] === "-" && arg[1] !== "-") {
|
|
2350
|
+
const option = this._findOption(`-${arg[1]}`);
|
|
2351
|
+
if (option) {
|
|
2352
|
+
if (option.required || option.optional && this._combineFlagAndOptionalValue) this.emit(`option:${option.name()}`, arg.slice(2));
|
|
2353
|
+
else {
|
|
2354
|
+
this.emit(`option:${option.name()}`);
|
|
2355
|
+
activeGroup = `-${arg.slice(2)}`;
|
|
2356
|
+
}
|
|
2357
|
+
continue;
|
|
2358
|
+
}
|
|
2359
|
+
}
|
|
2360
|
+
if (/^--[^=]+=/.test(arg)) {
|
|
2361
|
+
const index = arg.indexOf("=");
|
|
2362
|
+
const option = this._findOption(arg.slice(0, index));
|
|
2363
|
+
if (option && (option.required || option.optional)) {
|
|
2364
|
+
this.emit(`option:${option.name()}`, arg.slice(index + 1));
|
|
2365
|
+
continue;
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
if (dest === operands && maybeOption(arg) && !(this.commands.length === 0 && negativeNumberArg(arg))) dest = unknown;
|
|
2369
|
+
if ((this._enablePositionalOptions || this._passThroughOptions) && operands.length === 0 && unknown.length === 0) {
|
|
2370
|
+
if (this._findCommand(arg)) {
|
|
2371
|
+
operands.push(arg);
|
|
2372
|
+
unknown.push(...args.slice(i));
|
|
2373
|
+
break;
|
|
2374
|
+
} else if (this._getHelpCommand() && arg === this._getHelpCommand().name()) {
|
|
2375
|
+
operands.push(arg, ...args.slice(i));
|
|
2376
|
+
break;
|
|
2377
|
+
} else if (this._defaultCommandName) {
|
|
2378
|
+
unknown.push(arg, ...args.slice(i));
|
|
2379
|
+
break;
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
if (this._passThroughOptions) {
|
|
2383
|
+
dest.push(arg, ...args.slice(i));
|
|
2384
|
+
break;
|
|
2385
|
+
}
|
|
2386
|
+
dest.push(arg);
|
|
2387
|
+
}
|
|
2388
|
+
return {
|
|
2389
|
+
operands,
|
|
2390
|
+
unknown
|
|
2391
|
+
};
|
|
2392
|
+
}
|
|
2393
|
+
/**
|
|
2394
|
+
* Return an object containing local option values as key-value pairs.
|
|
2395
|
+
*
|
|
2396
|
+
* @return {object}
|
|
2397
|
+
*/
|
|
2398
|
+
opts() {
|
|
2399
|
+
if (this._storeOptionsAsProperties) {
|
|
2400
|
+
const result = {};
|
|
2401
|
+
const len = this.options.length;
|
|
2402
|
+
for (let i = 0; i < len; i++) {
|
|
2403
|
+
const key = this.options[i].attributeName();
|
|
2404
|
+
result[key] = key === this._versionOptionName ? this._version : this[key];
|
|
2405
|
+
}
|
|
2406
|
+
return result;
|
|
2407
|
+
}
|
|
2408
|
+
return this._optionValues;
|
|
2409
|
+
}
|
|
2410
|
+
/**
|
|
2411
|
+
* Return an object containing merged local and global option values as key-value pairs.
|
|
2412
|
+
*
|
|
2413
|
+
* @return {object}
|
|
2414
|
+
*/
|
|
2415
|
+
optsWithGlobals() {
|
|
2416
|
+
return this._getCommandAndAncestors().reduce((combinedOptions, cmd) => Object.assign(combinedOptions, cmd.opts()), {});
|
|
2417
|
+
}
|
|
2418
|
+
/**
|
|
2419
|
+
* Display error message and exit (or call exitOverride).
|
|
2420
|
+
*
|
|
2421
|
+
* @param {string} message
|
|
2422
|
+
* @param {object} [errorOptions]
|
|
2423
|
+
* @param {string} [errorOptions.code] - an id string representing the error
|
|
2424
|
+
* @param {number} [errorOptions.exitCode] - used with process.exit
|
|
2425
|
+
*/
|
|
2426
|
+
error(message, errorOptions) {
|
|
2427
|
+
this._outputConfiguration.outputError(`${message}\n`, this._outputConfiguration.writeErr);
|
|
2428
|
+
if (typeof this._showHelpAfterError === "string") this._outputConfiguration.writeErr(`${this._showHelpAfterError}\n`);
|
|
2429
|
+
else if (this._showHelpAfterError) {
|
|
2430
|
+
this._outputConfiguration.writeErr("\n");
|
|
2431
|
+
this.outputHelp({ error: true });
|
|
2432
|
+
}
|
|
2433
|
+
const config = errorOptions || {};
|
|
2434
|
+
const exitCode = config.exitCode || 1;
|
|
2435
|
+
const code = config.code || "commander.error";
|
|
2436
|
+
this._exit(exitCode, code, message);
|
|
2437
|
+
}
|
|
2438
|
+
/**
|
|
2439
|
+
* Apply any option related environment variables, if option does
|
|
2440
|
+
* not have a value from cli or client code.
|
|
2441
|
+
*
|
|
2442
|
+
* @private
|
|
2443
|
+
*/
|
|
2444
|
+
_parseOptionsEnv() {
|
|
2445
|
+
this.options.forEach((option) => {
|
|
2446
|
+
if (option.envVar && option.envVar in process$1.env) {
|
|
2447
|
+
const optionKey = option.attributeName();
|
|
2448
|
+
if (this.getOptionValue(optionKey) === void 0 || [
|
|
2449
|
+
"default",
|
|
2450
|
+
"config",
|
|
2451
|
+
"env"
|
|
2452
|
+
].includes(this.getOptionValueSource(optionKey))) if (option.required || option.optional) this.emit(`optionEnv:${option.name()}`, process$1.env[option.envVar]);
|
|
2453
|
+
else this.emit(`optionEnv:${option.name()}`);
|
|
2454
|
+
}
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
/**
|
|
2458
|
+
* Apply any implied option values, if option is undefined or default value.
|
|
2459
|
+
*
|
|
2460
|
+
* @private
|
|
2461
|
+
*/
|
|
2462
|
+
_parseOptionsImplied() {
|
|
2463
|
+
const dualHelper = new DualOptions(this.options);
|
|
2464
|
+
const hasCustomOptionValue = (optionKey) => {
|
|
2465
|
+
return this.getOptionValue(optionKey) !== void 0 && !["default", "implied"].includes(this.getOptionValueSource(optionKey));
|
|
2466
|
+
};
|
|
2467
|
+
this.options.filter((option) => option.implied !== void 0 && hasCustomOptionValue(option.attributeName()) && dualHelper.valueFromOption(this.getOptionValue(option.attributeName()), option)).forEach((option) => {
|
|
2468
|
+
Object.keys(option.implied).filter((impliedKey) => !hasCustomOptionValue(impliedKey)).forEach((impliedKey) => {
|
|
2469
|
+
this.setOptionValueWithSource(impliedKey, option.implied[impliedKey], "implied");
|
|
2470
|
+
});
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
/**
|
|
2474
|
+
* Argument `name` is missing.
|
|
2475
|
+
*
|
|
2476
|
+
* @param {string} name
|
|
2477
|
+
* @private
|
|
2478
|
+
*/
|
|
2479
|
+
missingArgument(name) {
|
|
2480
|
+
const message = `error: missing required argument '${name}'`;
|
|
2481
|
+
this.error(message, { code: "commander.missingArgument" });
|
|
2482
|
+
}
|
|
2483
|
+
/**
|
|
2484
|
+
* `Option` is missing an argument.
|
|
2485
|
+
*
|
|
2486
|
+
* @param {Option} option
|
|
2487
|
+
* @private
|
|
2488
|
+
*/
|
|
2489
|
+
optionMissingArgument(option) {
|
|
2490
|
+
const message = `error: option '${option.flags}' argument missing`;
|
|
2491
|
+
this.error(message, { code: "commander.optionMissingArgument" });
|
|
2492
|
+
}
|
|
2493
|
+
/**
|
|
2494
|
+
* `Option` does not have a value, and is a mandatory option.
|
|
2495
|
+
*
|
|
2496
|
+
* @param {Option} option
|
|
2497
|
+
* @private
|
|
2498
|
+
*/
|
|
2499
|
+
missingMandatoryOptionValue(option) {
|
|
2500
|
+
const message = `error: required option '${option.flags}' not specified`;
|
|
2501
|
+
this.error(message, { code: "commander.missingMandatoryOptionValue" });
|
|
2502
|
+
}
|
|
2503
|
+
/**
|
|
2504
|
+
* `Option` conflicts with another option.
|
|
2505
|
+
*
|
|
2506
|
+
* @param {Option} option
|
|
2507
|
+
* @param {Option} conflictingOption
|
|
2508
|
+
* @private
|
|
2509
|
+
*/
|
|
2510
|
+
_conflictingOption(option, conflictingOption) {
|
|
2511
|
+
const findBestOptionFromValue = (option) => {
|
|
2512
|
+
const optionKey = option.attributeName();
|
|
2513
|
+
const optionValue = this.getOptionValue(optionKey);
|
|
2514
|
+
const negativeOption = this.options.find((target) => target.negate && optionKey === target.attributeName());
|
|
2515
|
+
const positiveOption = this.options.find((target) => !target.negate && optionKey === target.attributeName());
|
|
2516
|
+
if (negativeOption && (negativeOption.presetArg === void 0 && optionValue === false || negativeOption.presetArg !== void 0 && optionValue === negativeOption.presetArg)) return negativeOption;
|
|
2517
|
+
return positiveOption || option;
|
|
2518
|
+
};
|
|
2519
|
+
const getErrorMessage = (option) => {
|
|
2520
|
+
const bestOption = findBestOptionFromValue(option);
|
|
2521
|
+
const optionKey = bestOption.attributeName();
|
|
2522
|
+
if (this.getOptionValueSource(optionKey) === "env") return `environment variable '${bestOption.envVar}'`;
|
|
2523
|
+
return `option '${bestOption.flags}'`;
|
|
2524
|
+
};
|
|
2525
|
+
const message = `error: ${getErrorMessage(option)} cannot be used with ${getErrorMessage(conflictingOption)}`;
|
|
2526
|
+
this.error(message, { code: "commander.conflictingOption" });
|
|
2527
|
+
}
|
|
2528
|
+
/**
|
|
2529
|
+
* Unknown option `flag`.
|
|
2530
|
+
*
|
|
2531
|
+
* @param {string} flag
|
|
2532
|
+
* @private
|
|
2533
|
+
*/
|
|
2534
|
+
unknownOption(flag) {
|
|
2535
|
+
if (this._allowUnknownOption) return;
|
|
2536
|
+
let suggestion = "";
|
|
2537
|
+
if (flag.startsWith("--") && this._showSuggestionAfterError) {
|
|
2538
|
+
let candidateFlags = [];
|
|
2539
|
+
let command = this;
|
|
2540
|
+
do {
|
|
2541
|
+
const moreFlags = command.createHelp().visibleOptions(command).filter((option) => option.long).map((option) => option.long);
|
|
2542
|
+
candidateFlags = candidateFlags.concat(moreFlags);
|
|
2543
|
+
command = command.parent;
|
|
2544
|
+
} while (command && !command._enablePositionalOptions);
|
|
2545
|
+
suggestion = suggestSimilar(flag, candidateFlags);
|
|
2546
|
+
}
|
|
2547
|
+
const message = `error: unknown option '${flag}'${suggestion}`;
|
|
2548
|
+
this.error(message, { code: "commander.unknownOption" });
|
|
2549
|
+
}
|
|
2550
|
+
/**
|
|
2551
|
+
* Excess arguments, more than expected.
|
|
2552
|
+
*
|
|
2553
|
+
* @param {string[]} receivedArgs
|
|
2554
|
+
* @private
|
|
2555
|
+
*/
|
|
2556
|
+
_excessArguments(receivedArgs) {
|
|
2557
|
+
if (this._allowExcessArguments) return;
|
|
2558
|
+
const expected = this.registeredArguments.length;
|
|
2559
|
+
const s = expected === 1 ? "" : "s";
|
|
2560
|
+
const message = `error: too many arguments${this.parent ? ` for '${this.name()}'` : ""}. Expected ${expected} argument${s} but got ${receivedArgs.length}.`;
|
|
2561
|
+
this.error(message, { code: "commander.excessArguments" });
|
|
2562
|
+
}
|
|
2563
|
+
/**
|
|
2564
|
+
* Unknown command.
|
|
2565
|
+
*
|
|
2566
|
+
* @private
|
|
2567
|
+
*/
|
|
2568
|
+
unknownCommand() {
|
|
2569
|
+
const unknownName = this.args[0];
|
|
2570
|
+
let suggestion = "";
|
|
2571
|
+
if (this._showSuggestionAfterError) {
|
|
2572
|
+
const candidateNames = [];
|
|
2573
|
+
this.createHelp().visibleCommands(this).forEach((command) => {
|
|
2574
|
+
candidateNames.push(command.name());
|
|
2575
|
+
if (command.alias()) candidateNames.push(command.alias());
|
|
2576
|
+
});
|
|
2577
|
+
suggestion = suggestSimilar(unknownName, candidateNames);
|
|
2578
|
+
}
|
|
2579
|
+
const message = `error: unknown command '${unknownName}'${suggestion}`;
|
|
2580
|
+
this.error(message, { code: "commander.unknownCommand" });
|
|
2581
|
+
}
|
|
2582
|
+
/**
|
|
2583
|
+
* Get or set the program version.
|
|
2584
|
+
*
|
|
2585
|
+
* This method auto-registers the "-V, --version" option which will print the version number.
|
|
2586
|
+
*
|
|
2587
|
+
* You can optionally supply the flags and description to override the defaults.
|
|
2588
|
+
*
|
|
2589
|
+
* @param {string} [str]
|
|
2590
|
+
* @param {string} [flags]
|
|
2591
|
+
* @param {string} [description]
|
|
2592
|
+
* @return {(this | string | undefined)} `this` command for chaining, or version string if no arguments
|
|
2593
|
+
*/
|
|
2594
|
+
version(str, flags, description) {
|
|
2595
|
+
if (str === void 0) return this._version;
|
|
2596
|
+
this._version = str;
|
|
2597
|
+
flags = flags || "-V, --version";
|
|
2598
|
+
description = description || "output the version number";
|
|
2599
|
+
const versionOption = this.createOption(flags, description);
|
|
2600
|
+
this._versionOptionName = versionOption.attributeName();
|
|
2601
|
+
this._registerOption(versionOption);
|
|
2602
|
+
this.on("option:" + versionOption.name(), () => {
|
|
2603
|
+
this._outputConfiguration.writeOut(`${str}\n`);
|
|
2604
|
+
this._exit(0, "commander.version", str);
|
|
2605
|
+
});
|
|
2606
|
+
return this;
|
|
2607
|
+
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Set the description.
|
|
2610
|
+
*
|
|
2611
|
+
* @param {string} [str]
|
|
2612
|
+
* @param {object} [argsDescription]
|
|
2613
|
+
* @return {(string|Command)}
|
|
2614
|
+
*/
|
|
2615
|
+
description(str, argsDescription) {
|
|
2616
|
+
if (str === void 0 && argsDescription === void 0) return this._description;
|
|
2617
|
+
this._description = str;
|
|
2618
|
+
if (argsDescription) this._argsDescription = argsDescription;
|
|
2619
|
+
return this;
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Set the summary. Used when listed as subcommand of parent.
|
|
2623
|
+
*
|
|
2624
|
+
* @param {string} [str]
|
|
2625
|
+
* @return {(string|Command)}
|
|
2626
|
+
*/
|
|
2627
|
+
summary(str) {
|
|
2628
|
+
if (str === void 0) return this._summary;
|
|
2629
|
+
this._summary = str;
|
|
2630
|
+
return this;
|
|
2631
|
+
}
|
|
2632
|
+
/**
|
|
2633
|
+
* Set an alias for the command.
|
|
2634
|
+
*
|
|
2635
|
+
* You may call more than once to add multiple aliases. Only the first alias is shown in the auto-generated help.
|
|
2636
|
+
*
|
|
2637
|
+
* @param {string} [alias]
|
|
2638
|
+
* @return {(string|Command)}
|
|
2639
|
+
*/
|
|
2640
|
+
alias(alias) {
|
|
2641
|
+
if (alias === void 0) return this._aliases[0];
|
|
2642
|
+
/** @type {Command} */
|
|
2643
|
+
let command = this;
|
|
2644
|
+
if (this.commands.length !== 0 && this.commands[this.commands.length - 1]._executableHandler) command = this.commands[this.commands.length - 1];
|
|
2645
|
+
if (alias === command._name) throw new Error("Command alias can't be the same as its name");
|
|
2646
|
+
const matchingCommand = this.parent?._findCommand(alias);
|
|
2647
|
+
if (matchingCommand) {
|
|
2648
|
+
const existingCmd = [matchingCommand.name()].concat(matchingCommand.aliases()).join("|");
|
|
2649
|
+
throw new Error(`cannot add alias '${alias}' to command '${this.name()}' as already have command '${existingCmd}'`);
|
|
2650
|
+
}
|
|
2651
|
+
command._aliases.push(alias);
|
|
2652
|
+
return this;
|
|
2653
|
+
}
|
|
2654
|
+
/**
|
|
2655
|
+
* Set aliases for the command.
|
|
2656
|
+
*
|
|
2657
|
+
* Only the first alias is shown in the auto-generated help.
|
|
2658
|
+
*
|
|
2659
|
+
* @param {string[]} [aliases]
|
|
2660
|
+
* @return {(string[]|Command)}
|
|
2661
|
+
*/
|
|
2662
|
+
aliases(aliases) {
|
|
2663
|
+
if (aliases === void 0) return this._aliases;
|
|
2664
|
+
aliases.forEach((alias) => this.alias(alias));
|
|
2665
|
+
return this;
|
|
2666
|
+
}
|
|
2667
|
+
/**
|
|
2668
|
+
* Set / get the command usage `str`.
|
|
2669
|
+
*
|
|
2670
|
+
* @param {string} [str]
|
|
2671
|
+
* @return {(string|Command)}
|
|
2672
|
+
*/
|
|
2673
|
+
usage(str) {
|
|
2674
|
+
if (str === void 0) {
|
|
2675
|
+
if (this._usage) return this._usage;
|
|
2676
|
+
const args = this.registeredArguments.map((arg) => {
|
|
2677
|
+
return humanReadableArgName(arg);
|
|
2678
|
+
});
|
|
2679
|
+
return [].concat(this.options.length || this._helpOption !== null ? "[options]" : [], this.commands.length ? "[command]" : [], this.registeredArguments.length ? args : []).join(" ");
|
|
2680
|
+
}
|
|
2681
|
+
this._usage = str;
|
|
2682
|
+
return this;
|
|
2683
|
+
}
|
|
2684
|
+
/**
|
|
2685
|
+
* Get or set the name of the command.
|
|
2686
|
+
*
|
|
2687
|
+
* @param {string} [str]
|
|
2688
|
+
* @return {(string|Command)}
|
|
2689
|
+
*/
|
|
2690
|
+
name(str) {
|
|
2691
|
+
if (str === void 0) return this._name;
|
|
2692
|
+
this._name = str;
|
|
2693
|
+
return this;
|
|
2694
|
+
}
|
|
2695
|
+
/**
|
|
2696
|
+
* Set/get the help group heading for this subcommand in parent command's help.
|
|
2697
|
+
*
|
|
2698
|
+
* @param {string} [heading]
|
|
2699
|
+
* @return {Command | string}
|
|
2700
|
+
*/
|
|
2701
|
+
helpGroup(heading) {
|
|
2702
|
+
if (heading === void 0) return this._helpGroupHeading ?? "";
|
|
2703
|
+
this._helpGroupHeading = heading;
|
|
2704
|
+
return this;
|
|
2705
|
+
}
|
|
2706
|
+
/**
|
|
2707
|
+
* Set/get the default help group heading for subcommands added to this command.
|
|
2708
|
+
* (This does not override a group set directly on the subcommand using .helpGroup().)
|
|
2709
|
+
*
|
|
2710
|
+
* @example
|
|
2711
|
+
* program.commandsGroup('Development Commands:);
|
|
2712
|
+
* program.command('watch')...
|
|
2713
|
+
* program.command('lint')...
|
|
2714
|
+
* ...
|
|
2715
|
+
*
|
|
2716
|
+
* @param {string} [heading]
|
|
2717
|
+
* @returns {Command | string}
|
|
2718
|
+
*/
|
|
2719
|
+
commandsGroup(heading) {
|
|
2720
|
+
if (heading === void 0) return this._defaultCommandGroup ?? "";
|
|
2721
|
+
this._defaultCommandGroup = heading;
|
|
2722
|
+
return this;
|
|
2723
|
+
}
|
|
2724
|
+
/**
|
|
2725
|
+
* Set/get the default help group heading for options added to this command.
|
|
2726
|
+
* (This does not override a group set directly on the option using .helpGroup().)
|
|
2727
|
+
*
|
|
2728
|
+
* @example
|
|
2729
|
+
* program
|
|
2730
|
+
* .optionsGroup('Development Options:')
|
|
2731
|
+
* .option('-d, --debug', 'output extra debugging')
|
|
2732
|
+
* .option('-p, --profile', 'output profiling information')
|
|
2733
|
+
*
|
|
2734
|
+
* @param {string} [heading]
|
|
2735
|
+
* @returns {Command | string}
|
|
2736
|
+
*/
|
|
2737
|
+
optionsGroup(heading) {
|
|
2738
|
+
if (heading === void 0) return this._defaultOptionGroup ?? "";
|
|
2739
|
+
this._defaultOptionGroup = heading;
|
|
2740
|
+
return this;
|
|
2741
|
+
}
|
|
2742
|
+
/**
|
|
2743
|
+
* @param {Option} option
|
|
2744
|
+
* @private
|
|
2745
|
+
*/
|
|
2746
|
+
_initOptionGroup(option) {
|
|
2747
|
+
if (this._defaultOptionGroup && !option.helpGroupHeading) option.helpGroup(this._defaultOptionGroup);
|
|
2748
|
+
}
|
|
2749
|
+
/**
|
|
2750
|
+
* @param {Command} cmd
|
|
2751
|
+
* @private
|
|
2752
|
+
*/
|
|
2753
|
+
_initCommandGroup(cmd) {
|
|
2754
|
+
if (this._defaultCommandGroup && !cmd.helpGroup()) cmd.helpGroup(this._defaultCommandGroup);
|
|
2755
|
+
}
|
|
2756
|
+
/**
|
|
2757
|
+
* Set the name of the command from script filename, such as process.argv[1],
|
|
2758
|
+
* or require.main.filename, or __filename.
|
|
2759
|
+
*
|
|
2760
|
+
* (Used internally and public although not documented in README.)
|
|
2761
|
+
*
|
|
2762
|
+
* @example
|
|
2763
|
+
* program.nameFromFilename(require.main.filename);
|
|
2764
|
+
*
|
|
2765
|
+
* @param {string} filename
|
|
2766
|
+
* @return {Command}
|
|
2767
|
+
*/
|
|
2768
|
+
nameFromFilename(filename) {
|
|
2769
|
+
this._name = path.basename(filename, path.extname(filename));
|
|
2770
|
+
return this;
|
|
2771
|
+
}
|
|
2772
|
+
/**
|
|
2773
|
+
* Get or set the directory for searching for executable subcommands of this command.
|
|
2774
|
+
*
|
|
2775
|
+
* @example
|
|
2776
|
+
* program.executableDir(__dirname);
|
|
2777
|
+
* // or
|
|
2778
|
+
* program.executableDir('subcommands');
|
|
2779
|
+
*
|
|
2780
|
+
* @param {string} [path]
|
|
2781
|
+
* @return {(string|null|Command)}
|
|
2782
|
+
*/
|
|
2783
|
+
executableDir(path) {
|
|
2784
|
+
if (path === void 0) return this._executableDir;
|
|
2785
|
+
this._executableDir = path;
|
|
2786
|
+
return this;
|
|
2787
|
+
}
|
|
2788
|
+
/**
|
|
2789
|
+
* Return program help documentation.
|
|
2790
|
+
*
|
|
2791
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to wrap for stderr instead of stdout
|
|
2792
|
+
* @return {string}
|
|
2793
|
+
*/
|
|
2794
|
+
helpInformation(contextOptions) {
|
|
2795
|
+
const helper = this.createHelp();
|
|
2796
|
+
const context = this._getOutputContext(contextOptions);
|
|
2797
|
+
helper.prepareContext({
|
|
2798
|
+
error: context.error,
|
|
2799
|
+
helpWidth: context.helpWidth,
|
|
2800
|
+
outputHasColors: context.hasColors
|
|
2801
|
+
});
|
|
2802
|
+
const text = helper.formatHelp(this, helper);
|
|
2803
|
+
if (context.hasColors) return text;
|
|
2804
|
+
return this._outputConfiguration.stripColor(text);
|
|
2805
|
+
}
|
|
2806
|
+
/**
|
|
2807
|
+
* @typedef HelpContext
|
|
2808
|
+
* @type {object}
|
|
2809
|
+
* @property {boolean} error
|
|
2810
|
+
* @property {number} helpWidth
|
|
2811
|
+
* @property {boolean} hasColors
|
|
2812
|
+
* @property {function} write - includes stripColor if needed
|
|
2813
|
+
*
|
|
2814
|
+
* @returns {HelpContext}
|
|
2815
|
+
* @private
|
|
2816
|
+
*/
|
|
2817
|
+
_getOutputContext(contextOptions) {
|
|
2818
|
+
contextOptions = contextOptions || {};
|
|
2819
|
+
const error = !!contextOptions.error;
|
|
2820
|
+
let baseWrite;
|
|
2821
|
+
let hasColors;
|
|
2822
|
+
let helpWidth;
|
|
2823
|
+
if (error) {
|
|
2824
|
+
baseWrite = (str) => this._outputConfiguration.writeErr(str);
|
|
2825
|
+
hasColors = this._outputConfiguration.getErrHasColors();
|
|
2826
|
+
helpWidth = this._outputConfiguration.getErrHelpWidth();
|
|
2827
|
+
} else {
|
|
2828
|
+
baseWrite = (str) => this._outputConfiguration.writeOut(str);
|
|
2829
|
+
hasColors = this._outputConfiguration.getOutHasColors();
|
|
2830
|
+
helpWidth = this._outputConfiguration.getOutHelpWidth();
|
|
2831
|
+
}
|
|
2832
|
+
const write = (str) => {
|
|
2833
|
+
if (!hasColors) str = this._outputConfiguration.stripColor(str);
|
|
2834
|
+
return baseWrite(str);
|
|
2835
|
+
};
|
|
2836
|
+
return {
|
|
2837
|
+
error,
|
|
2838
|
+
write,
|
|
2839
|
+
hasColors,
|
|
2840
|
+
helpWidth
|
|
2841
|
+
};
|
|
2842
|
+
}
|
|
2843
|
+
/**
|
|
2844
|
+
* Output help information for this command.
|
|
2845
|
+
*
|
|
2846
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
2847
|
+
*
|
|
2848
|
+
* @param {{ error: boolean } | Function} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
2849
|
+
*/
|
|
2850
|
+
outputHelp(contextOptions) {
|
|
2851
|
+
let deprecatedCallback;
|
|
2852
|
+
if (typeof contextOptions === "function") {
|
|
2853
|
+
deprecatedCallback = contextOptions;
|
|
2854
|
+
contextOptions = void 0;
|
|
2855
|
+
}
|
|
2856
|
+
const outputContext = this._getOutputContext(contextOptions);
|
|
2857
|
+
/** @type {HelpTextEventContext} */
|
|
2858
|
+
const eventContext = {
|
|
2859
|
+
error: outputContext.error,
|
|
2860
|
+
write: outputContext.write,
|
|
2861
|
+
command: this
|
|
2862
|
+
};
|
|
2863
|
+
this._getCommandAndAncestors().reverse().forEach((command) => command.emit("beforeAllHelp", eventContext));
|
|
2864
|
+
this.emit("beforeHelp", eventContext);
|
|
2865
|
+
let helpInformation = this.helpInformation({ error: outputContext.error });
|
|
2866
|
+
if (deprecatedCallback) {
|
|
2867
|
+
helpInformation = deprecatedCallback(helpInformation);
|
|
2868
|
+
if (typeof helpInformation !== "string" && !Buffer.isBuffer(helpInformation)) throw new Error("outputHelp callback must return a string or a Buffer");
|
|
2869
|
+
}
|
|
2870
|
+
outputContext.write(helpInformation);
|
|
2871
|
+
if (this._getHelpOption()?.long) this.emit(this._getHelpOption().long);
|
|
2872
|
+
this.emit("afterHelp", eventContext);
|
|
2873
|
+
this._getCommandAndAncestors().forEach((command) => command.emit("afterAllHelp", eventContext));
|
|
2874
|
+
}
|
|
2875
|
+
/**
|
|
2876
|
+
* You can pass in flags and a description to customise the built-in help option.
|
|
2877
|
+
* Pass in false to disable the built-in help option.
|
|
2878
|
+
*
|
|
2879
|
+
* @example
|
|
2880
|
+
* program.helpOption('-?, --help' 'show help'); // customise
|
|
2881
|
+
* program.helpOption(false); // disable
|
|
2882
|
+
*
|
|
2883
|
+
* @param {(string | boolean)} flags
|
|
2884
|
+
* @param {string} [description]
|
|
2885
|
+
* @return {Command} `this` command for chaining
|
|
2886
|
+
*/
|
|
2887
|
+
helpOption(flags, description) {
|
|
2888
|
+
if (typeof flags === "boolean") {
|
|
2889
|
+
if (flags) {
|
|
2890
|
+
if (this._helpOption === null) this._helpOption = void 0;
|
|
2891
|
+
if (this._defaultOptionGroup) this._initOptionGroup(this._getHelpOption());
|
|
2892
|
+
} else this._helpOption = null;
|
|
2893
|
+
return this;
|
|
2894
|
+
}
|
|
2895
|
+
this._helpOption = this.createOption(flags ?? "-h, --help", description ?? "display help for command");
|
|
2896
|
+
if (flags || description) this._initOptionGroup(this._helpOption);
|
|
2897
|
+
return this;
|
|
2898
|
+
}
|
|
2899
|
+
/**
|
|
2900
|
+
* Lazy create help option.
|
|
2901
|
+
* Returns null if has been disabled with .helpOption(false).
|
|
2902
|
+
*
|
|
2903
|
+
* @returns {(Option | null)} the help option
|
|
2904
|
+
* @package
|
|
2905
|
+
*/
|
|
2906
|
+
_getHelpOption() {
|
|
2907
|
+
if (this._helpOption === void 0) this.helpOption(void 0, void 0);
|
|
2908
|
+
return this._helpOption;
|
|
2909
|
+
}
|
|
2910
|
+
/**
|
|
2911
|
+
* Supply your own option to use for the built-in help option.
|
|
2912
|
+
* This is an alternative to using helpOption() to customise the flags and description etc.
|
|
2913
|
+
*
|
|
2914
|
+
* @param {Option} option
|
|
2915
|
+
* @return {Command} `this` command for chaining
|
|
2916
|
+
*/
|
|
2917
|
+
addHelpOption(option) {
|
|
2918
|
+
this._helpOption = option;
|
|
2919
|
+
this._initOptionGroup(option);
|
|
2920
|
+
return this;
|
|
2921
|
+
}
|
|
2922
|
+
/**
|
|
2923
|
+
* Output help information and exit.
|
|
2924
|
+
*
|
|
2925
|
+
* Outputs built-in help, and custom text added using `.addHelpText()`.
|
|
2926
|
+
*
|
|
2927
|
+
* @param {{ error: boolean }} [contextOptions] - pass {error:true} to write to stderr instead of stdout
|
|
2928
|
+
*/
|
|
2929
|
+
help(contextOptions) {
|
|
2930
|
+
this.outputHelp(contextOptions);
|
|
2931
|
+
let exitCode = Number(process$1.exitCode ?? 0);
|
|
2932
|
+
if (exitCode === 0 && contextOptions && typeof contextOptions !== "function" && contextOptions.error) exitCode = 1;
|
|
2933
|
+
this._exit(exitCode, "commander.help", "(outputHelp)");
|
|
2934
|
+
}
|
|
2935
|
+
/**
|
|
2936
|
+
* // Do a little typing to coordinate emit and listener for the help text events.
|
|
2937
|
+
* @typedef HelpTextEventContext
|
|
2938
|
+
* @type {object}
|
|
2939
|
+
* @property {boolean} error
|
|
2940
|
+
* @property {Command} command
|
|
2941
|
+
* @property {function} write
|
|
2942
|
+
*/
|
|
2943
|
+
/**
|
|
2944
|
+
* Add additional text to be displayed with the built-in help.
|
|
2945
|
+
*
|
|
2946
|
+
* Position is 'before' or 'after' to affect just this command,
|
|
2947
|
+
* and 'beforeAll' or 'afterAll' to affect this command and all its subcommands.
|
|
2948
|
+
*
|
|
2949
|
+
* @param {string} position - before or after built-in help
|
|
2950
|
+
* @param {(string | Function)} text - string to add, or a function returning a string
|
|
2951
|
+
* @return {Command} `this` command for chaining
|
|
2952
|
+
*/
|
|
2953
|
+
addHelpText(position, text) {
|
|
2954
|
+
const allowedValues = [
|
|
2955
|
+
"beforeAll",
|
|
2956
|
+
"before",
|
|
2957
|
+
"after",
|
|
2958
|
+
"afterAll"
|
|
2959
|
+
];
|
|
2960
|
+
if (!allowedValues.includes(position)) throw new Error(`Unexpected value for position to addHelpText.
|
|
2961
|
+
Expecting one of '${allowedValues.join("', '")}'`);
|
|
2962
|
+
const helpEvent = `${position}Help`;
|
|
2963
|
+
this.on(helpEvent, (context) => {
|
|
2964
|
+
let helpStr;
|
|
2965
|
+
if (typeof text === "function") helpStr = text({
|
|
2966
|
+
error: context.error,
|
|
2967
|
+
command: context.command
|
|
2968
|
+
});
|
|
2969
|
+
else helpStr = text;
|
|
2970
|
+
if (helpStr) context.write(`${helpStr}\n`);
|
|
2971
|
+
});
|
|
2972
|
+
return this;
|
|
2973
|
+
}
|
|
2974
|
+
/**
|
|
2975
|
+
* Output help information if help flags specified
|
|
2976
|
+
*
|
|
2977
|
+
* @param {Array} args - array of options to search for help flags
|
|
2978
|
+
* @private
|
|
2979
|
+
*/
|
|
2980
|
+
_outputHelpIfRequested(args) {
|
|
2981
|
+
const helpOption = this._getHelpOption();
|
|
2982
|
+
if (helpOption && args.find((arg) => helpOption.is(arg))) {
|
|
2983
|
+
this.outputHelp();
|
|
2984
|
+
this._exit(0, "commander.helpDisplayed", "(outputHelp)");
|
|
2985
|
+
}
|
|
2986
|
+
}
|
|
2987
|
+
};
|
|
2988
|
+
/**
|
|
2989
|
+
* Scan arguments and increment port number for inspect calls (to avoid conflicts when spawning new command).
|
|
2990
|
+
*
|
|
2991
|
+
* @param {string[]} args - array of arguments from node.execArgv
|
|
2992
|
+
* @returns {string[]}
|
|
2993
|
+
* @private
|
|
2994
|
+
*/
|
|
2995
|
+
function incrementNodeInspectorPort(args) {
|
|
2996
|
+
return args.map((arg) => {
|
|
2997
|
+
if (!arg.startsWith("--inspect")) return arg;
|
|
2998
|
+
let debugOption;
|
|
2999
|
+
let debugHost = "127.0.0.1";
|
|
3000
|
+
let debugPort = "9229";
|
|
3001
|
+
let match;
|
|
3002
|
+
if ((match = arg.match(/^(--inspect(-brk)?)$/)) !== null) debugOption = match[1];
|
|
3003
|
+
else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+)$/)) !== null) {
|
|
3004
|
+
debugOption = match[1];
|
|
3005
|
+
if (/^\d+$/.test(match[3])) debugPort = match[3];
|
|
3006
|
+
else debugHost = match[3];
|
|
3007
|
+
} else if ((match = arg.match(/^(--inspect(-brk|-port)?)=([^:]+):(\d+)$/)) !== null) {
|
|
3008
|
+
debugOption = match[1];
|
|
3009
|
+
debugHost = match[3];
|
|
3010
|
+
debugPort = match[4];
|
|
3011
|
+
}
|
|
3012
|
+
if (debugOption && debugPort !== "0") return `${debugOption}=${debugHost}:${parseInt(debugPort) + 1}`;
|
|
3013
|
+
return arg;
|
|
3014
|
+
});
|
|
3015
|
+
}
|
|
3016
|
+
/**
|
|
3017
|
+
* @returns {boolean | undefined}
|
|
3018
|
+
* @package
|
|
3019
|
+
*/
|
|
3020
|
+
function useColor() {
|
|
3021
|
+
if (process$1.env.NO_COLOR || process$1.env.FORCE_COLOR === "0" || process$1.env.FORCE_COLOR === "false") return false;
|
|
3022
|
+
if (process$1.env.FORCE_COLOR || process$1.env.CLICOLOR_FORCE !== void 0) return true;
|
|
3023
|
+
}
|
|
3024
|
+
exports.Command = Command;
|
|
3025
|
+
exports.useColor = useColor;
|
|
3026
|
+
}));
|
|
3027
|
+
|
|
3028
|
+
//#endregion
|
|
3029
|
+
//#region node_modules/commander/index.js
|
|
3030
|
+
var require_commander = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
3031
|
+
const { Argument } = require_argument();
|
|
3032
|
+
const { Command } = require_command();
|
|
3033
|
+
const { CommanderError, InvalidArgumentError } = require_error();
|
|
3034
|
+
const { Help } = require_help();
|
|
3035
|
+
const { Option } = require_option();
|
|
3036
|
+
exports.program = new Command();
|
|
3037
|
+
exports.createCommand = (name) => new Command(name);
|
|
3038
|
+
exports.createOption = (flags, description) => new Option(flags, description);
|
|
3039
|
+
exports.createArgument = (name, description) => new Argument(name, description);
|
|
3040
|
+
/**
|
|
3041
|
+
* Expose classes
|
|
3042
|
+
*/
|
|
3043
|
+
exports.Command = Command;
|
|
3044
|
+
exports.Option = Option;
|
|
3045
|
+
exports.Argument = Argument;
|
|
3046
|
+
exports.Help = Help;
|
|
3047
|
+
exports.CommanderError = CommanderError;
|
|
3048
|
+
exports.InvalidArgumentError = InvalidArgumentError;
|
|
3049
|
+
exports.InvalidOptionArgumentError = InvalidArgumentError;
|
|
3050
|
+
}));
|
|
3051
|
+
|
|
3052
|
+
//#endregion
|
|
3053
|
+
//#region node_modules/commander/esm.mjs
|
|
3054
|
+
var import_commander = /* @__PURE__ */ __toESM$2(require_commander(), 1);
|
|
3055
|
+
const { program: program$1, createCommand, createArgument, createOption, CommanderError, InvalidArgumentError, InvalidOptionArgumentError, Command, Argument, Option, Help } = import_commander.default;
|
|
3056
|
+
|
|
3057
|
+
//#endregion
|
|
3058
|
+
//#region node_modules/@trpc/client/dist/objectSpread2-BvkFp-_Y.mjs
|
|
3059
|
+
var __create$1 = Object.create;
|
|
3060
|
+
var __defProp$1 = Object.defineProperty;
|
|
3061
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
3062
|
+
var __getOwnPropNames$1 = Object.getOwnPropertyNames;
|
|
3063
|
+
var __getProtoOf$1 = Object.getPrototypeOf;
|
|
3064
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
3065
|
+
var __commonJS$1 = (cb, mod) => function() {
|
|
3066
|
+
return mod || (0, cb[__getOwnPropNames$1(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3067
|
+
};
|
|
3068
|
+
var __copyProps$1 = (to, from, except, desc) => {
|
|
3069
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames$1(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
3070
|
+
key = keys[i];
|
|
3071
|
+
if (!__hasOwnProp$1.call(to, key) && key !== except) __defProp$1(to, key, {
|
|
3072
|
+
get: ((k) => from[k]).bind(null, key),
|
|
3073
|
+
enumerable: !(desc = __getOwnPropDesc$1(from, key)) || desc.enumerable
|
|
3074
|
+
});
|
|
3075
|
+
}
|
|
3076
|
+
return to;
|
|
3077
|
+
};
|
|
3078
|
+
var __toESM$1 = (mod, isNodeMode, target) => (target = mod != null ? __create$1(__getProtoOf$1(mod)) : {}, __copyProps$1(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
|
|
3079
|
+
value: mod,
|
|
3080
|
+
enumerable: true
|
|
3081
|
+
}) : target, mod));
|
|
3082
|
+
var require_typeof$1 = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
3083
|
+
function _typeof$2(o) {
|
|
3084
|
+
"@babel/helpers - typeof";
|
|
3085
|
+
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
3086
|
+
return typeof o$1;
|
|
3087
|
+
} : function(o$1) {
|
|
3088
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
3089
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
3090
|
+
}
|
|
3091
|
+
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3092
|
+
} });
|
|
3093
|
+
var require_toPrimitive$1 = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
3094
|
+
var _typeof$1 = require_typeof$1()["default"];
|
|
3095
|
+
function toPrimitive$1(t, r) {
|
|
3096
|
+
if ("object" != _typeof$1(t) || !t) return t;
|
|
3097
|
+
var e = t[Symbol.toPrimitive];
|
|
3098
|
+
if (void 0 !== e) {
|
|
3099
|
+
var i = e.call(t, r || "default");
|
|
3100
|
+
if ("object" != _typeof$1(i)) return i;
|
|
3101
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
3102
|
+
}
|
|
3103
|
+
return ("string" === r ? String : Number)(t);
|
|
3104
|
+
}
|
|
3105
|
+
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3106
|
+
} });
|
|
3107
|
+
var require_toPropertyKey$1 = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
3108
|
+
var _typeof = require_typeof$1()["default"];
|
|
3109
|
+
var toPrimitive = require_toPrimitive$1();
|
|
3110
|
+
function toPropertyKey$1(t) {
|
|
3111
|
+
var i = toPrimitive(t, "string");
|
|
3112
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
3113
|
+
}
|
|
3114
|
+
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3115
|
+
} });
|
|
3116
|
+
var require_defineProperty$1 = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
3117
|
+
var toPropertyKey = require_toPropertyKey$1();
|
|
3118
|
+
function _defineProperty(e, r, t) {
|
|
3119
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
3120
|
+
value: t,
|
|
3121
|
+
enumerable: !0,
|
|
3122
|
+
configurable: !0,
|
|
3123
|
+
writable: !0
|
|
3124
|
+
}) : e[r] = t, e;
|
|
3125
|
+
}
|
|
3126
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3127
|
+
} });
|
|
3128
|
+
var require_objectSpread2$1 = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
3129
|
+
var defineProperty = require_defineProperty$1();
|
|
3130
|
+
function ownKeys(e, r) {
|
|
3131
|
+
var t = Object.keys(e);
|
|
3132
|
+
if (Object.getOwnPropertySymbols) {
|
|
3133
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
3134
|
+
r && (o = o.filter(function(r$1) {
|
|
3135
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
3136
|
+
})), t.push.apply(t, o);
|
|
3137
|
+
}
|
|
3138
|
+
return t;
|
|
3139
|
+
}
|
|
3140
|
+
function _objectSpread2(e) {
|
|
3141
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
3142
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
3143
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
3144
|
+
defineProperty(e, r$1, t[r$1]);
|
|
3145
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
3146
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
3147
|
+
});
|
|
3148
|
+
}
|
|
3149
|
+
return e;
|
|
3150
|
+
}
|
|
3151
|
+
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3152
|
+
} });
|
|
3153
|
+
|
|
3154
|
+
//#endregion
|
|
3155
|
+
//#region node_modules/@trpc/server/dist/observable-UMO3vUa_.mjs
|
|
3156
|
+
/** @public */
|
|
3157
|
+
function observable(subscribe) {
|
|
3158
|
+
const self = {
|
|
3159
|
+
subscribe(observer) {
|
|
3160
|
+
let teardownRef = null;
|
|
3161
|
+
let isDone = false;
|
|
3162
|
+
let unsubscribed = false;
|
|
3163
|
+
let teardownImmediately = false;
|
|
3164
|
+
function unsubscribe() {
|
|
3165
|
+
if (teardownRef === null) {
|
|
3166
|
+
teardownImmediately = true;
|
|
3167
|
+
return;
|
|
3168
|
+
}
|
|
3169
|
+
if (unsubscribed) return;
|
|
3170
|
+
unsubscribed = true;
|
|
3171
|
+
if (typeof teardownRef === "function") teardownRef();
|
|
3172
|
+
else if (teardownRef) teardownRef.unsubscribe();
|
|
3173
|
+
}
|
|
3174
|
+
teardownRef = subscribe({
|
|
3175
|
+
next(value) {
|
|
3176
|
+
var _observer$next;
|
|
3177
|
+
if (isDone) return;
|
|
3178
|
+
(_observer$next = observer.next) === null || _observer$next === void 0 || _observer$next.call(observer, value);
|
|
3179
|
+
},
|
|
3180
|
+
error(err) {
|
|
3181
|
+
var _observer$error;
|
|
3182
|
+
if (isDone) return;
|
|
3183
|
+
isDone = true;
|
|
3184
|
+
(_observer$error = observer.error) === null || _observer$error === void 0 || _observer$error.call(observer, err);
|
|
3185
|
+
unsubscribe();
|
|
3186
|
+
},
|
|
3187
|
+
complete() {
|
|
3188
|
+
var _observer$complete;
|
|
3189
|
+
if (isDone) return;
|
|
3190
|
+
isDone = true;
|
|
3191
|
+
(_observer$complete = observer.complete) === null || _observer$complete === void 0 || _observer$complete.call(observer);
|
|
3192
|
+
unsubscribe();
|
|
3193
|
+
}
|
|
3194
|
+
});
|
|
3195
|
+
if (teardownImmediately) unsubscribe();
|
|
3196
|
+
return { unsubscribe };
|
|
3197
|
+
},
|
|
3198
|
+
pipe(...operations) {
|
|
3199
|
+
return operations.reduce(pipeReducer, self);
|
|
3200
|
+
}
|
|
3201
|
+
};
|
|
3202
|
+
return self;
|
|
3203
|
+
}
|
|
3204
|
+
function pipeReducer(prev, fn) {
|
|
3205
|
+
return fn(prev);
|
|
3206
|
+
}
|
|
3207
|
+
/** @internal */
|
|
3208
|
+
function observableToPromise(observable$1) {
|
|
3209
|
+
const ac = new AbortController();
|
|
3210
|
+
return new Promise((resolve, reject) => {
|
|
3211
|
+
let isDone = false;
|
|
3212
|
+
function onDone() {
|
|
3213
|
+
if (isDone) return;
|
|
3214
|
+
isDone = true;
|
|
3215
|
+
obs$.unsubscribe();
|
|
3216
|
+
}
|
|
3217
|
+
ac.signal.addEventListener("abort", () => {
|
|
3218
|
+
reject(ac.signal.reason);
|
|
3219
|
+
});
|
|
3220
|
+
const obs$ = observable$1.subscribe({
|
|
3221
|
+
next(data) {
|
|
3222
|
+
isDone = true;
|
|
3223
|
+
resolve(data);
|
|
3224
|
+
onDone();
|
|
3225
|
+
},
|
|
3226
|
+
error(data) {
|
|
3227
|
+
reject(data);
|
|
3228
|
+
},
|
|
3229
|
+
complete() {
|
|
3230
|
+
ac.abort();
|
|
3231
|
+
onDone();
|
|
3232
|
+
}
|
|
3233
|
+
});
|
|
3234
|
+
});
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
//#endregion
|
|
3238
|
+
//#region node_modules/@trpc/server/dist/observable-CUiPknO-.mjs
|
|
3239
|
+
function share(_opts) {
|
|
3240
|
+
return (source) => {
|
|
3241
|
+
let refCount = 0;
|
|
3242
|
+
let subscription = null;
|
|
3243
|
+
const observers = [];
|
|
3244
|
+
function startIfNeeded() {
|
|
3245
|
+
if (subscription) return;
|
|
3246
|
+
subscription = source.subscribe({
|
|
3247
|
+
next(value) {
|
|
3248
|
+
for (const observer of observers) {
|
|
3249
|
+
var _observer$next;
|
|
3250
|
+
(_observer$next = observer.next) === null || _observer$next === void 0 || _observer$next.call(observer, value);
|
|
3251
|
+
}
|
|
3252
|
+
},
|
|
3253
|
+
error(error) {
|
|
3254
|
+
for (const observer of observers) {
|
|
3255
|
+
var _observer$error;
|
|
3256
|
+
(_observer$error = observer.error) === null || _observer$error === void 0 || _observer$error.call(observer, error);
|
|
3257
|
+
}
|
|
3258
|
+
},
|
|
3259
|
+
complete() {
|
|
3260
|
+
for (const observer of observers) {
|
|
3261
|
+
var _observer$complete;
|
|
3262
|
+
(_observer$complete = observer.complete) === null || _observer$complete === void 0 || _observer$complete.call(observer);
|
|
3263
|
+
}
|
|
3264
|
+
}
|
|
3265
|
+
});
|
|
3266
|
+
}
|
|
3267
|
+
function resetIfNeeded() {
|
|
3268
|
+
if (refCount === 0 && subscription) {
|
|
3269
|
+
const _sub = subscription;
|
|
3270
|
+
subscription = null;
|
|
3271
|
+
_sub.unsubscribe();
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
return observable((subscriber) => {
|
|
3275
|
+
refCount++;
|
|
3276
|
+
observers.push(subscriber);
|
|
3277
|
+
startIfNeeded();
|
|
3278
|
+
return { unsubscribe() {
|
|
3279
|
+
refCount--;
|
|
3280
|
+
resetIfNeeded();
|
|
3281
|
+
const index = observers.findIndex((v) => v === subscriber);
|
|
3282
|
+
if (index > -1) observers.splice(index, 1);
|
|
3283
|
+
} };
|
|
3284
|
+
});
|
|
3285
|
+
};
|
|
3286
|
+
}
|
|
3287
|
+
/**
|
|
3288
|
+
* @internal
|
|
3289
|
+
* An observable that maintains and provides a "current value" to subscribers
|
|
3290
|
+
* @see https://www.learnrxjs.io/learn-rxjs/subjects/behaviorsubject
|
|
3291
|
+
*/
|
|
3292
|
+
function behaviorSubject(initialValue) {
|
|
3293
|
+
let value = initialValue;
|
|
3294
|
+
const observerList = [];
|
|
3295
|
+
const addObserver = (observer) => {
|
|
3296
|
+
if (value !== void 0) observer.next(value);
|
|
3297
|
+
observerList.push(observer);
|
|
3298
|
+
};
|
|
3299
|
+
const removeObserver = (observer) => {
|
|
3300
|
+
observerList.splice(observerList.indexOf(observer), 1);
|
|
3301
|
+
};
|
|
3302
|
+
const obs = observable((observer) => {
|
|
3303
|
+
addObserver(observer);
|
|
3304
|
+
return () => {
|
|
3305
|
+
removeObserver(observer);
|
|
3306
|
+
};
|
|
3307
|
+
});
|
|
3308
|
+
obs.next = (nextValue) => {
|
|
3309
|
+
if (value === nextValue) return;
|
|
3310
|
+
value = nextValue;
|
|
3311
|
+
for (const observer of observerList) observer.next(nextValue);
|
|
3312
|
+
};
|
|
3313
|
+
obs.get = () => value;
|
|
3314
|
+
return obs;
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3317
|
+
//#endregion
|
|
3318
|
+
//#region node_modules/@trpc/client/dist/splitLink-B7Cuf2c_.mjs
|
|
3319
|
+
/** @internal */
|
|
3320
|
+
function createChain(opts) {
|
|
3321
|
+
return observable((observer) => {
|
|
3322
|
+
function execute(index = 0, op = opts.op) {
|
|
3323
|
+
const next = opts.links[index];
|
|
3324
|
+
if (!next) throw new Error("No more links to execute - did you forget to add an ending link?");
|
|
3325
|
+
return next({
|
|
3326
|
+
op,
|
|
3327
|
+
next(nextOp) {
|
|
3328
|
+
return execute(index + 1, nextOp);
|
|
3329
|
+
}
|
|
3330
|
+
});
|
|
3331
|
+
}
|
|
3332
|
+
return execute().subscribe(observer);
|
|
3333
|
+
});
|
|
3334
|
+
}
|
|
3335
|
+
|
|
3336
|
+
//#endregion
|
|
3337
|
+
//#region node_modules/@trpc/server/dist/codes-DagpWZLc.mjs
|
|
3338
|
+
/**
|
|
3339
|
+
* Check that value is object
|
|
3340
|
+
* @internal
|
|
3341
|
+
*/
|
|
3342
|
+
function isObject(value) {
|
|
3343
|
+
return !!value && !Array.isArray(value) && typeof value === "object";
|
|
3344
|
+
}
|
|
3345
|
+
/**
|
|
3346
|
+
* Create an object without inheriting anything from `Object.prototype`
|
|
3347
|
+
* @internal
|
|
3348
|
+
*/
|
|
3349
|
+
function emptyObject() {
|
|
3350
|
+
return Object.create(null);
|
|
3351
|
+
}
|
|
3352
|
+
/**
|
|
3353
|
+
* JSON-RPC 2.0 Error codes
|
|
3354
|
+
*
|
|
3355
|
+
* `-32000` to `-32099` are reserved for implementation-defined server-errors.
|
|
3356
|
+
* For tRPC we're copying the last digits of HTTP 4XX errors.
|
|
3357
|
+
*/
|
|
3358
|
+
const TRPC_ERROR_CODES_BY_KEY = {
|
|
3359
|
+
PARSE_ERROR: -32700,
|
|
3360
|
+
BAD_REQUEST: -32600,
|
|
3361
|
+
INTERNAL_SERVER_ERROR: -32603,
|
|
3362
|
+
NOT_IMPLEMENTED: -32603,
|
|
3363
|
+
BAD_GATEWAY: -32603,
|
|
3364
|
+
SERVICE_UNAVAILABLE: -32603,
|
|
3365
|
+
GATEWAY_TIMEOUT: -32603,
|
|
3366
|
+
UNAUTHORIZED: -32001,
|
|
3367
|
+
PAYMENT_REQUIRED: -32002,
|
|
3368
|
+
FORBIDDEN: -32003,
|
|
3369
|
+
NOT_FOUND: -32004,
|
|
3370
|
+
METHOD_NOT_SUPPORTED: -32005,
|
|
3371
|
+
TIMEOUT: -32008,
|
|
3372
|
+
CONFLICT: -32009,
|
|
3373
|
+
PRECONDITION_FAILED: -32012,
|
|
3374
|
+
PAYLOAD_TOO_LARGE: -32013,
|
|
3375
|
+
UNSUPPORTED_MEDIA_TYPE: -32015,
|
|
3376
|
+
UNPROCESSABLE_CONTENT: -32022,
|
|
3377
|
+
PRECONDITION_REQUIRED: -32028,
|
|
3378
|
+
TOO_MANY_REQUESTS: -32029,
|
|
3379
|
+
CLIENT_CLOSED_REQUEST: -32099
|
|
3380
|
+
};
|
|
3381
|
+
/**
|
|
3382
|
+
* tRPC error codes that are considered retryable
|
|
3383
|
+
* With out of the box SSE, the client will reconnect when these errors are encountered
|
|
3384
|
+
*/
|
|
3385
|
+
const retryableRpcCodes = [
|
|
3386
|
+
TRPC_ERROR_CODES_BY_KEY.BAD_GATEWAY,
|
|
3387
|
+
TRPC_ERROR_CODES_BY_KEY.SERVICE_UNAVAILABLE,
|
|
3388
|
+
TRPC_ERROR_CODES_BY_KEY.GATEWAY_TIMEOUT,
|
|
3389
|
+
TRPC_ERROR_CODES_BY_KEY.INTERNAL_SERVER_ERROR
|
|
3390
|
+
];
|
|
3391
|
+
|
|
3392
|
+
//#endregion
|
|
3393
|
+
//#region node_modules/@trpc/server/dist/getErrorShape-vC8mUXJD.mjs
|
|
3394
|
+
var __create = Object.create;
|
|
3395
|
+
var __defProp = Object.defineProperty;
|
|
3396
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3397
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
3398
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
3399
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
3400
|
+
var __commonJS = (cb, mod) => function() {
|
|
3401
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
3402
|
+
};
|
|
3403
|
+
var __copyProps = (to, from, except, desc) => {
|
|
3404
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
3405
|
+
key = keys[i];
|
|
3406
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
3407
|
+
get: ((k) => from[k]).bind(null, key),
|
|
3408
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
3409
|
+
});
|
|
3410
|
+
}
|
|
3411
|
+
return to;
|
|
3412
|
+
};
|
|
3413
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
3414
|
+
value: mod,
|
|
3415
|
+
enumerable: true
|
|
3416
|
+
}) : target, mod));
|
|
3417
|
+
const noop = () => {};
|
|
3418
|
+
const freezeIfAvailable = (obj) => {
|
|
3419
|
+
if (Object.freeze) Object.freeze(obj);
|
|
3420
|
+
};
|
|
3421
|
+
function createInnerProxy(callback, path, memo) {
|
|
3422
|
+
var _memo$cacheKey;
|
|
3423
|
+
const cacheKey = path.join(".");
|
|
3424
|
+
(_memo$cacheKey = memo[cacheKey]) !== null && _memo$cacheKey !== void 0 || (memo[cacheKey] = new Proxy(noop, {
|
|
3425
|
+
get(_obj, key) {
|
|
3426
|
+
if (typeof key !== "string" || key === "then") return void 0;
|
|
3427
|
+
return createInnerProxy(callback, [...path, key], memo);
|
|
3428
|
+
},
|
|
3429
|
+
apply(_1, _2, args) {
|
|
3430
|
+
const lastOfPath = path[path.length - 1];
|
|
3431
|
+
let opts = {
|
|
3432
|
+
args,
|
|
3433
|
+
path
|
|
3434
|
+
};
|
|
3435
|
+
if (lastOfPath === "call") opts = {
|
|
3436
|
+
args: args.length >= 2 ? [args[1]] : [],
|
|
3437
|
+
path: path.slice(0, -1)
|
|
3438
|
+
};
|
|
3439
|
+
else if (lastOfPath === "apply") opts = {
|
|
3440
|
+
args: args.length >= 2 ? args[1] : [],
|
|
3441
|
+
path: path.slice(0, -1)
|
|
3442
|
+
};
|
|
3443
|
+
freezeIfAvailable(opts.args);
|
|
3444
|
+
freezeIfAvailable(opts.path);
|
|
3445
|
+
return callback(opts);
|
|
3446
|
+
}
|
|
3447
|
+
}));
|
|
3448
|
+
return memo[cacheKey];
|
|
3449
|
+
}
|
|
3450
|
+
/**
|
|
3451
|
+
* Creates a proxy that calls the callback with the path and arguments
|
|
3452
|
+
*
|
|
3453
|
+
* @internal
|
|
3454
|
+
*/
|
|
3455
|
+
const createRecursiveProxy = (callback) => createInnerProxy(callback, [], emptyObject());
|
|
3456
|
+
/**
|
|
3457
|
+
* Used in place of `new Proxy` where each handler will map 1 level deep to another value.
|
|
3458
|
+
*
|
|
3459
|
+
* @internal
|
|
3460
|
+
*/
|
|
3461
|
+
const createFlatProxy = (callback) => {
|
|
3462
|
+
return new Proxy(noop, { get(_obj, name) {
|
|
3463
|
+
if (name === "then") return void 0;
|
|
3464
|
+
return callback(name);
|
|
3465
|
+
} });
|
|
3466
|
+
};
|
|
3467
|
+
var require_typeof = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/typeof.js"(exports, module) {
|
|
3468
|
+
function _typeof$2(o) {
|
|
3469
|
+
"@babel/helpers - typeof";
|
|
3470
|
+
return module.exports = _typeof$2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
|
|
3471
|
+
return typeof o$1;
|
|
3472
|
+
} : function(o$1) {
|
|
3473
|
+
return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
|
|
3474
|
+
}, module.exports.__esModule = true, module.exports["default"] = module.exports, _typeof$2(o);
|
|
3475
|
+
}
|
|
3476
|
+
module.exports = _typeof$2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3477
|
+
} });
|
|
3478
|
+
var require_toPrimitive = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPrimitive.js"(exports, module) {
|
|
3479
|
+
var _typeof$1 = require_typeof()["default"];
|
|
3480
|
+
function toPrimitive$1(t, r) {
|
|
3481
|
+
if ("object" != _typeof$1(t) || !t) return t;
|
|
3482
|
+
var e = t[Symbol.toPrimitive];
|
|
3483
|
+
if (void 0 !== e) {
|
|
3484
|
+
var i = e.call(t, r || "default");
|
|
3485
|
+
if ("object" != _typeof$1(i)) return i;
|
|
3486
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
3487
|
+
}
|
|
3488
|
+
return ("string" === r ? String : Number)(t);
|
|
3489
|
+
}
|
|
3490
|
+
module.exports = toPrimitive$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3491
|
+
} });
|
|
3492
|
+
var require_toPropertyKey = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/toPropertyKey.js"(exports, module) {
|
|
3493
|
+
var _typeof = require_typeof()["default"];
|
|
3494
|
+
var toPrimitive = require_toPrimitive();
|
|
3495
|
+
function toPropertyKey$1(t) {
|
|
3496
|
+
var i = toPrimitive(t, "string");
|
|
3497
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
3498
|
+
}
|
|
3499
|
+
module.exports = toPropertyKey$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3500
|
+
} });
|
|
3501
|
+
var require_defineProperty = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/defineProperty.js"(exports, module) {
|
|
3502
|
+
var toPropertyKey = require_toPropertyKey();
|
|
3503
|
+
function _defineProperty(e, r, t) {
|
|
3504
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
3505
|
+
value: t,
|
|
3506
|
+
enumerable: !0,
|
|
3507
|
+
configurable: !0,
|
|
3508
|
+
writable: !0
|
|
3509
|
+
}) : e[r] = t, e;
|
|
3510
|
+
}
|
|
3511
|
+
module.exports = _defineProperty, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3512
|
+
} });
|
|
3513
|
+
var require_objectSpread2 = __commonJS({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/objectSpread2.js"(exports, module) {
|
|
3514
|
+
var defineProperty = require_defineProperty();
|
|
3515
|
+
function ownKeys(e, r) {
|
|
3516
|
+
var t = Object.keys(e);
|
|
3517
|
+
if (Object.getOwnPropertySymbols) {
|
|
3518
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
3519
|
+
r && (o = o.filter(function(r$1) {
|
|
3520
|
+
return Object.getOwnPropertyDescriptor(e, r$1).enumerable;
|
|
3521
|
+
})), t.push.apply(t, o);
|
|
3522
|
+
}
|
|
3523
|
+
return t;
|
|
3524
|
+
}
|
|
3525
|
+
function _objectSpread2(e) {
|
|
3526
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
3527
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
3528
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function(r$1) {
|
|
3529
|
+
defineProperty(e, r$1, t[r$1]);
|
|
3530
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r$1) {
|
|
3531
|
+
Object.defineProperty(e, r$1, Object.getOwnPropertyDescriptor(t, r$1));
|
|
3532
|
+
});
|
|
3533
|
+
}
|
|
3534
|
+
return e;
|
|
3535
|
+
}
|
|
3536
|
+
module.exports = _objectSpread2, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
3537
|
+
} });
|
|
3538
|
+
var import_objectSpread2$11 = __toESM(require_objectSpread2(), 1);
|
|
3539
|
+
|
|
3540
|
+
//#endregion
|
|
3541
|
+
//#region node_modules/@trpc/server/dist/tracked-Bjtgv3wJ.mjs
|
|
3542
|
+
var import_defineProperty$6 = __toESM(require_defineProperty(), 1);
|
|
3543
|
+
var import_objectSpread2$1$11 = __toESM(require_objectSpread2(), 1);
|
|
3544
|
+
/** @internal */
|
|
3545
|
+
function transformResultInner(response, transformer) {
|
|
3546
|
+
if ("error" in response) {
|
|
3547
|
+
const error = transformer.deserialize(response.error);
|
|
3548
|
+
return {
|
|
3549
|
+
ok: false,
|
|
3550
|
+
error: (0, import_objectSpread2$1$11.default)((0, import_objectSpread2$1$11.default)({}, response), {}, { error })
|
|
3551
|
+
};
|
|
3552
|
+
}
|
|
3553
|
+
return {
|
|
3554
|
+
ok: true,
|
|
3555
|
+
result: (0, import_objectSpread2$1$11.default)((0, import_objectSpread2$1$11.default)({}, response.result), (!response.result.type || response.result.type === "data") && {
|
|
3556
|
+
type: "data",
|
|
3557
|
+
data: transformer.deserialize(response.result.data)
|
|
3558
|
+
})
|
|
3559
|
+
};
|
|
3560
|
+
}
|
|
3561
|
+
var TransformResultError = class extends Error {
|
|
3562
|
+
constructor() {
|
|
3563
|
+
super("Unable to transform response from server");
|
|
3564
|
+
}
|
|
3565
|
+
};
|
|
3566
|
+
/**
|
|
3567
|
+
* Transforms and validates that the result is a valid TRPCResponse
|
|
3568
|
+
* @internal
|
|
3569
|
+
*/
|
|
3570
|
+
function transformResult(response, transformer) {
|
|
3571
|
+
let result;
|
|
3572
|
+
try {
|
|
3573
|
+
result = transformResultInner(response, transformer);
|
|
3574
|
+
} catch (_unused) {
|
|
3575
|
+
throw new TransformResultError();
|
|
3576
|
+
}
|
|
3577
|
+
if (!result.ok && (!isObject(result.error.error) || typeof result.error.error["code"] !== "number")) throw new TransformResultError();
|
|
3578
|
+
if (result.ok && !isObject(result.result)) throw new TransformResultError();
|
|
3579
|
+
return result;
|
|
3580
|
+
}
|
|
3581
|
+
var import_objectSpread2$12 = __toESM(require_objectSpread2(), 1);
|
|
3582
|
+
|
|
3583
|
+
//#endregion
|
|
3584
|
+
//#region node_modules/@trpc/client/dist/TRPCClientError-apv8gw59.mjs
|
|
3585
|
+
var import_defineProperty$5 = __toESM$1(require_defineProperty$1(), 1);
|
|
3586
|
+
var import_objectSpread2$10 = __toESM$1(require_objectSpread2$1(), 1);
|
|
3587
|
+
function isTRPCClientError(cause) {
|
|
3588
|
+
return cause instanceof TRPCClientError;
|
|
3589
|
+
}
|
|
3590
|
+
function isTRPCErrorResponse(obj) {
|
|
3591
|
+
return isObject(obj) && isObject(obj["error"]) && typeof obj["error"]["code"] === "number" && typeof obj["error"]["message"] === "string";
|
|
3592
|
+
}
|
|
3593
|
+
function getMessageFromUnknownError(err, fallback) {
|
|
3594
|
+
if (typeof err === "string") return err;
|
|
3595
|
+
if (isObject(err) && typeof err["message"] === "string") return err["message"];
|
|
3596
|
+
return fallback;
|
|
3597
|
+
}
|
|
3598
|
+
var TRPCClientError = class TRPCClientError extends Error {
|
|
3599
|
+
constructor(message, opts) {
|
|
3600
|
+
var _opts$result, _opts$result2;
|
|
3601
|
+
const cause = opts === null || opts === void 0 ? void 0 : opts.cause;
|
|
3602
|
+
super(message, { cause });
|
|
3603
|
+
(0, import_defineProperty$5.default)(this, "cause", void 0);
|
|
3604
|
+
(0, import_defineProperty$5.default)(this, "shape", void 0);
|
|
3605
|
+
(0, import_defineProperty$5.default)(this, "data", void 0);
|
|
3606
|
+
(0, import_defineProperty$5.default)(this, "meta", void 0);
|
|
3607
|
+
this.meta = opts === null || opts === void 0 ? void 0 : opts.meta;
|
|
3608
|
+
this.cause = cause;
|
|
3609
|
+
this.shape = opts === null || opts === void 0 || (_opts$result = opts.result) === null || _opts$result === void 0 ? void 0 : _opts$result.error;
|
|
3610
|
+
this.data = opts === null || opts === void 0 || (_opts$result2 = opts.result) === null || _opts$result2 === void 0 ? void 0 : _opts$result2.error.data;
|
|
3611
|
+
this.name = "TRPCClientError";
|
|
3612
|
+
Object.setPrototypeOf(this, TRPCClientError.prototype);
|
|
3613
|
+
}
|
|
3614
|
+
static from(_cause, opts = {}) {
|
|
3615
|
+
const cause = _cause;
|
|
3616
|
+
if (isTRPCClientError(cause)) {
|
|
3617
|
+
if (opts.meta) cause.meta = (0, import_objectSpread2$10.default)((0, import_objectSpread2$10.default)({}, cause.meta), opts.meta);
|
|
3618
|
+
return cause;
|
|
3619
|
+
}
|
|
3620
|
+
if (isTRPCErrorResponse(cause)) return new TRPCClientError(cause.error.message, (0, import_objectSpread2$10.default)((0, import_objectSpread2$10.default)({}, opts), {}, {
|
|
3621
|
+
result: cause,
|
|
3622
|
+
cause: opts.cause
|
|
3623
|
+
}));
|
|
3624
|
+
return new TRPCClientError(getMessageFromUnknownError(cause, "Unknown error"), (0, import_objectSpread2$10.default)((0, import_objectSpread2$10.default)({}, opts), {}, { cause }));
|
|
3625
|
+
}
|
|
3626
|
+
};
|
|
3627
|
+
|
|
3628
|
+
//#endregion
|
|
3629
|
+
//#region node_modules/@trpc/client/dist/unstable-internals-Bg7n9BBj.mjs
|
|
3630
|
+
/**
|
|
3631
|
+
* @internal
|
|
3632
|
+
*/
|
|
3633
|
+
/**
|
|
3634
|
+
* @internal
|
|
3635
|
+
*/
|
|
3636
|
+
function getTransformer(transformer) {
|
|
3637
|
+
const _transformer = transformer;
|
|
3638
|
+
if (!_transformer) return {
|
|
3639
|
+
input: {
|
|
3640
|
+
serialize: (data) => data,
|
|
3641
|
+
deserialize: (data) => data
|
|
3642
|
+
},
|
|
3643
|
+
output: {
|
|
3644
|
+
serialize: (data) => data,
|
|
3645
|
+
deserialize: (data) => data
|
|
3646
|
+
}
|
|
3647
|
+
};
|
|
3648
|
+
if ("input" in _transformer) return _transformer;
|
|
3649
|
+
return {
|
|
3650
|
+
input: _transformer,
|
|
3651
|
+
output: _transformer
|
|
3652
|
+
};
|
|
3653
|
+
}
|
|
3654
|
+
|
|
3655
|
+
//#endregion
|
|
3656
|
+
//#region node_modules/@trpc/client/dist/httpUtils-Dv57hbOd.mjs
|
|
3657
|
+
const isFunction = (fn) => typeof fn === "function";
|
|
3658
|
+
function getFetch(customFetchImpl) {
|
|
3659
|
+
if (customFetchImpl) return customFetchImpl;
|
|
3660
|
+
if (typeof window !== "undefined" && isFunction(window.fetch)) return window.fetch;
|
|
3661
|
+
if (typeof globalThis !== "undefined" && isFunction(globalThis.fetch)) return globalThis.fetch;
|
|
3662
|
+
throw new Error("No fetch implementation found");
|
|
3663
|
+
}
|
|
3664
|
+
var import_objectSpread2$9 = __toESM$1(require_objectSpread2$1(), 1);
|
|
3665
|
+
function resolveHTTPLinkOptions(opts) {
|
|
3666
|
+
return {
|
|
3667
|
+
url: opts.url.toString(),
|
|
3668
|
+
fetch: opts.fetch,
|
|
3669
|
+
transformer: getTransformer(opts.transformer),
|
|
3670
|
+
methodOverride: opts.methodOverride
|
|
3671
|
+
};
|
|
3672
|
+
}
|
|
3673
|
+
function arrayToDict(array) {
|
|
3674
|
+
const dict = {};
|
|
3675
|
+
for (let index = 0; index < array.length; index++) dict[index] = array[index];
|
|
3676
|
+
return dict;
|
|
3677
|
+
}
|
|
3678
|
+
const METHOD = {
|
|
3679
|
+
query: "GET",
|
|
3680
|
+
mutation: "POST",
|
|
3681
|
+
subscription: "PATCH"
|
|
3682
|
+
};
|
|
3683
|
+
function getInput(opts) {
|
|
3684
|
+
return "input" in opts ? opts.transformer.input.serialize(opts.input) : arrayToDict(opts.inputs.map((_input) => opts.transformer.input.serialize(_input)));
|
|
3685
|
+
}
|
|
3686
|
+
const getUrl = (opts) => {
|
|
3687
|
+
const parts = opts.url.split("?");
|
|
3688
|
+
let url = parts[0].replace(/\/$/, "") + "/" + opts.path;
|
|
3689
|
+
const queryParts = [];
|
|
3690
|
+
if (parts[1]) queryParts.push(parts[1]);
|
|
3691
|
+
if ("inputs" in opts) queryParts.push("batch=1");
|
|
3692
|
+
if (opts.type === "query" || opts.type === "subscription") {
|
|
3693
|
+
const input = getInput(opts);
|
|
3694
|
+
if (input !== void 0 && opts.methodOverride !== "POST") queryParts.push(`input=${encodeURIComponent(JSON.stringify(input))}`);
|
|
3695
|
+
}
|
|
3696
|
+
if (queryParts.length) url += "?" + queryParts.join("&");
|
|
3697
|
+
return url;
|
|
3698
|
+
};
|
|
3699
|
+
const getBody = (opts) => {
|
|
3700
|
+
if (opts.type === "query" && opts.methodOverride !== "POST") return void 0;
|
|
3701
|
+
const input = getInput(opts);
|
|
3702
|
+
return input !== void 0 ? JSON.stringify(input) : void 0;
|
|
3703
|
+
};
|
|
3704
|
+
const jsonHttpRequester = (opts) => {
|
|
3705
|
+
return httpRequest((0, import_objectSpread2$9.default)((0, import_objectSpread2$9.default)({}, opts), {}, {
|
|
3706
|
+
contentTypeHeader: "application/json",
|
|
3707
|
+
getUrl,
|
|
3708
|
+
getBody
|
|
3709
|
+
}));
|
|
3710
|
+
};
|
|
3711
|
+
/**
|
|
3712
|
+
* Polyfill for DOMException with AbortError name
|
|
3713
|
+
*/
|
|
3714
|
+
var AbortError = class extends Error {
|
|
3715
|
+
constructor() {
|
|
3716
|
+
const name = "AbortError";
|
|
3717
|
+
super(name);
|
|
3718
|
+
this.name = name;
|
|
3719
|
+
this.message = name;
|
|
3720
|
+
}
|
|
3721
|
+
};
|
|
3722
|
+
/**
|
|
3723
|
+
* Polyfill for `signal.throwIfAborted()`
|
|
3724
|
+
*
|
|
3725
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/throwIfAborted
|
|
3726
|
+
*/
|
|
3727
|
+
const throwIfAborted = (signal) => {
|
|
3728
|
+
var _signal$throwIfAborte;
|
|
3729
|
+
if (!(signal === null || signal === void 0 ? void 0 : signal.aborted)) return;
|
|
3730
|
+
(_signal$throwIfAborte = signal.throwIfAborted) === null || _signal$throwIfAborte === void 0 || _signal$throwIfAborte.call(signal);
|
|
3731
|
+
if (typeof DOMException !== "undefined") throw new DOMException("AbortError", "AbortError");
|
|
3732
|
+
throw new AbortError();
|
|
3733
|
+
};
|
|
3734
|
+
async function fetchHTTPResponse(opts) {
|
|
3735
|
+
var _opts$methodOverride;
|
|
3736
|
+
throwIfAborted(opts.signal);
|
|
3737
|
+
const url = opts.getUrl(opts);
|
|
3738
|
+
const body = opts.getBody(opts);
|
|
3739
|
+
const method = (_opts$methodOverride = opts.methodOverride) !== null && _opts$methodOverride !== void 0 ? _opts$methodOverride : METHOD[opts.type];
|
|
3740
|
+
const resolvedHeaders = await (async () => {
|
|
3741
|
+
const heads = await opts.headers();
|
|
3742
|
+
if (Symbol.iterator in heads) return Object.fromEntries(heads);
|
|
3743
|
+
return heads;
|
|
3744
|
+
})();
|
|
3745
|
+
const headers = (0, import_objectSpread2$9.default)((0, import_objectSpread2$9.default)((0, import_objectSpread2$9.default)({}, opts.contentTypeHeader && method !== "GET" ? { "content-type": opts.contentTypeHeader } : {}), opts.trpcAcceptHeader ? { "trpc-accept": opts.trpcAcceptHeader } : void 0), resolvedHeaders);
|
|
3746
|
+
return getFetch(opts.fetch)(url, {
|
|
3747
|
+
method,
|
|
3748
|
+
signal: opts.signal,
|
|
3749
|
+
body,
|
|
3750
|
+
headers
|
|
3751
|
+
});
|
|
3752
|
+
}
|
|
3753
|
+
async function httpRequest(opts) {
|
|
3754
|
+
const meta = {};
|
|
3755
|
+
const res = await fetchHTTPResponse(opts);
|
|
3756
|
+
meta.response = res;
|
|
3757
|
+
const json = await res.json();
|
|
3758
|
+
meta.responseJSON = json;
|
|
3759
|
+
return {
|
|
3760
|
+
json,
|
|
3761
|
+
meta
|
|
3762
|
+
};
|
|
3763
|
+
}
|
|
3764
|
+
|
|
3765
|
+
//#endregion
|
|
3766
|
+
//#region node_modules/@trpc/client/dist/httpLink-Cz9h1Qgh.mjs
|
|
3767
|
+
function isOctetType(input) {
|
|
3768
|
+
return input instanceof Uint8Array || input instanceof Blob;
|
|
3769
|
+
}
|
|
3770
|
+
function isFormData(input) {
|
|
3771
|
+
return input instanceof FormData;
|
|
3772
|
+
}
|
|
3773
|
+
var import_objectSpread2$8 = __toESM$1(require_objectSpread2$1(), 1);
|
|
3774
|
+
const universalRequester = (opts) => {
|
|
3775
|
+
if ("input" in opts) {
|
|
3776
|
+
const { input } = opts;
|
|
3777
|
+
if (isFormData(input)) {
|
|
3778
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("FormData is only supported for mutations");
|
|
3779
|
+
return httpRequest((0, import_objectSpread2$8.default)((0, import_objectSpread2$8.default)({}, opts), {}, {
|
|
3780
|
+
contentTypeHeader: void 0,
|
|
3781
|
+
getUrl,
|
|
3782
|
+
getBody: () => input
|
|
3783
|
+
}));
|
|
3784
|
+
}
|
|
3785
|
+
if (isOctetType(input)) {
|
|
3786
|
+
if (opts.type !== "mutation" && opts.methodOverride !== "POST") throw new Error("Octet type input is only supported for mutations");
|
|
3787
|
+
return httpRequest((0, import_objectSpread2$8.default)((0, import_objectSpread2$8.default)({}, opts), {}, {
|
|
3788
|
+
contentTypeHeader: "application/octet-stream",
|
|
3789
|
+
getUrl,
|
|
3790
|
+
getBody: () => input
|
|
3791
|
+
}));
|
|
3792
|
+
}
|
|
3793
|
+
}
|
|
3794
|
+
return jsonHttpRequester(opts);
|
|
3795
|
+
};
|
|
3796
|
+
/**
|
|
3797
|
+
* @see https://trpc.io/docs/client/links/httpLink
|
|
3798
|
+
*/
|
|
3799
|
+
function httpLink(opts) {
|
|
3800
|
+
const resolvedOpts = resolveHTTPLinkOptions(opts);
|
|
3801
|
+
return () => {
|
|
3802
|
+
return (operationOpts) => {
|
|
3803
|
+
const { op } = operationOpts;
|
|
3804
|
+
return observable((observer) => {
|
|
3805
|
+
const { path, input, type } = op;
|
|
3806
|
+
/* istanbul ignore if -- @preserve */
|
|
3807
|
+
if (type === "subscription") throw new Error("Subscriptions are unsupported by `httpLink` - use `httpSubscriptionLink` or `wsLink`");
|
|
3808
|
+
const request = universalRequester((0, import_objectSpread2$8.default)((0, import_objectSpread2$8.default)({}, resolvedOpts), {}, {
|
|
3809
|
+
type,
|
|
3810
|
+
path,
|
|
3811
|
+
input,
|
|
3812
|
+
signal: op.signal,
|
|
3813
|
+
headers() {
|
|
3814
|
+
if (!opts.headers) return {};
|
|
3815
|
+
if (typeof opts.headers === "function") return opts.headers({ op });
|
|
3816
|
+
return opts.headers;
|
|
3817
|
+
}
|
|
3818
|
+
}));
|
|
3819
|
+
let meta = void 0;
|
|
3820
|
+
request.then((res) => {
|
|
3821
|
+
meta = res.meta;
|
|
3822
|
+
const transformed = transformResult(res.json, resolvedOpts.transformer.output);
|
|
3823
|
+
if (!transformed.ok) {
|
|
3824
|
+
observer.error(TRPCClientError.from(transformed.error, { meta }));
|
|
3825
|
+
return;
|
|
3826
|
+
}
|
|
3827
|
+
observer.next({
|
|
3828
|
+
context: res.meta,
|
|
3829
|
+
result: transformed.result
|
|
3830
|
+
});
|
|
3831
|
+
observer.complete();
|
|
3832
|
+
}).catch((cause) => {
|
|
3833
|
+
observer.error(TRPCClientError.from(cause, { meta }));
|
|
3834
|
+
});
|
|
3835
|
+
return () => {};
|
|
3836
|
+
});
|
|
3837
|
+
};
|
|
3838
|
+
};
|
|
3839
|
+
}
|
|
3840
|
+
|
|
3841
|
+
//#endregion
|
|
3842
|
+
//#region node_modules/@trpc/client/dist/httpBatchLink-fQ1NAi-e.mjs
|
|
3843
|
+
var import_objectSpread2$7 = __toESM$1(require_objectSpread2$1(), 1);
|
|
3844
|
+
|
|
3845
|
+
//#endregion
|
|
3846
|
+
//#region node_modules/@trpc/client/dist/loggerLink-ineCN1PO.mjs
|
|
3847
|
+
var import_objectSpread2$6 = __toESM$1(require_objectSpread2$1(), 1);
|
|
3848
|
+
|
|
3849
|
+
//#endregion
|
|
3850
|
+
//#region node_modules/@trpc/client/dist/wsLink-DSf4KOdW.mjs
|
|
3851
|
+
/**
|
|
3852
|
+
* Get the result of a value or function that returns a value
|
|
3853
|
+
* It also optionally accepts typesafe arguments for the function
|
|
3854
|
+
*/
|
|
3855
|
+
const resultOf = (value, ...args) => {
|
|
3856
|
+
return typeof value === "function" ? value(...args) : value;
|
|
3857
|
+
};
|
|
3858
|
+
var import_defineProperty$3 = __toESM$1(require_defineProperty$1(), 1);
|
|
3859
|
+
function withResolvers() {
|
|
3860
|
+
let resolve;
|
|
3861
|
+
let reject;
|
|
3862
|
+
return {
|
|
3863
|
+
promise: new Promise((res, rej) => {
|
|
3864
|
+
resolve = res;
|
|
3865
|
+
reject = rej;
|
|
3866
|
+
}),
|
|
3867
|
+
resolve,
|
|
3868
|
+
reject
|
|
3869
|
+
};
|
|
3870
|
+
}
|
|
3871
|
+
/**
|
|
3872
|
+
* Resolves a WebSocket URL and optionally appends connection parameters.
|
|
3873
|
+
*
|
|
3874
|
+
* If connectionParams are provided, appends 'connectionParams=1' query parameter.
|
|
3875
|
+
*/
|
|
3876
|
+
async function prepareUrl(urlOptions) {
|
|
3877
|
+
const url = await resultOf(urlOptions.url);
|
|
3878
|
+
if (!urlOptions.connectionParams) return url;
|
|
3879
|
+
return url + `${url.includes("?") ? "&" : "?"}connectionParams=1`;
|
|
3880
|
+
}
|
|
3881
|
+
async function buildConnectionMessage(connectionParams, encoder) {
|
|
3882
|
+
const message = {
|
|
3883
|
+
method: "connectionParams",
|
|
3884
|
+
data: await resultOf(connectionParams)
|
|
3885
|
+
};
|
|
3886
|
+
return encoder.encode(message);
|
|
3887
|
+
}
|
|
3888
|
+
var import_defineProperty$2 = __toESM$1(require_defineProperty$1(), 1);
|
|
3889
|
+
var import_defineProperty$1 = __toESM$1(require_defineProperty$1(), 1);
|
|
3890
|
+
/**
|
|
3891
|
+
* Opens a WebSocket connection asynchronously and returns a promise
|
|
3892
|
+
* that resolves when the connection is successfully established.
|
|
3893
|
+
* The promise rejects if an error occurs during the connection attempt.
|
|
3894
|
+
*/
|
|
3895
|
+
function asyncWsOpen(ws) {
|
|
3896
|
+
const { promise, resolve, reject } = withResolvers();
|
|
3897
|
+
ws.addEventListener("open", () => {
|
|
3898
|
+
ws.removeEventListener("error", reject);
|
|
3899
|
+
resolve();
|
|
3900
|
+
});
|
|
3901
|
+
ws.addEventListener("error", reject);
|
|
3902
|
+
return promise;
|
|
3903
|
+
}
|
|
3904
|
+
/**
|
|
3905
|
+
* Sets up a periodic ping-pong mechanism to keep the WebSocket connection alive.
|
|
3906
|
+
*
|
|
3907
|
+
* - Sends "PING" messages at regular intervals defined by `intervalMs`.
|
|
3908
|
+
* - If a "PONG" response is not received within the `pongTimeoutMs`, the WebSocket is closed.
|
|
3909
|
+
* - The ping timer resets upon receiving any message to maintain activity.
|
|
3910
|
+
* - Automatically starts the ping process when the WebSocket connection is opened.
|
|
3911
|
+
* - Cleans up timers when the WebSocket is closed.
|
|
3912
|
+
*
|
|
3913
|
+
* @param ws - The WebSocket instance to manage.
|
|
3914
|
+
* @param options - Configuration options for ping-pong intervals and timeouts.
|
|
3915
|
+
*/
|
|
3916
|
+
function setupPingInterval(ws, { intervalMs, pongTimeoutMs }) {
|
|
3917
|
+
let pingTimeout;
|
|
3918
|
+
let pongTimeout;
|
|
3919
|
+
function start() {
|
|
3920
|
+
pingTimeout = setTimeout(() => {
|
|
3921
|
+
ws.send("PING");
|
|
3922
|
+
pongTimeout = setTimeout(() => {
|
|
3923
|
+
ws.close();
|
|
3924
|
+
}, pongTimeoutMs);
|
|
3925
|
+
}, intervalMs);
|
|
3926
|
+
}
|
|
3927
|
+
function reset() {
|
|
3928
|
+
clearTimeout(pingTimeout);
|
|
3929
|
+
start();
|
|
3930
|
+
}
|
|
3931
|
+
function pong() {
|
|
3932
|
+
clearTimeout(pongTimeout);
|
|
3933
|
+
reset();
|
|
3934
|
+
}
|
|
3935
|
+
ws.addEventListener("open", start);
|
|
3936
|
+
ws.addEventListener("message", ({ data }) => {
|
|
3937
|
+
clearTimeout(pingTimeout);
|
|
3938
|
+
start();
|
|
3939
|
+
if (data === "PONG") pong();
|
|
3940
|
+
});
|
|
3941
|
+
ws.addEventListener("close", () => {
|
|
3942
|
+
clearTimeout(pingTimeout);
|
|
3943
|
+
clearTimeout(pongTimeout);
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3946
|
+
/**
|
|
3947
|
+
* Manages a WebSocket connection with support for reconnection, keep-alive mechanisms,
|
|
3948
|
+
* and observable state tracking.
|
|
3949
|
+
*/
|
|
3950
|
+
var WsConnection = class WsConnection {
|
|
3951
|
+
constructor(opts) {
|
|
3952
|
+
var _opts$WebSocketPonyfi;
|
|
3953
|
+
(0, import_defineProperty$1.default)(this, "id", ++WsConnection.connectCount);
|
|
3954
|
+
(0, import_defineProperty$1.default)(this, "WebSocketPonyfill", void 0);
|
|
3955
|
+
(0, import_defineProperty$1.default)(this, "urlOptions", void 0);
|
|
3956
|
+
(0, import_defineProperty$1.default)(this, "keepAliveOpts", void 0);
|
|
3957
|
+
(0, import_defineProperty$1.default)(this, "encoder", void 0);
|
|
3958
|
+
(0, import_defineProperty$1.default)(this, "wsObservable", behaviorSubject(null));
|
|
3959
|
+
(0, import_defineProperty$1.default)(this, "openPromise", null);
|
|
3960
|
+
this.WebSocketPonyfill = (_opts$WebSocketPonyfi = opts.WebSocketPonyfill) !== null && _opts$WebSocketPonyfi !== void 0 ? _opts$WebSocketPonyfi : WebSocket;
|
|
3961
|
+
if (!this.WebSocketPonyfill) throw new Error("No WebSocket implementation found - you probably don't want to use this on the server, but if you do you need to pass a `WebSocket`-ponyfill");
|
|
3962
|
+
this.urlOptions = opts.urlOptions;
|
|
3963
|
+
this.keepAliveOpts = opts.keepAlive;
|
|
3964
|
+
this.encoder = opts.encoder;
|
|
3965
|
+
}
|
|
3966
|
+
get ws() {
|
|
3967
|
+
return this.wsObservable.get();
|
|
3968
|
+
}
|
|
3969
|
+
set ws(ws) {
|
|
3970
|
+
this.wsObservable.next(ws);
|
|
3971
|
+
}
|
|
3972
|
+
/**
|
|
3973
|
+
* Checks if the WebSocket connection is open and ready to communicate.
|
|
3974
|
+
*/
|
|
3975
|
+
isOpen() {
|
|
3976
|
+
return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN && !this.openPromise;
|
|
3977
|
+
}
|
|
3978
|
+
/**
|
|
3979
|
+
* Checks if the WebSocket connection is closed or in the process of closing.
|
|
3980
|
+
*/
|
|
3981
|
+
isClosed() {
|
|
3982
|
+
return !!this.ws && (this.ws.readyState === this.WebSocketPonyfill.CLOSING || this.ws.readyState === this.WebSocketPonyfill.CLOSED);
|
|
3983
|
+
}
|
|
3984
|
+
async open() {
|
|
3985
|
+
var _this = this;
|
|
3986
|
+
if (_this.openPromise) return _this.openPromise;
|
|
3987
|
+
_this.id = ++WsConnection.connectCount;
|
|
3988
|
+
_this.openPromise = prepareUrl(_this.urlOptions).then((url) => new _this.WebSocketPonyfill(url)).then(async (ws) => {
|
|
3989
|
+
_this.ws = ws;
|
|
3990
|
+
ws.binaryType = "arraybuffer";
|
|
3991
|
+
ws.addEventListener("message", function({ data }) {
|
|
3992
|
+
if (data === "PING") this.send("PONG");
|
|
3993
|
+
});
|
|
3994
|
+
if (_this.keepAliveOpts.enabled) setupPingInterval(ws, _this.keepAliveOpts);
|
|
3995
|
+
ws.addEventListener("close", () => {
|
|
3996
|
+
if (_this.ws === ws) _this.ws = null;
|
|
3997
|
+
});
|
|
3998
|
+
await asyncWsOpen(ws);
|
|
3999
|
+
if (_this.urlOptions.connectionParams) ws.send(await buildConnectionMessage(_this.urlOptions.connectionParams, _this.encoder));
|
|
4000
|
+
});
|
|
4001
|
+
try {
|
|
4002
|
+
await _this.openPromise;
|
|
4003
|
+
} finally {
|
|
4004
|
+
_this.openPromise = null;
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
/**
|
|
4008
|
+
* Closes the WebSocket connection gracefully.
|
|
4009
|
+
* Waits for any ongoing open operation to complete before closing.
|
|
4010
|
+
*/
|
|
4011
|
+
async close() {
|
|
4012
|
+
var _this2 = this;
|
|
4013
|
+
try {
|
|
4014
|
+
await _this2.openPromise;
|
|
4015
|
+
} finally {
|
|
4016
|
+
var _this$ws;
|
|
4017
|
+
(_this$ws = _this2.ws) === null || _this$ws === void 0 || _this$ws.close();
|
|
4018
|
+
}
|
|
4019
|
+
}
|
|
4020
|
+
};
|
|
4021
|
+
(0, import_defineProperty$1.default)(WsConnection, "connectCount", 0);
|
|
4022
|
+
var import_defineProperty$4 = __toESM$1(require_defineProperty$1(), 1);
|
|
4023
|
+
var import_objectSpread2$5 = __toESM$1(require_objectSpread2$1(), 1);
|
|
4024
|
+
|
|
4025
|
+
//#endregion
|
|
4026
|
+
//#region node_modules/@trpc/client/dist/index.mjs
|
|
4027
|
+
var import_defineProperty = __toESM$1(require_defineProperty$1(), 1);
|
|
4028
|
+
var import_objectSpread2$4 = __toESM$1(require_objectSpread2$1(), 1);
|
|
4029
|
+
var TRPCUntypedClient = class {
|
|
4030
|
+
constructor(opts) {
|
|
4031
|
+
(0, import_defineProperty.default)(this, "links", void 0);
|
|
4032
|
+
(0, import_defineProperty.default)(this, "runtime", void 0);
|
|
4033
|
+
(0, import_defineProperty.default)(this, "requestId", void 0);
|
|
4034
|
+
this.requestId = 0;
|
|
4035
|
+
this.runtime = {};
|
|
4036
|
+
this.links = opts.links.map((link) => link(this.runtime));
|
|
4037
|
+
}
|
|
4038
|
+
$request(opts) {
|
|
4039
|
+
var _opts$context;
|
|
4040
|
+
return createChain({
|
|
4041
|
+
links: this.links,
|
|
4042
|
+
op: (0, import_objectSpread2$4.default)((0, import_objectSpread2$4.default)({}, opts), {}, {
|
|
4043
|
+
context: (_opts$context = opts.context) !== null && _opts$context !== void 0 ? _opts$context : {},
|
|
4044
|
+
id: ++this.requestId
|
|
4045
|
+
})
|
|
4046
|
+
}).pipe(share());
|
|
4047
|
+
}
|
|
4048
|
+
async requestAsPromise(opts) {
|
|
4049
|
+
var _this = this;
|
|
4050
|
+
try {
|
|
4051
|
+
return (await observableToPromise(_this.$request(opts))).result.data;
|
|
4052
|
+
} catch (err) {
|
|
4053
|
+
throw TRPCClientError.from(err);
|
|
4054
|
+
}
|
|
4055
|
+
}
|
|
4056
|
+
query(path, input, opts) {
|
|
4057
|
+
return this.requestAsPromise({
|
|
4058
|
+
type: "query",
|
|
4059
|
+
path,
|
|
4060
|
+
input,
|
|
4061
|
+
context: opts === null || opts === void 0 ? void 0 : opts.context,
|
|
4062
|
+
signal: opts === null || opts === void 0 ? void 0 : opts.signal
|
|
4063
|
+
});
|
|
4064
|
+
}
|
|
4065
|
+
mutation(path, input, opts) {
|
|
4066
|
+
return this.requestAsPromise({
|
|
4067
|
+
type: "mutation",
|
|
4068
|
+
path,
|
|
4069
|
+
input,
|
|
4070
|
+
context: opts === null || opts === void 0 ? void 0 : opts.context,
|
|
4071
|
+
signal: opts === null || opts === void 0 ? void 0 : opts.signal
|
|
4072
|
+
});
|
|
4073
|
+
}
|
|
4074
|
+
subscription(path, input, opts) {
|
|
4075
|
+
return this.$request({
|
|
4076
|
+
type: "subscription",
|
|
4077
|
+
path,
|
|
4078
|
+
input,
|
|
4079
|
+
context: opts.context,
|
|
4080
|
+
signal: opts.signal
|
|
4081
|
+
}).subscribe({
|
|
4082
|
+
next(envelope) {
|
|
4083
|
+
switch (envelope.result.type) {
|
|
4084
|
+
case "state":
|
|
4085
|
+
var _opts$onConnectionSta;
|
|
4086
|
+
(_opts$onConnectionSta = opts.onConnectionStateChange) === null || _opts$onConnectionSta === void 0 || _opts$onConnectionSta.call(opts, envelope.result);
|
|
4087
|
+
break;
|
|
4088
|
+
case "started":
|
|
4089
|
+
var _opts$onStarted;
|
|
4090
|
+
(_opts$onStarted = opts.onStarted) === null || _opts$onStarted === void 0 || _opts$onStarted.call(opts, { context: envelope.context });
|
|
4091
|
+
break;
|
|
4092
|
+
case "stopped":
|
|
4093
|
+
var _opts$onStopped;
|
|
4094
|
+
(_opts$onStopped = opts.onStopped) === null || _opts$onStopped === void 0 || _opts$onStopped.call(opts);
|
|
4095
|
+
break;
|
|
4096
|
+
case "data":
|
|
4097
|
+
case void 0:
|
|
4098
|
+
var _opts$onData;
|
|
4099
|
+
(_opts$onData = opts.onData) === null || _opts$onData === void 0 || _opts$onData.call(opts, envelope.result.data);
|
|
4100
|
+
break;
|
|
4101
|
+
}
|
|
4102
|
+
},
|
|
4103
|
+
error(err) {
|
|
4104
|
+
var _opts$onError;
|
|
4105
|
+
(_opts$onError = opts.onError) === null || _opts$onError === void 0 || _opts$onError.call(opts, err);
|
|
4106
|
+
},
|
|
4107
|
+
complete() {
|
|
4108
|
+
var _opts$onComplete;
|
|
4109
|
+
(_opts$onComplete = opts.onComplete) === null || _opts$onComplete === void 0 || _opts$onComplete.call(opts);
|
|
4110
|
+
}
|
|
4111
|
+
});
|
|
4112
|
+
}
|
|
4113
|
+
};
|
|
4114
|
+
const untypedClientSymbol = Symbol.for("trpc_untypedClient");
|
|
4115
|
+
const clientCallTypeMap = {
|
|
4116
|
+
query: "query",
|
|
4117
|
+
mutate: "mutation",
|
|
4118
|
+
subscribe: "subscription"
|
|
4119
|
+
};
|
|
4120
|
+
/** @internal */
|
|
4121
|
+
const clientCallTypeToProcedureType = (clientCallType) => {
|
|
4122
|
+
return clientCallTypeMap[clientCallType];
|
|
4123
|
+
};
|
|
4124
|
+
/**
|
|
4125
|
+
* @internal
|
|
4126
|
+
*/
|
|
4127
|
+
function createTRPCClientProxy(client) {
|
|
4128
|
+
const proxy = createRecursiveProxy(({ path, args }) => {
|
|
4129
|
+
const pathCopy = [...path];
|
|
4130
|
+
const procedureType = clientCallTypeToProcedureType(pathCopy.pop());
|
|
4131
|
+
const fullPath = pathCopy.join(".");
|
|
4132
|
+
return client[procedureType](fullPath, ...args);
|
|
4133
|
+
});
|
|
4134
|
+
return createFlatProxy((key) => {
|
|
4135
|
+
if (key === untypedClientSymbol) return client;
|
|
4136
|
+
return proxy[key];
|
|
4137
|
+
});
|
|
4138
|
+
}
|
|
4139
|
+
function createTRPCClient(opts) {
|
|
4140
|
+
return createTRPCClientProxy(new TRPCUntypedClient(opts));
|
|
4141
|
+
}
|
|
4142
|
+
var import_objectSpread2$3 = __toESM$1(require_objectSpread2$1(), 1);
|
|
4143
|
+
var import_objectSpread2$2 = __toESM$1(require_objectSpread2$1(), 1);
|
|
4144
|
+
var import_asyncIterator = __toESM$1(__commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/asyncIterator.js"(exports, module) {
|
|
4145
|
+
function _asyncIterator$1(r) {
|
|
4146
|
+
var n, t, o, e = 2;
|
|
4147
|
+
for ("undefined" != typeof Symbol && (t = Symbol.asyncIterator, o = Symbol.iterator); e--;) {
|
|
4148
|
+
if (t && null != (n = r[t])) return n.call(r);
|
|
4149
|
+
if (o && null != (n = r[o])) return new AsyncFromSyncIterator(n.call(r));
|
|
4150
|
+
t = "@@asyncIterator", o = "@@iterator";
|
|
4151
|
+
}
|
|
4152
|
+
throw new TypeError("Object is not async iterable");
|
|
4153
|
+
}
|
|
4154
|
+
function AsyncFromSyncIterator(r) {
|
|
4155
|
+
function AsyncFromSyncIteratorContinuation(r$1) {
|
|
4156
|
+
if (Object(r$1) !== r$1) return Promise.reject(/* @__PURE__ */ new TypeError(r$1 + " is not an object."));
|
|
4157
|
+
var n = r$1.done;
|
|
4158
|
+
return Promise.resolve(r$1.value).then(function(r$2) {
|
|
4159
|
+
return {
|
|
4160
|
+
value: r$2,
|
|
4161
|
+
done: n
|
|
4162
|
+
};
|
|
4163
|
+
});
|
|
4164
|
+
}
|
|
4165
|
+
return AsyncFromSyncIterator = function AsyncFromSyncIterator$1(r$1) {
|
|
4166
|
+
this.s = r$1, this.n = r$1.next;
|
|
4167
|
+
}, AsyncFromSyncIterator.prototype = {
|
|
4168
|
+
s: null,
|
|
4169
|
+
n: null,
|
|
4170
|
+
next: function next() {
|
|
4171
|
+
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
4172
|
+
},
|
|
4173
|
+
"return": function _return(r$1) {
|
|
4174
|
+
var n = this.s["return"];
|
|
4175
|
+
return void 0 === n ? Promise.resolve({
|
|
4176
|
+
value: r$1,
|
|
4177
|
+
done: !0
|
|
4178
|
+
}) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
4179
|
+
},
|
|
4180
|
+
"throw": function _throw(r$1) {
|
|
4181
|
+
var n = this.s["return"];
|
|
4182
|
+
return void 0 === n ? Promise.reject(r$1) : AsyncFromSyncIteratorContinuation(n.apply(this.s, arguments));
|
|
4183
|
+
}
|
|
4184
|
+
}, new AsyncFromSyncIterator(r);
|
|
4185
|
+
}
|
|
4186
|
+
module.exports = _asyncIterator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
4187
|
+
} })(), 1);
|
|
4188
|
+
var import_objectSpread2$1 = __toESM$1(require_objectSpread2$1(), 1);
|
|
4189
|
+
var require_usingCtx = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js"(exports, module) {
|
|
4190
|
+
function _usingCtx() {
|
|
4191
|
+
var r = "function" == typeof SuppressedError ? SuppressedError : function(r$1, e$1) {
|
|
4192
|
+
var n$1 = Error();
|
|
4193
|
+
return n$1.name = "SuppressedError", n$1.error = r$1, n$1.suppressed = e$1, n$1;
|
|
4194
|
+
}, e = {}, n = [];
|
|
4195
|
+
function using(r$1, e$1) {
|
|
4196
|
+
if (null != e$1) {
|
|
4197
|
+
if (Object(e$1) !== e$1) throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
|
|
4198
|
+
if (r$1) var o = e$1[Symbol.asyncDispose || Symbol["for"]("Symbol.asyncDispose")];
|
|
4199
|
+
if (void 0 === o && (o = e$1[Symbol.dispose || Symbol["for"]("Symbol.dispose")], r$1)) var t = o;
|
|
4200
|
+
if ("function" != typeof o) throw new TypeError("Object is not disposable.");
|
|
4201
|
+
t && (o = function o$1() {
|
|
4202
|
+
try {
|
|
4203
|
+
t.call(e$1);
|
|
4204
|
+
} catch (r$2) {
|
|
4205
|
+
return Promise.reject(r$2);
|
|
4206
|
+
}
|
|
4207
|
+
}), n.push({
|
|
4208
|
+
v: e$1,
|
|
4209
|
+
d: o,
|
|
4210
|
+
a: r$1
|
|
4211
|
+
});
|
|
4212
|
+
} else r$1 && n.push({
|
|
4213
|
+
d: e$1,
|
|
4214
|
+
a: r$1
|
|
4215
|
+
});
|
|
4216
|
+
return e$1;
|
|
4217
|
+
}
|
|
4218
|
+
return {
|
|
4219
|
+
e,
|
|
4220
|
+
u: using.bind(null, !1),
|
|
4221
|
+
a: using.bind(null, !0),
|
|
4222
|
+
d: function d() {
|
|
4223
|
+
var o, t = this.e, s = 0;
|
|
4224
|
+
function next() {
|
|
4225
|
+
for (; o = n.pop();) try {
|
|
4226
|
+
if (!o.a && 1 === s) return s = 0, n.push(o), Promise.resolve().then(next);
|
|
4227
|
+
if (o.d) {
|
|
4228
|
+
var r$1 = o.d.call(o.v);
|
|
4229
|
+
if (o.a) return s |= 2, Promise.resolve(r$1).then(next, err);
|
|
4230
|
+
} else s |= 1;
|
|
4231
|
+
} catch (r$2) {
|
|
4232
|
+
return err(r$2);
|
|
4233
|
+
}
|
|
4234
|
+
if (1 === s) return t !== e ? Promise.reject(t) : Promise.resolve();
|
|
4235
|
+
if (t !== e) throw t;
|
|
4236
|
+
}
|
|
4237
|
+
function err(n$1) {
|
|
4238
|
+
return t = t !== e ? new r(n$1, t) : n$1, next();
|
|
4239
|
+
}
|
|
4240
|
+
return next();
|
|
4241
|
+
}
|
|
4242
|
+
};
|
|
4243
|
+
}
|
|
4244
|
+
module.exports = _usingCtx, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
4245
|
+
} });
|
|
4246
|
+
var require_OverloadYield = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/OverloadYield.js"(exports, module) {
|
|
4247
|
+
function _OverloadYield(e, d) {
|
|
4248
|
+
this.v = e, this.k = d;
|
|
4249
|
+
}
|
|
4250
|
+
module.exports = _OverloadYield, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
4251
|
+
} });
|
|
4252
|
+
var require_awaitAsyncGenerator = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/awaitAsyncGenerator.js"(exports, module) {
|
|
4253
|
+
var OverloadYield$1 = require_OverloadYield();
|
|
4254
|
+
function _awaitAsyncGenerator$1(e) {
|
|
4255
|
+
return new OverloadYield$1(e, 0);
|
|
4256
|
+
}
|
|
4257
|
+
module.exports = _awaitAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
4258
|
+
} });
|
|
4259
|
+
var require_wrapAsyncGenerator = __commonJS$1({ "../../node_modules/.pnpm/@oxc-project+runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/wrapAsyncGenerator.js"(exports, module) {
|
|
4260
|
+
var OverloadYield = require_OverloadYield();
|
|
4261
|
+
function _wrapAsyncGenerator$1(e) {
|
|
4262
|
+
return function() {
|
|
4263
|
+
return new AsyncGenerator(e.apply(this, arguments));
|
|
4264
|
+
};
|
|
4265
|
+
}
|
|
4266
|
+
function AsyncGenerator(e) {
|
|
4267
|
+
var r, t;
|
|
4268
|
+
function resume(r$1, t$1) {
|
|
4269
|
+
try {
|
|
4270
|
+
var n = e[r$1](t$1), o = n.value, u = o instanceof OverloadYield;
|
|
4271
|
+
Promise.resolve(u ? o.v : o).then(function(t$2) {
|
|
4272
|
+
if (u) {
|
|
4273
|
+
var i = "return" === r$1 ? "return" : "next";
|
|
4274
|
+
if (!o.k || t$2.done) return resume(i, t$2);
|
|
4275
|
+
t$2 = e[i](t$2).value;
|
|
4276
|
+
}
|
|
4277
|
+
settle(n.done ? "return" : "normal", t$2);
|
|
4278
|
+
}, function(e$1) {
|
|
4279
|
+
resume("throw", e$1);
|
|
4280
|
+
});
|
|
4281
|
+
} catch (e$1) {
|
|
4282
|
+
settle("throw", e$1);
|
|
4283
|
+
}
|
|
4284
|
+
}
|
|
4285
|
+
function settle(e$1, n) {
|
|
4286
|
+
switch (e$1) {
|
|
4287
|
+
case "return":
|
|
4288
|
+
r.resolve({
|
|
4289
|
+
value: n,
|
|
4290
|
+
done: !0
|
|
4291
|
+
});
|
|
4292
|
+
break;
|
|
4293
|
+
case "throw":
|
|
4294
|
+
r.reject(n);
|
|
4295
|
+
break;
|
|
4296
|
+
default: r.resolve({
|
|
4297
|
+
value: n,
|
|
4298
|
+
done: !1
|
|
4299
|
+
});
|
|
4300
|
+
}
|
|
4301
|
+
(r = r.next) ? resume(r.key, r.arg) : t = null;
|
|
4302
|
+
}
|
|
4303
|
+
this._invoke = function(e$1, n) {
|
|
4304
|
+
return new Promise(function(o, u) {
|
|
4305
|
+
var i = {
|
|
4306
|
+
key: e$1,
|
|
4307
|
+
arg: n,
|
|
4308
|
+
resolve: o,
|
|
4309
|
+
reject: u,
|
|
4310
|
+
next: null
|
|
4311
|
+
};
|
|
4312
|
+
t ? t = t.next = i : (r = t = i, resume(e$1, n));
|
|
4313
|
+
});
|
|
4314
|
+
}, "function" != typeof e["return"] && (this["return"] = void 0);
|
|
4315
|
+
}
|
|
4316
|
+
AsyncGenerator.prototype["function" == typeof Symbol && Symbol.asyncIterator || "@@asyncIterator"] = function() {
|
|
4317
|
+
return this;
|
|
4318
|
+
}, AsyncGenerator.prototype.next = function(e) {
|
|
4319
|
+
return this._invoke("next", e);
|
|
4320
|
+
}, AsyncGenerator.prototype["throw"] = function(e) {
|
|
4321
|
+
return this._invoke("throw", e);
|
|
4322
|
+
}, AsyncGenerator.prototype["return"] = function(e) {
|
|
4323
|
+
return this._invoke("return", e);
|
|
4324
|
+
};
|
|
4325
|
+
module.exports = _wrapAsyncGenerator$1, module.exports.__esModule = true, module.exports["default"] = module.exports;
|
|
4326
|
+
} });
|
|
4327
|
+
var import_usingCtx = __toESM$1(require_usingCtx(), 1);
|
|
4328
|
+
var import_awaitAsyncGenerator = __toESM$1(require_awaitAsyncGenerator(), 1);
|
|
4329
|
+
var import_wrapAsyncGenerator = __toESM$1(require_wrapAsyncGenerator(), 1);
|
|
4330
|
+
var import_objectSpread2 = __toESM$1(require_objectSpread2$1(), 1);
|
|
4331
|
+
|
|
4332
|
+
//#endregion
|
|
4333
|
+
//#region src/cli/lite.ts
|
|
4334
|
+
/**
|
|
4335
|
+
* clawmini-lite - A standalone client
|
|
4336
|
+
*/
|
|
4337
|
+
const API_URL = process.env.CLAW_API_URL;
|
|
4338
|
+
const API_TOKEN = process.env.CLAW_API_TOKEN;
|
|
4339
|
+
function getClient() {
|
|
4340
|
+
return createTRPCClient({ links: [httpLink({
|
|
4341
|
+
url: API_URL,
|
|
4342
|
+
headers() {
|
|
4343
|
+
return {
|
|
4344
|
+
Authorization: `Bearer ${API_TOKEN}`,
|
|
4345
|
+
"Content-Type": "application/json"
|
|
4346
|
+
};
|
|
4347
|
+
}
|
|
4348
|
+
})] });
|
|
4349
|
+
}
|
|
4350
|
+
const program = new Command();
|
|
4351
|
+
program.name("clawmini-lite").description("A standalone client for clawmini").hook("preAction", () => {
|
|
4352
|
+
if (!API_URL || !API_TOKEN) {
|
|
4353
|
+
console.error("CLAW_API_URL and CLAW_API_TOKEN must be set in the environment.");
|
|
4354
|
+
process.exit(1);
|
|
4355
|
+
}
|
|
4356
|
+
});
|
|
4357
|
+
program.command("log [message]").description("Log a message").option("-f, --file <path>", "File path(s) to attach (can specify multiple)", (val, prev) => prev.concat([val]), []).action(async (message, options) => {
|
|
4358
|
+
try {
|
|
4359
|
+
const files = options.file.length > 0 ? options.file : void 0;
|
|
4360
|
+
const payload = {};
|
|
4361
|
+
if (message !== void 0) payload.message = message;
|
|
4362
|
+
if (files !== void 0) payload.files = files;
|
|
4363
|
+
await getClient().logMessage.mutate(payload);
|
|
4364
|
+
console.log("Log message appended.");
|
|
4365
|
+
} catch (err) {
|
|
4366
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
4367
|
+
process.exit(1);
|
|
4368
|
+
}
|
|
4369
|
+
});
|
|
4370
|
+
const jobs = program.command("jobs").description("Manage cron jobs");
|
|
4371
|
+
jobs.command("list").description("List cron jobs").action(async () => {
|
|
4372
|
+
try {
|
|
4373
|
+
const jobsList = await getClient().listCronJobs.query({});
|
|
4374
|
+
console.log(JSON.stringify(jobsList, null, 2));
|
|
4375
|
+
} catch (err) {
|
|
4376
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
4377
|
+
process.exit(1);
|
|
4378
|
+
}
|
|
4379
|
+
});
|
|
4380
|
+
jobs.command("add <name>").description("Add a cron job").option("--at <time>", "Schedule at specific time").option("--every <interval>", "Schedule at interval").option("--cron <cron>", "Schedule via cron expression").option("-m, --message <msg>", "Message to send").option("-r, --reply <reply>", "Reply text").option("-a, --agent <agentId>", "Agent ID").option("-s, --session <type>", "Session type (must be \"new\")").option("-e, --env <env>", "Environment variables in key=value format", (val, prev) => prev.concat([val]), []).option("-c, --chat <chatId>", "Chat ID").action(async (name, options) => {
|
|
4381
|
+
try {
|
|
4382
|
+
let schedule;
|
|
4383
|
+
if (options.at) schedule = { at: options.at };
|
|
4384
|
+
else if (options.every) schedule = { every: options.every };
|
|
4385
|
+
else if (options.cron) schedule = { cron: options.cron };
|
|
4386
|
+
else throw new Error("A schedule must be specified (--at, --every, or --cron).");
|
|
4387
|
+
const job = {
|
|
4388
|
+
id: name,
|
|
4389
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4390
|
+
message: options.message || "",
|
|
4391
|
+
schedule
|
|
4392
|
+
};
|
|
4393
|
+
if (options.reply) job.reply = options.reply;
|
|
4394
|
+
if (options.agent) job.agentId = options.agent;
|
|
4395
|
+
if (options.session) {
|
|
4396
|
+
if (options.session !== "new") throw new Error("Only \"new\" session type is supported.");
|
|
4397
|
+
job.session = { type: "new" };
|
|
4398
|
+
}
|
|
4399
|
+
if (options.env && options.env.length > 0) {
|
|
4400
|
+
const jobEnv = {};
|
|
4401
|
+
for (const e of options.env) {
|
|
4402
|
+
const [k, ...v] = e.split("=");
|
|
4403
|
+
if (k) jobEnv[k] = v.join("=");
|
|
4404
|
+
}
|
|
4405
|
+
job.env = jobEnv;
|
|
4406
|
+
}
|
|
4407
|
+
await getClient().addCronJob.mutate({
|
|
4408
|
+
chatId: options.chat,
|
|
4409
|
+
job
|
|
4410
|
+
});
|
|
4411
|
+
console.log(`Job '${name}' created successfully.`);
|
|
4412
|
+
} catch (err) {
|
|
4413
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
4414
|
+
process.exit(1);
|
|
4415
|
+
}
|
|
4416
|
+
});
|
|
4417
|
+
jobs.command("delete <name>").description("Delete a cron job").option("-c, --chat <chatId>", "Chat ID").action(async (name, options) => {
|
|
4418
|
+
try {
|
|
4419
|
+
const result = await getClient().deleteCronJob.mutate({
|
|
4420
|
+
chatId: options.chat,
|
|
4421
|
+
id: name
|
|
4422
|
+
});
|
|
4423
|
+
if (result && result.deleted) console.log(`Job '${name}' deleted successfully.`);
|
|
4424
|
+
else console.log(`Job '${name}' not found.`);
|
|
4425
|
+
} catch (err) {
|
|
4426
|
+
console.error("Error:", err instanceof Error ? err.message : err);
|
|
4427
|
+
process.exit(1);
|
|
4428
|
+
}
|
|
4429
|
+
});
|
|
4430
|
+
program.parse(process.argv);
|
|
4431
|
+
|
|
4432
|
+
//#endregion
|
|
4433
|
+
export { };
|
|
4434
|
+
//# sourceMappingURL=lite.mjs.map
|