Skip to content

Commit

Permalink
cli: relax requirement of --network on indexer rules delete all
Browse files Browse the repository at this point in the history
  • Loading branch information
tilacog committed Jun 22, 2023
1 parent b88c8e1 commit 06d5bf9
Showing 1 changed file with 33 additions and 7 deletions.
40 changes: 33 additions & 7 deletions packages/indexer-cli/src/commands/indexer/rules/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import chalk from 'chalk'
import { loadValidatedConfig } from '../../../config'
import { createIndexerManagementClient } from '../../../client'
import {
requireProtocolNetworkOption,
extractProtocolNetworkOption,
fixParameters,
parseOutputFormat,
} from '../../../command-helpers'
Expand Down Expand Up @@ -44,8 +44,7 @@ module.exports = {
const config = loadValidatedConfig()

try {
const protocolNetwork = requireProtocolNetworkOption(parameters.options)
const chainAlias = resolveChainAlias(protocolNetwork)
const protocolNetwork = extractProtocolNetworkOption(parameters.options)
const [identifier, identifierType] = await processIdentifier(id, {
all: true,
global: true,
Expand All @@ -64,15 +63,40 @@ module.exports = {
global: true,
})
)[0]
return { identifier, protocolNetwork }

// All rules returned from `indexingRules` are have a `protocolNetwork` field, so we
// don't expect to see this error.
if (!rule.protocolNetwork) {
throw Error(
`Indexing Rule is missing a 'protocolNetwork' attribute: ${JSON.stringify(
rule,
)}`,
)
}

return {
identifier,
protocolNetwork: rule.protocolNetwork,
}
}),
)

/* eslint-disable @typescript-eslint/no-non-null-assertion */
await deleteIndexingRules(client, rulesIdentifiers)
/* eslint-enable @typescript-eslint/no-non-null-assertion */
print.success(`Deleted all indexing rules for network '${chainAlias}'`)
} else if (identifier === 'global') {
print.success('Deleted all indexing rules')
return
}

// Since we are not deleting all rules, we must require a protocol network from the user
if (!protocolNetwork) {
throw Error(
'The --netowrk option must be used when deleting a glboal Indexing Rule',
)
}
const chainAlias = resolveChainAlias(protocolNetwork)

if (identifier === 'global') {
const globalIdentifier = { identifier, protocolNetwork }
await deleteIndexingRules(client, [globalIdentifier])
print.warning(
Expand All @@ -81,7 +105,9 @@ module.exports = {
} else {
const ruleIdentifier = { identifier, protocolNetwork }
await deleteIndexingRules(client, [ruleIdentifier])
print.success(`Deleted indexing rules for "${identifier}" (${identifierType})`)
print.success(
`Deleted indexing rules for "${identifier}" (${identifierType}) on network: '${chainAlias}'`,
)
}
} catch (error) {
print.error(error.toString())
Expand Down

0 comments on commit 06d5bf9

Please sign in to comment.