Skip to content

Commit 670f8fc

Browse files
hopeyenfordN
authored andcommitted
indexer-cli: add delete options all and status filter
1 parent d820a46 commit 670f8fc

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

packages/indexer-cli/src/__tests__/references/indexer-actions.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Manage indexer actions
44
indexer actions queue Queue an action item
55
indexer actions get List one or more actions
66
indexer actions execute Execute approved items in the action queue
7-
indexer actions delete Delete an item in the queue
7+
indexer actions delete Delete one or many actions in the queue
88
indexer actions cancel Cancel an item in the queue
99
indexer actions approve Approve an action item
1010
indexer actions Manage indexer actions

packages/indexer-cli/src/__tests__/references/indexer-help.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Manage indexer configuration
2626
indexer actions queue Queue an action item
2727
indexer actions get List one or more actions
2828
indexer actions execute Execute approved items in the action queue
29-
indexer actions delete Delete an item in the queue
29+
indexer actions delete Delete one or many actions in the queue
3030
indexer actions cancel Cancel an item in the queue
3131
indexer actions approve Approve an action item
3232
indexer actions Manage indexer actions

packages/indexer-cli/src/commands/indexer/actions/delete.ts

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,29 @@ import chalk from 'chalk'
44
import { loadValidatedConfig } from '../../../config'
55
import { createIndexerManagementClient } from '../../../client'
66
import { fixParameters } from '../../../command-helpers'
7-
import { deleteActions } from '../../../actions'
7+
import { deleteActions, fetchActions } from '../../../actions'
88

99
const HELP = `
10+
${chalk.bold('graph indexer actions delete')} [options] all
1011
${chalk.bold('graph indexer actions delete')} [options] [<actionID1> ...]
1112
1213
${chalk.dim('Options:')}
1314
14-
-h, --help Show usage information
15-
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
15+
-h, --help Show usage information
16+
--status queued|approved|pending|success|failed|canceled Filter by status
17+
-o, --output table|json|yaml Choose the output format: table (default), JSON, or YAML
1618
`
1719

1820
module.exports = {
1921
name: 'delete',
2022
alias: [],
21-
description: 'Delete an item in the queue',
23+
description: 'Delete one or many actions in the queue',
2224
run: async (toolbox: GluegunToolbox) => {
2325
const { print, parameters } = toolbox
2426

2527
const inputSpinner = toolbox.print.spin('Processing inputs')
2628

27-
const { h, help, o, output } = parameters.options
29+
const { status, h, help, o, output } = parameters.options
2830
const [...actionIDs] = fixParameters(parameters, { h, help }) || []
2931

3032
const outputFormat = o || output || 'table'
@@ -35,20 +37,37 @@ module.exports = {
3537
return
3638
}
3739

38-
let numericActionIDs: number[]
39-
4040
try {
4141
if (!['json', 'yaml', 'table'].includes(outputFormat)) {
4242
throw Error(
4343
`Invalid output format "${outputFormat}", must be one of ['json', 'yaml', 'table']`,
4444
)
4545
}
4646

47-
if (!actionIDs || actionIDs.length === 0) {
48-
throw Error(`Missing required argument: 'actionID'`)
47+
if (
48+
status &&
49+
!['queued', 'approved', 'pending', 'success', 'failed', 'canceled'].includes(
50+
status,
51+
)
52+
) {
53+
throw Error(
54+
`Invalid '--status' provided, must be one of ['queued', 'approved', 'pending', 'success', 'failed', 'canceled]`,
55+
)
56+
}
57+
58+
if (actionIDs[0] == 'all') {
59+
if (status || actionIDs.length > 1) {
60+
throw Error(
61+
`Invalid query, cannot specify '--status' filter or multiple ids in addition to 'action = all'`,
62+
)
63+
}
4964
}
5065

51-
numericActionIDs = actionIDs.map(action => +action)
66+
if (!status && (!actionIDs || actionIDs.length === 0)) {
67+
throw Error(
68+
`Required at least one argument: actionID(s), 'all', or '--status' filter`,
69+
)
70+
}
5271

5372
inputSpinner.succeed('Processed input parameters')
5473
} catch (error) {
@@ -63,6 +82,13 @@ module.exports = {
6382
const config = loadValidatedConfig()
6483
const client = await createIndexerManagementClient({ url: config.api })
6584

85+
const numericActionIDs: number[] =
86+
actionIDs[0] == 'all'
87+
? (await fetchActions(client, {})).map(action => action.id)
88+
: status
89+
? (await fetchActions(client, { status })).map(action => action.id)
90+
: actionIDs.map(action => +action)
91+
6692
const numDeleted = await deleteActions(client, numericActionIDs)
6793

6894
actionSpinner.succeed(`${numDeleted} actions deleted`)

0 commit comments

Comments
 (0)