@senators/bifrost-cli 0.0.0-stage → 7.0.0
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/LICENSE +21 -0
- package/README.md +180 -2
- package/out/accountEditor-CQB91PVf.js +2 -0
- package/out/accountEditor-CQB91PVf.js.map +1 -0
- package/out/achievements-Df5qqpYQ.js +2 -0
- package/out/achievements-Df5qqpYQ.js.map +1 -0
- package/out/active-CnUKpiEo.js +2 -0
- package/out/active-CnUKpiEo.js.map +1 -0
- package/out/alliance-BsPnhi7w.js +2 -0
- package/out/alliance-BsPnhi7w.js.map +1 -0
- package/out/allianceAdmin-Bkyl6ev4.js +2 -0
- package/out/allianceAdmin-Bkyl6ev4.js.map +1 -0
- package/out/arsenal-BMCmAHzv.js +2 -0
- package/out/arsenal-BMCmAHzv.js.map +1 -0
- package/out/ban-BXNvHPMq.js +2 -0
- package/out/ban-BXNvHPMq.js.map +1 -0
- package/out/banList-3DbCToEy.js +2 -0
- package/out/banList-3DbCToEy.js.map +1 -0
- package/out/banList-dT5GF5eO.js +2 -0
- package/out/banList-dT5GF5eO.js.map +1 -0
- package/out/battleHall-C4BALP6S.js +2 -0
- package/out/battleHall-C4BALP6S.js.map +1 -0
- package/out/battleHall-P7Co1jS5.js +2 -0
- package/out/battleHall-P7Co1jS5.js.map +1 -0
- package/out/battleReport-BG0-S-bF.js +2 -0
- package/out/battleReport-BG0-S-bF.js.map +1 -0
- package/out/battleReport-C3PQTXxc.js +2 -0
- package/out/battleReport-C3PQTXxc.js.map +1 -0
- package/out/battleSimulator-BOySErLn.js +2 -0
- package/out/battleSimulator-BOySErLn.js.map +1 -0
- package/out/board-CsNgDx4j.js +2 -0
- package/out/board-CsNgDx4j.js.map +1 -0
- package/out/board-DSCl8eU8.js +2 -0
- package/out/board-DSCl8eU8.js.map +1 -0
- package/out/bonusSummary-Dmm646zj.js +2 -0
- package/out/bonusSummary-Dmm646zj.js.map +1 -0
- package/out/buddyList-B50t-9_g.js +2 -0
- package/out/buddyList-B50t-9_g.js.map +1 -0
- package/out/buildings-CXrMgFyb.js +2 -0
- package/out/buildings-CXrMgFyb.js.map +1 -0
- package/out/catalog-DmSXp_YG.js +2 -0
- package/out/catalog-DmSXp_YG.js.map +1 -0
- package/out/chat-BvtMl-I7.js +2 -0
- package/out/chat-BvtMl-I7.js.map +1 -0
- package/out/clearCache-79cjREI0.js +2 -0
- package/out/clearCache-79cjREI0.js.map +1 -0
- package/out/cli.js +3 -0
- package/out/cli.js.map +1 -0
- package/out/containers-BhguCCkz.js +2 -0
- package/out/containers-BhguCCkz.js.map +1 -0
- package/out/control-IJRy1LDx.js +2 -0
- package/out/control-IJRy1LDx.js.map +1 -0
- package/out/create-D-IygCER.js +2 -0
- package/out/create-D-IygCER.js.map +1 -0
- package/out/createMoon-BMWjdwO0.js +2 -0
- package/out/createMoon-BMWjdwO0.js.map +1 -0
- package/out/cronjob-CCJKDSuv.js +2 -0
- package/out/cronjob-CCJKDSuv.js.map +1 -0
- package/out/dailyBonus-2UwWD4D0.js +2 -0
- package/out/dailyBonus-2UwWD4D0.js.map +1 -0
- package/out/delivery-d8NKP-f1.js +2 -0
- package/out/delivery-d8NKP-f1.js.map +1 -0
- package/out/disclaimer-BmejHZqk.js +2 -0
- package/out/disclaimer-BmejHZqk.js.map +1 -0
- package/out/dump--mJa5m3e.js +2 -0
- package/out/dump--mJa5m3e.js.map +1 -0
- package/out/endpoints-CbZGTbF-.js +2 -0
- package/out/endpoints-CbZGTbF-.js.map +1 -0
- package/out/externalAuth-Dwl3VAHa.js +2 -0
- package/out/externalAuth-Dwl3VAHa.js.map +1 -0
- package/out/findDebris-DOMvMC1l.js +2 -0
- package/out/findDebris-DOMvMC1l.js.map +1 -0
- package/out/fleet-DyITa_Xu.js +2 -0
- package/out/fleet-DyITa_Xu.js.map +1 -0
- package/out/fleetAjax-BGxyUtdi.js +2 -0
- package/out/fleetAjax-BGxyUtdi.js.map +1 -0
- package/out/fleetDealer-n6LM_8IT.js +2 -0
- package/out/fleetDealer-n6LM_8IT.js.map +1 -0
- package/out/fleetMissile-CucQvNmZ.js +2 -0
- package/out/fleetMissile-CucQvNmZ.js.map +1 -0
- package/out/fleetStep1-wp-NgTsC.js +2 -0
- package/out/fleetStep1-wp-NgTsC.js.map +1 -0
- package/out/fleetStep2-C-GzHXyn.js +2 -0
- package/out/fleetStep2-C-GzHXyn.js.map +1 -0
- package/out/fleetStep3-D_fqImWm.js +2 -0
- package/out/fleetStep3-D_fqImWm.js.map +1 -0
- package/out/fleetTable-BpWLh0R1.js +2 -0
- package/out/fleetTable-BpWLh0R1.js.map +1 -0
- package/out/flyingFleet-ClIrGPJz.js +2 -0
- package/out/flyingFleet-ClIrGPJz.js.map +1 -0
- package/out/galaxy-B12wKQUU.js +2 -0
- package/out/galaxy-B12wKQUU.js.map +1 -0
- package/out/get-Cn2hFvGS.js +2 -0
- package/out/get-Cn2hFvGS.js.map +1 -0
- package/out/giveaway-CDWEArOF.js +2 -0
- package/out/giveaway-CDWEArOF.js.map +1 -0
- package/out/growth-C_-C8rLD.js +2 -0
- package/out/growth-C_-C8rLD.js.map +1 -0
- package/out/index.d.ts +29 -0
- package/out/index.d.ts.map +1 -0
- package/out/index.js +1 -0
- package/out/information-CqfqYCH1.js +2 -0
- package/out/information-CqfqYCH1.js.map +1 -0
- package/out/information-DK93hgyE.js +2 -0
- package/out/information-DK93hgyE.js.map +1 -0
- package/out/log-BBE1Jt9i.js +2 -0
- package/out/log-BBE1Jt9i.js.map +1 -0
- package/out/login--4vqysQx.js +2 -0
- package/out/login--4vqysQx.js.map +1 -0
- package/out/login-C_DqRApn.js +2 -0
- package/out/login-C_DqRApn.js.map +1 -0
- package/out/logout-BYnLiMja.js +2 -0
- package/out/logout-BYnLiMja.js.map +1 -0
- package/out/logout-BsCSXzv8.js +2 -0
- package/out/logout-BsCSXzv8.js.map +1 -0
- package/out/lostPassword-Pc_1CUBD.js +2 -0
- package/out/lostPassword-Pc_1CUBD.js.map +1 -0
- package/out/market-DN8cY1tr.js +2 -0
- package/out/market-DN8cY1tr.js.map +1 -0
- package/out/messageList-k_zW_D0G.js +2 -0
- package/out/messageList-k_zW_D0G.js.map +1 -0
- package/out/messages-D461yIe6.js +2 -0
- package/out/messages-D461yIe6.js.map +1 -0
- package/out/missions-5zZtlLIm.js +2 -0
- package/out/missions-5zZtlLIm.js.map +1 -0
- package/out/module-BEPeTBhK.js +2 -0
- package/out/module-BEPeTBhK.js.map +1 -0
- package/out/multiIp-CP3lub1T.js +2 -0
- package/out/multiIp-CP3lub1T.js.map +1 -0
- package/out/new-star-BaVTTcIn.js +2 -0
- package/out/new-star-BaVTTcIn.js.map +1 -0
- package/out/news-BdDDcd-M.js +2 -0
- package/out/news-BdDDcd-M.js.map +1 -0
- package/out/news-Dd1C9JDl.js +2 -0
- package/out/news-Dd1C9JDl.js.map +1 -0
- package/out/notes-DLngBta3.js +2 -0
- package/out/notes-DLngBta3.js.map +1 -0
- package/out/overview-CzcSTNla.js +2 -0
- package/out/overview-CzcSTNla.js.map +1 -0
- package/out/overview-wQWIR_CB.js +2 -0
- package/out/overview-wQWIR_CB.js.map +1 -0
- package/out/password-ZA_1lStC.js +2 -0
- package/out/password-ZA_1lStC.js.map +1 -0
- package/out/phalanx-DaMaoJCT.js +2 -0
- package/out/phalanx-DaMaoJCT.js.map +1 -0
- package/out/planet-CecZ2cAZ.js +2 -0
- package/out/planet-CecZ2cAZ.js.map +1 -0
- package/out/playerCard-BG711xQi.js +2 -0
- package/out/playerCard-BG711xQi.js.map +1 -0
- package/out/post-C_ywAss7.js +2 -0
- package/out/post-C_ywAss7.js.map +1 -0
- package/out/production-D8SZfez8.js +2 -0
- package/out/production-D8SZfez8.js.map +1 -0
- package/out/public-TVVf75qu.js +2 -0
- package/out/public-TVVf75qu.js.map +1 -0
- package/out/questions-NwzZ5_fL.js +2 -0
- package/out/questions-NwzZ5_fL.js.map +1 -0
- package/out/quickEditor-DEJQFH0f.js +2 -0
- package/out/quickEditor-DEJQFH0f.js.map +1 -0
- package/out/records-CDVglYGy.js +2 -0
- package/out/records-CDVglYGy.js.map +1 -0
- package/out/records-Djjz9kxk.js +2 -0
- package/out/records-Djjz9kxk.js.map +1 -0
- package/out/reduceFleet-y8p89weR.js +2 -0
- package/out/reduceFleet-y8p89weR.js.map +1 -0
- package/out/reduceResources-CnGJ9fuf.js +2 -0
- package/out/reduceResources-CnGJ9fuf.js.map +1 -0
- package/out/refreshStatistics-CjGWyNc_.js +2 -0
- package/out/refreshStatistics-CjGWyNc_.js.map +1 -0
- package/out/register-4x5hZcWe.js +2 -0
- package/out/register-4x5hZcWe.js.map +1 -0
- package/out/research-dTK3-tOW.js +2 -0
- package/out/research-dTK3-tOW.js.map +1 -0
- package/out/reset-CHiMI9rj.js +2 -0
- package/out/reset-CHiMI9rj.js.map +1 -0
- package/out/resources-CjnevA41.js +2 -0
- package/out/resources-CjnevA41.js.map +1 -0
- package/out/rights-WPf-j_YF.js +2 -0
- package/out/rights-WPf-j_YF.js.map +1 -0
- package/out/rules-E29jtQRj.js +2 -0
- package/out/rules-E29jtQRj.js.map +1 -0
- package/out/runner-C2bQQS2G.js +43 -0
- package/out/runner-C2bQQS2G.js.map +1 -0
- package/out/scan-RvWZeyyM.js +2 -0
- package/out/scan-RvWZeyyM.js.map +1 -0
- package/out/screens-CZ4g-KNp.js +2 -0
- package/out/screens-CZ4g-KNp.js.map +1 -0
- package/out/search-BYvqiUBF.js +2 -0
- package/out/search-BYvqiUBF.js.map +1 -0
- package/out/search-auPbK2Xc.js +2 -0
- package/out/search-auPbK2Xc.js.map +1 -0
- package/out/sendMessages-B2Uj3PW4.js +2 -0
- package/out/sendMessages-B2Uj3PW4.js.map +1 -0
- package/out/settings-DFFa6Ush.js +2 -0
- package/out/settings-DFFa6Ush.js.map +1 -0
- package/out/settings-Ddez5x9U.js +2 -0
- package/out/settings-Ddez5x9U.js.map +1 -0
- package/out/shared-DoaW4mlX.js +2 -0
- package/out/shared-DoaW4mlX.js.map +1 -0
- package/out/shipyard-DXr745hR.js +2 -0
- package/out/shipyard-DXr745hR.js.map +1 -0
- package/out/shops-CEE02c0g.js +2 -0
- package/out/shops-CEE02c0g.js.map +1 -0
- package/out/snapshot-CrJ8l50N.js +2 -0
- package/out/snapshot-CrJ8l50N.js.map +1 -0
- package/out/social-1Gdni-jZ.js +2 -0
- package/out/social-1Gdni-jZ.js.map +1 -0
- package/out/spec-CrkWB0BN.js +2 -0
- package/out/spec-CrkWB0BN.js.map +1 -0
- package/out/statistics-zg3aVAvW.js +2 -0
- package/out/statistics-zg3aVAvW.js.map +1 -0
- package/out/store-dXG7NoB4.js +2 -0
- package/out/store-dXG7NoB4.js.map +1 -0
- package/out/support-DisUQr57.js +2 -0
- package/out/support-DisUQr57.js.map +1 -0
- package/out/techtree-Ba3FEH5_.js +2 -0
- package/out/techtree-Ba3FEH5_.js.map +1 -0
- package/out/ticket-O_8jTKW8.js +2 -0
- package/out/ticket-O_8jTKW8.js.map +1 -0
- package/out/trader-zFDGaHZ9.js +2 -0
- package/out/trader-zFDGaHZ9.js.map +1 -0
- package/out/universe-DO32RnLQ.js +2 -0
- package/out/universe-DO32RnLQ.js.map +1 -0
- package/out/universeSettings-S7enRJR4.js +2 -0
- package/out/universeSettings-S7enRJR4.js.map +1 -0
- package/out/values-gwcnIHXs.js +2 -0
- package/out/values-gwcnIHXs.js.map +1 -0
- package/out/verify-sYnZ9juV.js +2 -0
- package/out/verify-sYnZ9juV.js.map +1 -0
- package/out/version-Cgs-grc5.js +2 -0
- package/out/version-Cgs-grc5.js.map +1 -0
- package/package.json +65 -4
- package/src/admin.ts +317 -0
- package/src/arguments.ts +323 -0
- package/src/catalog.ts +117 -0
- package/src/cli.ts +29 -0
- package/src/commands/admin/accountEditor.ts +33 -0
- package/src/commands/admin/active.ts +25 -0
- package/src/commands/admin/ban.ts +59 -0
- package/src/commands/admin/clearCache.ts +12 -0
- package/src/commands/admin/create.ts +59 -0
- package/src/commands/admin/cronjob.ts +94 -0
- package/src/commands/admin/dump.ts +25 -0
- package/src/commands/admin/flyingFleet.ts +25 -0
- package/src/commands/admin/giveaway.ts +37 -0
- package/src/commands/admin/information.ts +12 -0
- package/src/commands/admin/log.ts +37 -0
- package/src/commands/admin/login.ts +15 -0
- package/src/commands/admin/logout.ts +12 -0
- package/src/commands/admin/messageList.ts +19 -0
- package/src/commands/admin/module.ts +25 -0
- package/src/commands/admin/multiIp.ts +25 -0
- package/src/commands/admin/news.ts +40 -0
- package/src/commands/admin/overview.ts +12 -0
- package/src/commands/admin/password.ts +18 -0
- package/src/commands/admin/quickEditor.ts +30 -0
- package/src/commands/admin/refreshStatistics.ts +12 -0
- package/src/commands/admin/reset.ts +26 -0
- package/src/commands/admin/rights.ts +68 -0
- package/src/commands/admin/search.ts +31 -0
- package/src/commands/admin/sendMessages.ts +26 -0
- package/src/commands/admin/support.ts +48 -0
- package/src/commands/admin/universe.ts +49 -0
- package/src/commands/admin/universeSettings.ts +32 -0
- package/src/commands/game/achievements.ts +18 -0
- package/src/commands/game/alliance.ts +248 -0
- package/src/commands/game/allianceAdmin.ts +236 -0
- package/src/commands/game/arsenal.ts +12 -0
- package/src/commands/game/banList.ts +20 -0
- package/src/commands/game/battleHall.ts +21 -0
- package/src/commands/game/battleReport.ts +20 -0
- package/src/commands/game/battleSimulator.ts +41 -0
- package/src/commands/game/board.ts +12 -0
- package/src/commands/game/bonusSummary.ts +12 -0
- package/src/commands/game/buddyList.ts +76 -0
- package/src/commands/game/buildings.ts +81 -0
- package/src/commands/game/chat.ts +12 -0
- package/src/commands/game/containers.ts +33 -0
- package/src/commands/game/control.ts +16 -0
- package/src/commands/game/createMoon.ts +28 -0
- package/src/commands/game/dailyBonus.ts +18 -0
- package/src/commands/game/delivery.ts +34 -0
- package/src/commands/game/endpoints.ts +61 -0
- package/src/commands/game/findDebris.ts +16 -0
- package/src/commands/game/fleetAjax.ts +24 -0
- package/src/commands/game/fleetDealer.ts +36 -0
- package/src/commands/game/fleetMissile.ts +25 -0
- package/src/commands/game/fleetStep1.ts +74 -0
- package/src/commands/game/fleetStep2.ts +27 -0
- package/src/commands/game/fleetStep3.ts +28 -0
- package/src/commands/game/fleetTable.ts +96 -0
- package/src/commands/game/galaxy.ts +26 -0
- package/src/commands/game/growth.ts +313 -0
- package/src/commands/game/information.ts +56 -0
- package/src/commands/game/logout.ts +12 -0
- package/src/commands/game/market.ts +67 -0
- package/src/commands/game/messages.ts +129 -0
- package/src/commands/game/notes.ts +65 -0
- package/src/commands/game/overview.ts +49 -0
- package/src/commands/game/phalanx.ts +23 -0
- package/src/commands/game/planet.ts +78 -0
- package/src/commands/game/playerCard.ts +20 -0
- package/src/commands/game/questions.ts +23 -0
- package/src/commands/game/records.ts +16 -0
- package/src/commands/game/reduceFleet.ts +41 -0
- package/src/commands/game/reduceResources.ts +35 -0
- package/src/commands/game/research.ts +80 -0
- package/src/commands/game/resources.ts +49 -0
- package/src/commands/game/scan.ts +12 -0
- package/src/commands/game/search.ts +44 -0
- package/src/commands/game/settings.ts +121 -0
- package/src/commands/game/shipyard.ts +61 -0
- package/src/commands/game/shops.ts +89 -0
- package/src/commands/game/statistics.ts +22 -0
- package/src/commands/game/store.ts +12 -0
- package/src/commands/game/techtree.ts +16 -0
- package/src/commands/game/ticket.ts +44 -0
- package/src/commands/game/trader.ts +51 -0
- package/src/commands/game/workflows/fleet.ts +12 -0
- package/src/commands/game/workflows/snapshot.ts +84 -0
- package/src/commands/game/workflows/social.ts +37 -0
- package/src/commands/http/get.ts +13 -0
- package/src/commands/http/post.ts +44 -0
- package/src/commands/public/banList.ts +21 -0
- package/src/commands/public/battleHall.ts +20 -0
- package/src/commands/public/battleReport.ts +20 -0
- package/src/commands/public/board.ts +20 -0
- package/src/commands/public/disclaimer.ts +20 -0
- package/src/commands/public/externalAuth.ts +17 -0
- package/src/commands/public/index.ts +22 -0
- package/src/commands/public/login.ts +20 -0
- package/src/commands/public/lostPassword.ts +57 -0
- package/src/commands/public/news.ts +20 -0
- package/src/commands/public/register.ts +46 -0
- package/src/commands/public/rules.ts +20 -0
- package/src/commands/public/screens.ts +20 -0
- package/src/commands/public/verify.ts +38 -0
- package/src/commands/rules/new-star.ts +221 -0
- package/src/commands/rules/production.ts +51 -0
- package/src/completion/BifrostCompletion.psm1 +47 -0
- package/src/completion.ts +445 -0
- package/src/connection.ts +106 -0
- package/src/destination.ts +64 -0
- package/src/game.ts +978 -0
- package/src/help.ts +203 -0
- package/src/i18n.ts +45 -0
- package/src/index.ts +2 -0
- package/src/input/admin/accountEditor.ts +156 -0
- package/src/input/admin/ban.ts +23 -0
- package/src/input/admin/create.ts +36 -0
- package/src/input/admin/cronjob.ts +22 -0
- package/src/input/admin/fields.ts +432 -0
- package/src/input/admin/login.ts +9 -0
- package/src/input/admin/messageList.ts +21 -0
- package/src/input/admin/news.ts +29 -0
- package/src/input/admin/quickEditor.ts +115 -0
- package/src/input/admin/records.ts +68 -0
- package/src/input/admin/reset.ts +29 -0
- package/src/input/admin/search.ts +23 -0
- package/src/input/admin/sendMessages.ts +21 -0
- package/src/input/admin/universeSettings.ts +46 -0
- package/src/input/files.ts +65 -0
- package/src/input/game/allianceAdmin.ts +55 -0
- package/src/input/game/battleSimulator.ts +25 -0
- package/src/input/game/fleetStep1.ts +14 -0
- package/src/input/game/settings.ts +46 -0
- package/src/input/game/ticket.ts +16 -0
- package/src/input/parse.ts +173 -0
- package/src/input/paths.ts +392 -0
- package/src/input/protocol/context.ts +10 -0
- package/src/input/protocol/missions.ts +6 -0
- package/src/input/protocol/routes.ts +15 -0
- package/src/input/protocol/settings.ts +126 -0
- package/src/input/protocol/values.ts +13 -0
- package/src/input/public/externalAuth.ts +26 -0
- package/src/input/public/register.ts +9 -0
- package/src/input/rules/new-star.ts +21 -0
- package/src/input/rules/production.ts +14 -0
- package/src/input/shared.ts +51 -0
- package/src/input/spec.ts +155 -0
- package/src/input/values.ts +114 -0
- package/src/input/workflows/fleet.ts +22 -0
- package/src/input/workflows/snapshot.ts +74 -0
- package/src/locales/en-US/commands.ts +377 -0
- package/src/locales/en-US/diagnostics.ts +89 -0
- package/src/locales/en-US.ts +61 -0
- package/src/locales/zh-CN/commands.ts +307 -0
- package/src/locales/zh-CN/diagnostics.ts +81 -0
- package/src/locales/zh-CN.ts +57 -0
- package/src/options.ts +48 -0
- package/src/output.ts +201 -0
- package/src/pointer.ts +46 -0
- package/src/presentation.ts +96 -0
- package/src/public.ts +99 -0
- package/src/registry.ts +67 -0
- package/src/requests.ts +13 -0
- package/src/result.ts +27 -0
- package/src/rules.ts +77 -0
- package/src/runner.ts +214 -0
- package/src/selection.ts +44 -0
- package/src/terminal.ts +27 -0
- package/src/types.ts +110 -0
- package/src/version.ts +11 -0
package/src/admin.ts
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
import { defineCommands } from './catalog.ts'
|
|
2
|
+
import type { CommandEntry } from './catalog.ts'
|
|
3
|
+
|
|
4
|
+
export const adminCommands: readonly CommandEntry[] = defineCommands('admin', [
|
|
5
|
+
{
|
|
6
|
+
method: 'adminAccountEditor',
|
|
7
|
+
load: () =>
|
|
8
|
+
import('./commands/admin/accountEditor.ts').then(
|
|
9
|
+
(module) => module.adminAccountEditorCommand,
|
|
10
|
+
),
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
method: 'adminAccountEditorSubmit',
|
|
14
|
+
load: () =>
|
|
15
|
+
import('./commands/admin/accountEditor.ts').then(
|
|
16
|
+
(module) => module.adminAccountEditorSubmitCommand,
|
|
17
|
+
),
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
method: 'adminActive',
|
|
21
|
+
load: () => import('./commands/admin/active.ts').then((module) => module.adminActiveCommand),
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
method: 'adminActiveDelete',
|
|
25
|
+
load: () =>
|
|
26
|
+
import('./commands/admin/active.ts').then((module) => module.adminActiveDeleteCommand),
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
method: 'adminBan',
|
|
30
|
+
load: () => import('./commands/admin/ban.ts').then((module) => module.adminBanCommand),
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
method: 'adminBanLift',
|
|
34
|
+
load: () => import('./commands/admin/ban.ts').then((module) => module.adminBanLiftCommand),
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
method: 'adminBanLookup',
|
|
38
|
+
load: () => import('./commands/admin/ban.ts').then((module) => module.adminBanLookupCommand),
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
method: 'adminBanPlace',
|
|
42
|
+
load: () => import('./commands/admin/ban.ts').then((module) => module.adminBanPlaceCommand),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
method: 'adminClearCache',
|
|
46
|
+
load: () =>
|
|
47
|
+
import('./commands/admin/clearCache.ts').then((module) => module.adminClearCacheCommand),
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
method: 'adminCreate',
|
|
51
|
+
load: () => import('./commands/admin/create.ts').then((module) => module.adminCreateCommand),
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
method: 'adminCreateMoon',
|
|
55
|
+
load: () =>
|
|
56
|
+
import('./commands/admin/create.ts').then((module) => module.adminCreateMoonCommand),
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
method: 'adminCreatePlanet',
|
|
60
|
+
load: () =>
|
|
61
|
+
import('./commands/admin/create.ts').then((module) => module.adminCreatePlanetCommand),
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
method: 'adminCreateUser',
|
|
65
|
+
load: () =>
|
|
66
|
+
import('./commands/admin/create.ts').then((module) => module.adminCreateUserCommand),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
method: 'adminCronjob',
|
|
70
|
+
load: () => import('./commands/admin/cronjob.ts').then((module) => module.adminCronjobCommand),
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
method: 'adminCronjobDelete',
|
|
74
|
+
load: () =>
|
|
75
|
+
import('./commands/admin/cronjob.ts').then((module) => module.adminCronjobDeleteCommand),
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
method: 'adminCronjobDetail',
|
|
79
|
+
load: () =>
|
|
80
|
+
import('./commands/admin/cronjob.ts').then((module) => module.adminCronjobDetailCommand),
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
method: 'adminCronjobEnable',
|
|
84
|
+
load: () =>
|
|
85
|
+
import('./commands/admin/cronjob.ts').then((module) => module.adminCronjobEnableCommand),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
method: 'adminCronjobLock',
|
|
89
|
+
load: () =>
|
|
90
|
+
import('./commands/admin/cronjob.ts').then((module) => module.adminCronjobLockCommand),
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
method: 'adminCronjobSave',
|
|
94
|
+
load: () =>
|
|
95
|
+
import('./commands/admin/cronjob.ts').then((module) => module.adminCronjobSaveCommand),
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
method: 'adminCronjobUnlock',
|
|
99
|
+
load: () =>
|
|
100
|
+
import('./commands/admin/cronjob.ts').then((module) => module.adminCronjobUnlockCommand),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
method: 'adminDump',
|
|
104
|
+
load: () => import('./commands/admin/dump.ts').then((module) => module.adminDumpCommand),
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
method: 'adminDumpBackup',
|
|
108
|
+
load: () => import('./commands/admin/dump.ts').then((module) => module.adminDumpBackupCommand),
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
method: 'adminFlyingFleet',
|
|
112
|
+
load: () =>
|
|
113
|
+
import('./commands/admin/flyingFleet.ts').then((module) => module.adminFlyingFleetCommand),
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
method: 'adminFlyingFleetSetBusy',
|
|
117
|
+
load: () =>
|
|
118
|
+
import('./commands/admin/flyingFleet.ts').then(
|
|
119
|
+
(module) => module.adminFlyingFleetSetBusyCommand,
|
|
120
|
+
),
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
method: 'adminGiveaway',
|
|
124
|
+
load: () =>
|
|
125
|
+
import('./commands/admin/giveaway.ts').then((module) => module.adminGiveawayCommand),
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
method: 'adminGiveawayAward',
|
|
129
|
+
load: () =>
|
|
130
|
+
import('./commands/admin/giveaway.ts').then((module) => module.adminGiveawayAwardCommand),
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
method: 'adminInformation',
|
|
134
|
+
load: () =>
|
|
135
|
+
import('./commands/admin/information.ts').then((module) => module.adminInformationCommand),
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
method: 'adminLog',
|
|
139
|
+
load: () => import('./commands/admin/log.ts').then((module) => module.adminLogCommand),
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
method: 'adminLogDetail',
|
|
143
|
+
load: () => import('./commands/admin/log.ts').then((module) => module.adminLogDetailCommand),
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
method: 'adminLogList',
|
|
147
|
+
load: () => import('./commands/admin/log.ts').then((module) => module.adminLogListCommand),
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
method: 'adminLogin',
|
|
151
|
+
load: () => import('./commands/admin/login.ts').then((module) => module.adminLoginCommand),
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
method: 'adminLogout',
|
|
155
|
+
load: () => import('./commands/admin/logout.ts').then((module) => module.adminLogoutCommand),
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
method: 'adminMessageList',
|
|
159
|
+
load: () =>
|
|
160
|
+
import('./commands/admin/messageList.ts').then((module) => module.adminMessageListCommand),
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
method: 'adminModule',
|
|
164
|
+
load: () => import('./commands/admin/module.ts').then((module) => module.adminModuleCommand),
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
method: 'adminModuleSet',
|
|
168
|
+
load: () => import('./commands/admin/module.ts').then((module) => module.adminModuleSetCommand),
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
method: 'adminMultiIp',
|
|
172
|
+
load: () => import('./commands/admin/multiIp.ts').then((module) => module.adminMultiIpCommand),
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
method: 'adminMultiIpMark',
|
|
176
|
+
load: () =>
|
|
177
|
+
import('./commands/admin/multiIp.ts').then((module) => module.adminMultiIpMarkCommand),
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
method: 'adminNews',
|
|
181
|
+
load: () => import('./commands/admin/news.ts').then((module) => module.adminNewsCommand),
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
method: 'adminNewsDelete',
|
|
185
|
+
load: () => import('./commands/admin/news.ts').then((module) => module.adminNewsDeleteCommand),
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
method: 'adminNewsSave',
|
|
189
|
+
load: () => import('./commands/admin/news.ts').then((module) => module.adminNewsSaveCommand),
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
method: 'adminOverview',
|
|
193
|
+
load: () =>
|
|
194
|
+
import('./commands/admin/overview.ts').then((module) => module.adminOverviewCommand),
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
method: 'adminPassword',
|
|
198
|
+
load: () =>
|
|
199
|
+
import('./commands/admin/password.ts').then((module) => module.adminPasswordCommand),
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
method: 'adminQuickEditor',
|
|
203
|
+
load: () =>
|
|
204
|
+
import('./commands/admin/quickEditor.ts').then((module) => module.adminQuickEditorCommand),
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
method: 'adminQuickEditorSave',
|
|
208
|
+
load: () =>
|
|
209
|
+
import('./commands/admin/quickEditor.ts').then(
|
|
210
|
+
(module) => module.adminQuickEditorSaveCommand,
|
|
211
|
+
),
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
method: 'adminRefreshStatistics',
|
|
215
|
+
load: () =>
|
|
216
|
+
import('./commands/admin/refreshStatistics.ts').then(
|
|
217
|
+
(module) => module.adminRefreshStatisticsCommand,
|
|
218
|
+
),
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
method: 'adminReset',
|
|
222
|
+
load: () => import('./commands/admin/reset.ts').then((module) => module.adminResetCommand),
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
method: 'adminResetUniverse',
|
|
226
|
+
load: () =>
|
|
227
|
+
import('./commands/admin/reset.ts').then((module) => module.adminResetUniverseCommand),
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
method: 'adminRights',
|
|
231
|
+
load: () => import('./commands/admin/rights.ts').then((module) => module.adminRightsCommand),
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
method: 'adminRightsLookup',
|
|
235
|
+
load: () =>
|
|
236
|
+
import('./commands/admin/rights.ts').then((module) => module.adminRightsLookupCommand),
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
method: 'adminRightsSave',
|
|
240
|
+
load: () =>
|
|
241
|
+
import('./commands/admin/rights.ts').then((module) => module.adminRightsSaveCommand),
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
method: 'adminRightsSetLevel',
|
|
245
|
+
load: () =>
|
|
246
|
+
import('./commands/admin/rights.ts').then((module) => module.adminRightsSetLevelCommand),
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
method: 'adminSearch',
|
|
250
|
+
load: () => import('./commands/admin/search.ts').then((module) => module.adminSearchCommand),
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
method: 'adminSearchDelete',
|
|
254
|
+
load: () =>
|
|
255
|
+
import('./commands/admin/search.ts').then((module) => module.adminSearchDeleteCommand),
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
method: 'adminSendMessages',
|
|
259
|
+
load: () =>
|
|
260
|
+
import('./commands/admin/sendMessages.ts').then((module) => module.adminSendMessagesCommand),
|
|
261
|
+
},
|
|
262
|
+
{
|
|
263
|
+
method: 'adminSendMessagesSend',
|
|
264
|
+
load: () =>
|
|
265
|
+
import('./commands/admin/sendMessages.ts').then(
|
|
266
|
+
(module) => module.adminSendMessagesSendCommand,
|
|
267
|
+
),
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
method: 'adminSupport',
|
|
271
|
+
load: () => import('./commands/admin/support.ts').then((module) => module.adminSupportCommand),
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
method: 'adminSupportSend',
|
|
275
|
+
load: () =>
|
|
276
|
+
import('./commands/admin/support.ts').then((module) => module.adminSupportSendCommand),
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
method: 'adminSupportView',
|
|
280
|
+
load: () =>
|
|
281
|
+
import('./commands/admin/support.ts').then((module) => module.adminSupportViewCommand),
|
|
282
|
+
},
|
|
283
|
+
{
|
|
284
|
+
method: 'adminUniverse',
|
|
285
|
+
load: () =>
|
|
286
|
+
import('./commands/admin/universe.ts').then((module) => module.adminUniverseCommand),
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
method: 'adminUniverseCreate',
|
|
290
|
+
load: () =>
|
|
291
|
+
import('./commands/admin/universe.ts').then((module) => module.adminUniverseCreateCommand),
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
method: 'adminUniverseDelete',
|
|
295
|
+
load: () =>
|
|
296
|
+
import('./commands/admin/universe.ts').then((module) => module.adminUniverseDeleteCommand),
|
|
297
|
+
},
|
|
298
|
+
{
|
|
299
|
+
method: 'adminUniverseOpen',
|
|
300
|
+
load: () =>
|
|
301
|
+
import('./commands/admin/universe.ts').then((module) => module.adminUniverseOpenCommand),
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
method: 'adminUniverseSettings',
|
|
305
|
+
load: () =>
|
|
306
|
+
import('./commands/admin/universeSettings.ts').then(
|
|
307
|
+
(module) => module.adminUniverseSettingsCommand,
|
|
308
|
+
),
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
method: 'adminUniverseSettingsSave',
|
|
312
|
+
load: () =>
|
|
313
|
+
import('./commands/admin/universeSettings.ts').then(
|
|
314
|
+
(module) => module.adminUniverseSettingsSaveCommand,
|
|
315
|
+
),
|
|
316
|
+
},
|
|
317
|
+
])
|
package/src/arguments.ts
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { parseArgs } from 'node:util'
|
|
2
|
+
|
|
3
|
+
import type { CommandEntry } from './catalog.ts'
|
|
4
|
+
import { LOCALE_MODES, messages } from './i18n.ts'
|
|
5
|
+
import type { LocaleMode } from './i18n.ts'
|
|
6
|
+
import type { InputSource } from './input/files.ts'
|
|
7
|
+
import { readArgument } from './input/files.ts'
|
|
8
|
+
import { matchesInput } from './input/parse.ts'
|
|
9
|
+
import { assignOptions, assignPath, comparePaths, inputLabel, resolvePath } from './input/paths.ts'
|
|
10
|
+
import type { InputPath } from './input/paths.ts'
|
|
11
|
+
import type { InputNode } from './input/spec.ts'
|
|
12
|
+
import { isFields, isNumber } from './input/values.ts'
|
|
13
|
+
import { BOOLEAN_FLAGS, COMPLETION_FLAGS, GLOBAL_FLAGS, isReservedFlag } from './options.ts'
|
|
14
|
+
import { PRESENTATION_MODES } from './presentation.ts'
|
|
15
|
+
import type { PresentationMode } from './presentation.ts'
|
|
16
|
+
import { findCommand } from './registry.ts'
|
|
17
|
+
import { UsageError } from './result.ts'
|
|
18
|
+
import { FORMATS } from './types.ts'
|
|
19
|
+
import type { Command, Fields, Format } from './types.ts'
|
|
20
|
+
|
|
21
|
+
export type Values = Record<string, string | boolean | undefined>
|
|
22
|
+
export type Invocation = {
|
|
23
|
+
words: string[]
|
|
24
|
+
values: Values
|
|
25
|
+
command: CommandEntry | undefined
|
|
26
|
+
format: Format
|
|
27
|
+
color: PresentationMode
|
|
28
|
+
links: PresentationMode
|
|
29
|
+
locale: LocaleMode
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function presentationOption(values: Values, name: string): PresentationMode {
|
|
33
|
+
const value = stringOption(values, name) ?? 'auto'
|
|
34
|
+
const mode = PRESENTATION_MODES.find((choice) => choice === value)
|
|
35
|
+
if (mode === undefined)
|
|
36
|
+
throw new UsageError(messages().diagnostics.presentationMode(name, PRESENTATION_MODES))
|
|
37
|
+
return mode
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function localeOption(values: Values): LocaleMode {
|
|
41
|
+
const value = stringOption(values, 'locale') ?? 'auto'
|
|
42
|
+
const locale = LOCALE_MODES.find((choice) => choice.toLowerCase() === value.toLowerCase())
|
|
43
|
+
if (locale === undefined)
|
|
44
|
+
throw new UsageError(messages().diagnostics.invalidLocale(value, LOCALE_MODES))
|
|
45
|
+
return locale
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Diagnostics honor valid display choices even when strict argument parsing fails.
|
|
50
|
+
*
|
|
51
|
+
* 严格参数解析失败时,诊断输出仍遵循已提供的有效显示选项。
|
|
52
|
+
*/
|
|
53
|
+
export function diagnosticOptions(
|
|
54
|
+
args: readonly string[],
|
|
55
|
+
): Pick<Invocation, 'format' | 'color' | 'links' | 'locale'> {
|
|
56
|
+
function choice<Value extends string>(
|
|
57
|
+
name: string,
|
|
58
|
+
values: readonly Value[],
|
|
59
|
+
fallback: Value,
|
|
60
|
+
): Value {
|
|
61
|
+
let result = fallback
|
|
62
|
+
for (const [index, argument] of args.entries()) {
|
|
63
|
+
if (argument === '--') break
|
|
64
|
+
const supplied =
|
|
65
|
+
argument === `--${name}`
|
|
66
|
+
? args[index + 1]
|
|
67
|
+
: argument.startsWith(`--${name}=`)
|
|
68
|
+
? argument.slice(name.length + 3)
|
|
69
|
+
: undefined
|
|
70
|
+
const value = values.find((candidate) =>
|
|
71
|
+
name === 'locale'
|
|
72
|
+
? candidate.toLowerCase() === supplied?.toLowerCase()
|
|
73
|
+
: candidate === supplied,
|
|
74
|
+
)
|
|
75
|
+
if (value !== undefined) result = value
|
|
76
|
+
}
|
|
77
|
+
return result
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
format: choice('format', ['text', 'json'], 'text'),
|
|
81
|
+
color: choice('color', PRESENTATION_MODES, 'auto'),
|
|
82
|
+
links: choice('links', PRESENTATION_MODES, 'auto'),
|
|
83
|
+
locale: choice('locale', LOCALE_MODES, 'auto'),
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Collect named options before resolving the command so values never become command words.
|
|
89
|
+
*
|
|
90
|
+
* 先收集具名选项,再解析命令,避免把参数值误认为命令路径。
|
|
91
|
+
*/
|
|
92
|
+
export function parse(arguments_: readonly string[]): Invocation {
|
|
93
|
+
const options: Record<string, { type: 'string' | 'boolean' }> = Object.fromEntries(
|
|
94
|
+
GLOBAL_FLAGS.map((name) => [name, { type: 'string' }]),
|
|
95
|
+
)
|
|
96
|
+
for (const name of [...BOOLEAN_FLAGS, ...COMPLETION_FLAGS]) options[name] = { type: 'boolean' }
|
|
97
|
+
for (const argument of arguments_) {
|
|
98
|
+
if (argument === '--') break
|
|
99
|
+
if (!argument.startsWith('--')) continue
|
|
100
|
+
const name = argument.slice(2).split('=')[0]
|
|
101
|
+
if (name && !Object.hasOwn(options, name)) options[name] = { type: 'string' }
|
|
102
|
+
}
|
|
103
|
+
let parsed
|
|
104
|
+
try {
|
|
105
|
+
parsed = parseArgs({ args: [...arguments_], options, allowPositionals: true, tokens: true })
|
|
106
|
+
} catch (error) {
|
|
107
|
+
if (!(error instanceof Error)) throw error
|
|
108
|
+
throw new UsageError(messages().diagnostics.nativeArguments(error.message))
|
|
109
|
+
}
|
|
110
|
+
const seen = new Set<string>()
|
|
111
|
+
for (const token of parsed.tokens) {
|
|
112
|
+
if (token.kind !== 'option') continue
|
|
113
|
+
const name = token.name === 'no-auto-login' ? 'auto-login' : token.name
|
|
114
|
+
if (seen.has(name)) throw new UsageError(messages().diagnostics.repeatedOption(name))
|
|
115
|
+
seen.add(name)
|
|
116
|
+
}
|
|
117
|
+
const values: Values = { ...parsed.values }
|
|
118
|
+
const format = stringOption(values, 'format') ?? 'text'
|
|
119
|
+
if (format !== 'json' && format !== 'text')
|
|
120
|
+
throw new UsageError(messages().diagnostics.outputFormat(FORMATS))
|
|
121
|
+
const color = presentationOption(values, 'color')
|
|
122
|
+
const links = presentationOption(values, 'links')
|
|
123
|
+
const locale = localeOption(values)
|
|
124
|
+
for (const token of parsed.tokens)
|
|
125
|
+
if (token.kind === 'option' && (token.name === 'auto-login' || token.name === 'no-auto-login'))
|
|
126
|
+
values['auto-login'] = token.name === 'auto-login'
|
|
127
|
+
delete values['no-auto-login']
|
|
128
|
+
const words = parsed.positionals
|
|
129
|
+
if (values.enhance === true && words[0] !== 'completion')
|
|
130
|
+
throw new UsageError(messages().diagnostics.enhanceScope)
|
|
131
|
+
const command = findCommand(words.join(' '))
|
|
132
|
+
/**
|
|
133
|
+
* With no command words every non-global option is undeclared; with command words it is the
|
|
134
|
+
* sequence itself that fails to resolve, and the caller reports that failure instead.
|
|
135
|
+
*
|
|
136
|
+
* 没有命令词时,任何非全局选项都是未声明的;有命令词时,无法解析的是词序列本身,
|
|
137
|
+
* 该失败交由调用方报告。
|
|
138
|
+
*/
|
|
139
|
+
if (words.length === 0)
|
|
140
|
+
for (const name of Object.keys(values))
|
|
141
|
+
if (!isReservedFlag(name)) throw new UsageError(messages().diagnostics.unknownOption(name))
|
|
142
|
+
return { words, values, command, format, color, links, locale }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export function stringOption(values: Values, name: string): string | undefined {
|
|
146
|
+
const value = values[name]
|
|
147
|
+
if (value === undefined) return undefined
|
|
148
|
+
if (typeof value !== 'string') throw new UsageError(messages().diagnostics.expectedString(name))
|
|
149
|
+
return value
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* JSON documents are explicit inputs; files and stdin do not become persistent CLI state.
|
|
154
|
+
*
|
|
155
|
+
* JSON 文档均为显式输入;文件与标准输入不作为 CLI 持久状态。
|
|
156
|
+
*/
|
|
157
|
+
export async function inputDocument(values: Values, read: InputSource): Promise<Fields> {
|
|
158
|
+
const input = stringOption(values, 'input')
|
|
159
|
+
if (input === undefined) return {}
|
|
160
|
+
const value = await readArgument(input, 'input', read)
|
|
161
|
+
if (!isFields(value)) throw new UsageError(messages().diagnostics.inputObject)
|
|
162
|
+
return value
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function stringInput(schema: InputNode): boolean {
|
|
166
|
+
if (schema.kind === 'string') return true
|
|
167
|
+
if (schema.kind === 'enum') return schema.values.some((value) => typeof value === 'string')
|
|
168
|
+
if (schema.kind === 'union') return schema.variants.some(stringInput)
|
|
169
|
+
return schema.kind === 'custom' && schema.input !== undefined && stringInput(schema.input)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function structuredInput(schema: InputNode): boolean {
|
|
173
|
+
if (
|
|
174
|
+
schema.kind === 'object' ||
|
|
175
|
+
schema.kind === 'array' ||
|
|
176
|
+
schema.kind === 'map' ||
|
|
177
|
+
schema.kind === 'document'
|
|
178
|
+
)
|
|
179
|
+
return true
|
|
180
|
+
if (schema.kind === 'union') return schema.variants.some(structuredInput)
|
|
181
|
+
return schema.kind === 'custom' && schema.input !== undefined && structuredInput(schema.input)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function numberValue(value: string): number | undefined {
|
|
185
|
+
const number = Number(value)
|
|
186
|
+
return value.trim() !== '' && isNumber(number) ? number : undefined
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Decode text according to its declared leaf type; strings retain literal spelling.
|
|
191
|
+
*
|
|
192
|
+
* 按声明的叶子类型解码文本;字符串保留字面内容。
|
|
193
|
+
*/
|
|
194
|
+
export function flagValue(schema: InputNode, value: string): unknown {
|
|
195
|
+
if (schema.kind === 'custom' && schema.input !== undefined) return flagValue(schema.input, value)
|
|
196
|
+
if (schema.kind === 'string') return value
|
|
197
|
+
if (schema.kind === 'number') {
|
|
198
|
+
const number = numberValue(value)
|
|
199
|
+
if (number !== undefined) return number
|
|
200
|
+
throw new UsageError(messages().diagnostics.finiteNumber)
|
|
201
|
+
}
|
|
202
|
+
if (schema.kind === 'enum') {
|
|
203
|
+
if (schema.values.includes(value)) return value
|
|
204
|
+
const number = numberValue(value)
|
|
205
|
+
for (const choice of schema.values)
|
|
206
|
+
if (typeof choice === 'number' ? choice === number : String(choice) === value) return choice
|
|
207
|
+
throw new UsageError(messages().diagnostics.enumChoice(schema.values.join(', ')))
|
|
208
|
+
}
|
|
209
|
+
if (schema.kind === 'union') {
|
|
210
|
+
if (structuredInput(schema) && /^\s*[[{]/u.test(value)) {
|
|
211
|
+
try {
|
|
212
|
+
return JSON.parse(value)
|
|
213
|
+
} catch {
|
|
214
|
+
throw new UsageError(messages().diagnostics.jsonContainer)
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
const preferred = schema.variants.toSorted(
|
|
218
|
+
(left, right) => Number(stringInput(right)) - Number(stringInput(left)),
|
|
219
|
+
)
|
|
220
|
+
for (const variant of preferred) {
|
|
221
|
+
try {
|
|
222
|
+
const decoded = flagValue(variant, value)
|
|
223
|
+
if (matchesInput(variant, decoded) || variant.kind === 'custom') return decoded
|
|
224
|
+
} catch (error) {
|
|
225
|
+
if (!(error instanceof UsageError)) throw error
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
throw new UsageError(messages().diagnostics.expectedType(inputLabel(schema)))
|
|
229
|
+
}
|
|
230
|
+
let decoded: unknown
|
|
231
|
+
try {
|
|
232
|
+
decoded = JSON.parse(value)
|
|
233
|
+
} catch {
|
|
234
|
+
throw new UsageError(messages().diagnostics.jsonValue)
|
|
235
|
+
}
|
|
236
|
+
if ((schema.kind === 'boolean' || schema.kind === 'null') && !matchesInput(schema, decoded))
|
|
237
|
+
throw new UsageError(messages().diagnostics.expectedType(inputLabel(schema)))
|
|
238
|
+
return decoded
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* More specific paths override parent values without mutating the supplied document.
|
|
243
|
+
*
|
|
244
|
+
* 具体路径覆盖父级值,不修改调用方提供的文档。
|
|
245
|
+
*/
|
|
246
|
+
export async function businessInput(
|
|
247
|
+
command: Command,
|
|
248
|
+
values: Values,
|
|
249
|
+
document: Fields,
|
|
250
|
+
read: InputSource,
|
|
251
|
+
): Promise<Fields> {
|
|
252
|
+
const options = Object.entries(values)
|
|
253
|
+
.filter(([name]) => !GLOBAL_FLAGS.includes(name) && !BOOLEAN_FLAGS.includes(name))
|
|
254
|
+
.flatMap(([name]) => {
|
|
255
|
+
const value = stringOption(values, name)
|
|
256
|
+
return value === undefined ? [] : [{ name, text: value }]
|
|
257
|
+
})
|
|
258
|
+
const assigned: {
|
|
259
|
+
name: string
|
|
260
|
+
text: string
|
|
261
|
+
imported: boolean
|
|
262
|
+
value: unknown
|
|
263
|
+
}[] = []
|
|
264
|
+
const input = await assignOptions(options, document, {
|
|
265
|
+
async resolve(name, current) {
|
|
266
|
+
try {
|
|
267
|
+
return await resolvePath(
|
|
268
|
+
command.input,
|
|
269
|
+
name,
|
|
270
|
+
current,
|
|
271
|
+
async (target) => (await findCommand(target)?.load())?.input,
|
|
272
|
+
)
|
|
273
|
+
} catch (error) {
|
|
274
|
+
if (!(error instanceof UsageError)) throw error
|
|
275
|
+
return error
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
unresolved(name, errors) {
|
|
279
|
+
throw errors[0] ?? new UsageError(messages().diagnostics.unresolvedOption(command.name, name))
|
|
280
|
+
},
|
|
281
|
+
async assign(current, entry, path) {
|
|
282
|
+
const text = entry.text.startsWith('@@') ? entry.text.slice(1) : entry.text
|
|
283
|
+
const imported = entry.text.startsWith('@') && !entry.text.startsWith('@@')
|
|
284
|
+
let value: unknown
|
|
285
|
+
if (imported) value = await read(entry.text)
|
|
286
|
+
else {
|
|
287
|
+
try {
|
|
288
|
+
value = flagValue(path.schema, text)
|
|
289
|
+
} catch (error) {
|
|
290
|
+
if (!(error instanceof UsageError)) throw error
|
|
291
|
+
value = text
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
const result = assignPath(current, path, value)
|
|
295
|
+
assigned.push({ name: entry.name, text, imported, value })
|
|
296
|
+
return result
|
|
297
|
+
},
|
|
298
|
+
})
|
|
299
|
+
/**
|
|
300
|
+
* Named discriminators may select a different branch than the base document; decode against their final values.
|
|
301
|
+
*
|
|
302
|
+
* 具名判别字段可以改变基础文档的联合分支;叶子按最终判别值解码。
|
|
303
|
+
*/
|
|
304
|
+
const resolved: { path: InputPath; value: unknown }[] = []
|
|
305
|
+
for (const entry of assigned) {
|
|
306
|
+
const path = await resolvePath(
|
|
307
|
+
command.input,
|
|
308
|
+
entry.name,
|
|
309
|
+
input,
|
|
310
|
+
async (name) => (await findCommand(name)?.load())?.input,
|
|
311
|
+
)
|
|
312
|
+
if (path === undefined) throw new UsageError(messages().diagnostics.branchOption(entry.name))
|
|
313
|
+
resolved.push({
|
|
314
|
+
path,
|
|
315
|
+
value: entry.imported ? entry.value : flagValue(path.schema, entry.text),
|
|
316
|
+
})
|
|
317
|
+
}
|
|
318
|
+
let result = document
|
|
319
|
+
for (const entry of resolved.toSorted((a, b) => comparePaths(a.path, b.path))) {
|
|
320
|
+
result = assignPath(result, entry.path, entry.value)
|
|
321
|
+
}
|
|
322
|
+
return result
|
|
323
|
+
}
|