-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d7fbebe
commit 2b8610b
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const Agora = require('../internal/agora/Agora') | ||
const output = require('ethernaut-common/src/ui/output') | ||
const similarity = require('string-similarity') | ||
|
||
require('../scopes/retro') | ||
.task('project', 'Information about a particular RetroPGF project') | ||
.addPositionalParam('name', 'The project name to query') | ||
.setAction(async ({ name }) => { | ||
try { | ||
let projects = await getProjects() | ||
|
||
const matches = similarity.findBestMatch( | ||
name, | ||
projects.map((p) => p.name), | ||
) | ||
|
||
if (!matches) { | ||
return output.resultBox('No project found') | ||
} | ||
|
||
const match = projects.find((p) => p.name === matches.bestMatch.target) | ||
|
||
return output.resultBox(JSON.stringify(match, null, 2)) | ||
} catch (err) { | ||
return output.errorBox(err) | ||
} | ||
}) | ||
|
||
async function getProjects() { | ||
const agora = new Agora() | ||
|
||
return agora.retro.projects() | ||
} |