Skip to content

Commit

Permalink
Merge pull request #391 from permaweb/jfrain99/select-from-processes-…
Browse files Browse the repository at this point in the history
…with-same-name

feat(aos): if multiple processes have the same name, allow user to select which process to run
  • Loading branch information
twilson63 authored Nov 14, 2024
2 parents 5a42340 + 7a55031 commit 8f911a3
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions src/register.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -150,7 +172,7 @@ export function register(jwk, services) {
if (!ctx.ok) return Rejected(ctx)
return findModule(ctx).chain(createProcess)
},
alreadyRegistered
fromPromise(alreadyRegistered)
)

}
Expand Down Expand Up @@ -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"] },
Expand All @@ -197,6 +219,10 @@ function queryForAOS(name) {
edges {
node {
id
tags {
name
value
}
}
}
}
Expand Down

0 comments on commit 8f911a3

Please sign in to comment.