Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aos): if multiple processes have the same name, allow user to select which process to run #391

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading