From 7a5503172b873c50a1f3c8284ecdf8443af8fddb Mon Sep 17 00:00:00 2001 From: Jack Frain Date: Fri, 1 Nov 2024 15:31:45 -0400 Subject: [PATCH] feat(aos): if multiple processes have the same name, allow user to select which process to run --- src/register.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/register.js b/src/register.js index fb64ecc8..14a59942 100644 --- a/src/register.js +++ b/src/register.js @@ -123,7 +123,29 @@ export function register(jwk, services) { }) } - const alreadyRegistered = results => Resolved(results[0].node.id) + const alreadyRegistered = async (results) => { + if (results.length == 1) { + return Promise.resolve(results[0].node.id) + } + + const processes = results.map((r, i) => { + const version = r.node.tags.find(t => t.name == "aos-Version")?.value + return { + title: `${i + 1} - ${version} - ${r.node.id}`, + value: r.node.id + } + }) + return prompts({ + type: 'select', + name: 'process', + message: 'Please select a process', + choices: processes, + instructions: false + }) + .then(r => r.process) + .catch(() => Promise.reject({ ok: false, error: 'Error selecting process' })) + } + const argv = minimist(process.argv.slice(2)) const name = argv._[0] || 'default' @@ -150,7 +172,7 @@ export function register(jwk, services) { if (!ctx.ok) return Rejected(ctx) return findModule(ctx).chain(createProcess) }, - alreadyRegistered + fromPromise(alreadyRegistered) ) } @@ -186,7 +208,7 @@ export function register(jwk, services) { function queryForAOS(name) { return `query ($owners: [String!]!) { transactions( - first: 1, + first: 10, owners: $owners, tags: [ { name: "Data-Protocol", values: ["ao"] }, @@ -197,6 +219,10 @@ function queryForAOS(name) { edges { node { id + tags { + name + value + } } } }