@@ -4,27 +4,29 @@ import chalk from 'chalk'
44import { loadValidatedConfig } from '../../../config'
55import { createIndexerManagementClient } from '../../../client'
66import { fixParameters } from '../../../command-helpers'
7- import { deleteActions } from '../../../actions'
7+ import { deleteActions , fetchActions } from '../../../actions'
88
99const 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
1820module . 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