From 39bd5653c96adbd263eaf45e4dd91c9cb898f6aa Mon Sep 17 00:00:00 2001 From: xeno097 Date: Tue, 5 Nov 2024 16:40:08 -0400 Subject: [PATCH 1/2] feat(cli): updated the runSingleChainSelectionStep function to use a search prompt instead of a select one --- typescript/cli/package.json | 1 + typescript/cli/src/config/hooks.ts | 2 +- typescript/cli/src/deploy/agent.ts | 2 +- typescript/cli/src/send/message.ts | 4 +- typescript/cli/src/send/transfer.ts | 4 +- typescript/cli/src/status/message.ts | 2 +- typescript/cli/src/utils/chains.ts | 20 ++++++++-- yarn.lock | 55 ++++++++++++++++++++++++++++ 8 files changed, 80 insertions(+), 10 deletions(-) diff --git a/typescript/cli/package.json b/typescript/cli/package.json index 7f885988cb..1f50f41724 100644 --- a/typescript/cli/package.json +++ b/typescript/cli/package.json @@ -11,6 +11,7 @@ "@inquirer/core": "9.0.10", "@inquirer/figures": "1.0.5", "@inquirer/prompts": "^3.0.0", + "@inquirer/search": "^3.0.1", "ansi-escapes": "^7.0.0", "asn1.js": "^5.4.1", "bignumber.js": "^9.1.1", diff --git a/typescript/cli/src/config/hooks.ts b/typescript/cli/src/config/hooks.ts index 0bfd8cb1f6..2be15dbd4d 100644 --- a/typescript/cli/src/config/hooks.ts +++ b/typescript/cli/src/config/hooks.ts @@ -270,7 +270,7 @@ async function getOwnerAndBeneficiary( async function selectIgpChains(context: CommandContext) { const localChain = await runSingleChainSelectionStep( context.chainMetadata, - 'Select local chain for IGP hook', + 'Select local chain for IGP hook:', ); const isTestnet = context.chainMetadata[localChain].isTestnet; const remoteChains = await runMultiChainSelectionStep({ diff --git a/typescript/cli/src/deploy/agent.ts b/typescript/cli/src/deploy/agent.ts index ca490fc5fb..70c2404dfa 100644 --- a/typescript/cli/src/deploy/agent.ts +++ b/typescript/cli/src/deploy/agent.ts @@ -24,7 +24,7 @@ export async function runKurtosisAgentDeploy({ if (!originChain) { originChain = await runSingleChainSelectionStep( context.chainMetadata, - 'Select the origin chain', + 'Select the origin chain:', ); } if (!relayChains) { diff --git a/typescript/cli/src/send/message.ts b/typescript/cli/src/send/message.ts index 430d3b7bcf..efcb5fa6cb 100644 --- a/typescript/cli/src/send/message.ts +++ b/typescript/cli/src/send/message.ts @@ -33,14 +33,14 @@ export async function sendTestMessage({ if (!origin) { origin = await runSingleChainSelectionStep( chainMetadata, - 'Select the origin chain', + 'Select the origin chain:', ); } if (!destination) { destination = await runSingleChainSelectionStep( chainMetadata, - 'Select the destination chain', + 'Select the destination chain:', ); } diff --git a/typescript/cli/src/send/transfer.ts b/typescript/cli/src/send/transfer.ts index a89eb6aa99..0fe1068ae8 100644 --- a/typescript/cli/src/send/transfer.ts +++ b/typescript/cli/src/send/transfer.ts @@ -53,14 +53,14 @@ export async function sendTestTransfer({ if (!origin) { origin = await runSingleChainSelectionStep( chainMetadata, - 'Select the origin chain', + 'Select the origin chain:', ); } if (!destination) { destination = await runSingleChainSelectionStep( chainMetadata, - 'Select the destination chain', + 'Select the destination chain:', ); } diff --git a/typescript/cli/src/status/message.ts b/typescript/cli/src/status/message.ts index 2c1e9af96c..678e5428e9 100644 --- a/typescript/cli/src/status/message.ts +++ b/typescript/cli/src/status/message.ts @@ -27,7 +27,7 @@ export async function checkMessageStatus({ if (!origin) { origin = await runSingleChainSelectionStep( context.chainMetadata, - 'Select the origin chain', + 'Select the origin chain:', ); } diff --git a/typescript/cli/src/utils/chains.ts b/typescript/cli/src/utils/chains.ts index add11203d0..e77bae7fcc 100644 --- a/typescript/cli/src/utils/chains.ts +++ b/typescript/cli/src/utils/chains.ts @@ -1,4 +1,5 @@ import { Separator, confirm } from '@inquirer/prompts'; +import search from '@inquirer/search'; import select from '@inquirer/select'; import chalk from 'chalk'; @@ -23,9 +24,20 @@ export async function runSingleChainSelectionStep( chainMetadata, networkType, ); - const chain = (await select({ + + const options = [networkTypeSeparator, ...choices]; + const chain = (await search({ message, - choices: [networkTypeSeparator, ...choices], + source: (searchTerm) => { + if (!searchTerm) { + return options; + } + + return options.filter( + (value) => + Separator.isSeparator(value) || value.value.includes(searchTerm), + ); + }, pageSize: calculatePageSize(2), })) as string; handleNewChain([chain]); @@ -142,7 +154,9 @@ function getChainChoices( networkType: 'mainnet' | 'testnet', ) { const chainsToChoices = (chains: ChainMetadata[]) => - chains.map((c) => ({ name: c.name, value: c.name })); + chains + .map((c) => ({ name: c.name, value: c.name })) + .sort((a, b) => a.name.localeCompare(b.name)); const chains = Object.values(chainMetadata); const filteredChains = chains.filter((c) => diff --git a/yarn.lock b/yarn.lock index 71c573b5cc..1a8535d3b6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7829,6 +7829,7 @@ __metadata: "@inquirer/core": "npm:9.0.10" "@inquirer/figures": "npm:1.0.5" "@inquirer/prompts": "npm:^3.0.0" + "@inquirer/search": "npm:^3.0.1" "@types/chai-as-promised": "npm:^8" "@types/mocha": "npm:^10.0.1" "@types/node": "npm:^18.14.5" @@ -8232,6 +8233,23 @@ __metadata: languageName: node linkType: hard +"@inquirer/core@npm:^10.0.1": + version: 10.0.1 + resolution: "@inquirer/core@npm:10.0.1" + dependencies: + "@inquirer/figures": "npm:^1.0.7" + "@inquirer/type": "npm:^3.0.0" + ansi-escapes: "npm:^4.3.2" + cli-width: "npm:^4.1.0" + mute-stream: "npm:^2.0.0" + signal-exit: "npm:^4.1.0" + strip-ansi: "npm:^6.0.1" + wrap-ansi: "npm:^6.2.0" + yoctocolors-cjs: "npm:^2.1.2" + checksum: 368f78110e3b9f1370a45047a24b5cc4ef41fe2b7f2d82080de15d9bfb7ee3ff90494e0c138d1cca1b480c2cfb21914da8e9706b09620ea2e314860f98938393 + languageName: node + linkType: hard + "@inquirer/core@npm:^3.0.0": version: 3.0.0 resolution: "@inquirer/core@npm:3.0.0" @@ -8307,6 +8325,13 @@ __metadata: languageName: node linkType: hard +"@inquirer/figures@npm:^1.0.7": + version: 1.0.7 + resolution: "@inquirer/figures@npm:1.0.7" + checksum: ce896860de9d822a7c2a212667bcfd0f04cf2ce86d9a2411cc9c077bb59cd61732cb5f72ac66e88d52912466eec433f005bf8a25efa658f41e1a32f3977080bd + languageName: node + linkType: hard + "@inquirer/input@npm:^1.2.5": version: 1.2.5 resolution: "@inquirer/input@npm:1.2.5" @@ -8429,6 +8454,20 @@ __metadata: languageName: node linkType: hard +"@inquirer/search@npm:^3.0.1": + version: 3.0.1 + resolution: "@inquirer/search@npm:3.0.1" + dependencies: + "@inquirer/core": "npm:^10.0.1" + "@inquirer/figures": "npm:^1.0.7" + "@inquirer/type": "npm:^3.0.0" + yoctocolors-cjs: "npm:^2.1.2" + peerDependencies: + "@types/node": ">=18" + checksum: bdea5b2659ccd91b9c91ee355d32d92061127b5f871837c91e709e8b8dfbd531b3dac312d4d0fe7454594ff6d9fbda4194edce6e52ba6bb4b91a65850e0948bb + languageName: node + linkType: hard + "@inquirer/select@npm:^1.2.5": version: 1.2.5 resolution: "@inquirer/select@npm:1.2.5" @@ -8471,6 +8510,15 @@ __metadata: languageName: node linkType: hard +"@inquirer/type@npm:^3.0.0": + version: 3.0.0 + resolution: "@inquirer/type@npm:3.0.0" + peerDependencies: + "@types/node": ">=18" + checksum: fd4c265f0ed03e8da7ae2972c4e6b81932f535d9dd1e039e9e52b027cb8b72ae3c3309a3383ba513a8d3ae626de7dd3634387775cbdcbd100155ecbcaa65a657 + languageName: node + linkType: hard + "@isaacs/cliui@npm:^8.0.2": version: 8.0.2 resolution: "@isaacs/cliui@npm:8.0.2" @@ -25003,6 +25051,13 @@ __metadata: languageName: node linkType: hard +"mute-stream@npm:^2.0.0": + version: 2.0.0 + resolution: "mute-stream@npm:2.0.0" + checksum: d2e4fd2f5aa342b89b98134a8d899d8ef9b0a6d69274c4af9df46faa2d97aeb1f2ce83d867880d6de63643c52386579b99139801e24e7526c3b9b0a6d1e18d6c + languageName: node + linkType: hard + "mz@npm:^2.7.0": version: 2.7.0 resolution: "mz@npm:2.7.0" From 87e8e3ea25ffc07a199faf665fc5e0d06a6229af Mon Sep 17 00:00:00 2001 From: xeno097 Date: Tue, 5 Nov 2024 16:49:12 -0400 Subject: [PATCH 2/2] docs(changeset): Update single chain selection to be searchable instead of a simple select --- .changeset/yellow-icons-do.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/yellow-icons-do.md diff --git a/.changeset/yellow-icons-do.md b/.changeset/yellow-icons-do.md new file mode 100644 index 0000000000..c8e5a583ed --- /dev/null +++ b/.changeset/yellow-icons-do.md @@ -0,0 +1,5 @@ +--- +'@hyperlane-xyz/cli': minor +--- + +Update single chain selection to be searchable instead of a simple select