Skip to content

Commit eefffca

Browse files
committed
refactor(cli): organize get-groups command code
1 parent 4ddf75b commit eefffca

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

packages/cli/src/index.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,39 +108,34 @@ program
108108
return
109109
}
110110

111-
let queryData
111+
let groupIds
112112

113113
const spinner = new Spinner("Fetching groups")
114-
115-
const getGroupIds = async () => {
116-
const groupIds = await queryData.getGroupIds()
117-
118-
spinner.stop()
119-
120-
if (groupIds.length === 0) {
121-
console.info(`\n ${logSymbols.info}`, "info: there are no groups in this network\n")
122-
return
123-
}
124-
125-
const content = `\n${groupIds.map((id: any) => ` - ${id}`).join("\n")}`
126-
127-
console.info(`${content}\n`)
128-
}
129-
130114
spinner.start()
131115

132116
try {
133-
queryData = new SemaphoreSubgraph(network)
134-
await getGroupIds()
117+
const semaphoreSubgraph = new SemaphoreSubgraph(network)
118+
groupIds = await semaphoreSubgraph.getGroupIds()
119+
spinner.stop()
135120
} catch (error) {
136121
try {
137-
queryData = new SemaphoreEthers(network)
138-
await getGroupIds()
122+
const semaphoreEthers = new SemaphoreEthers(network)
123+
groupIds = await semaphoreEthers.getGroupIds()
124+
spinner.stop()
139125
} catch {
140126
spinner.stop()
141127
console.info(`\n ${logSymbols.error}`, "error: unexpected error with the SemaphoreEthers package")
128+
return
142129
}
143130
}
131+
if (groupIds.length === 0) {
132+
console.info(`\n ${logSymbols.info}`, "info: there are no groups in this network\n")
133+
return
134+
}
135+
136+
const content = `\n${groupIds.map((id: any) => ` - ${id}`).join("\n")}`
137+
138+
console.info(`${content}\n`)
144139
})
145140

146141
program

0 commit comments

Comments
 (0)