Skip to content

Commit 4172410

Browse files
Copilotvobu
andauthored
feat: add --between date range filtering to list and search commands (#105)
* Initial plan * feat: add --between date range filtering to list and search commands Co-authored-by: vobu <6573426+vobu@users.noreply.github.com> * test: add --between integration tests for all changed search and list resources Co-authored-by: vobu <6573426+vobu@users.noreply.github.com> * fix: remove jobs --between integration tests incompatible with Camunda 8.8 Co-authored-by: vobu <6573426+vobu@users.noreply.github.com> * fix: restore jobs --between tests with Camunda version skip, fix incident test race condition Co-authored-by: vobu <6573426+vobu@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: vobu <6573426+vobu@users.noreply.github.com>
1 parent 9839b9a commit 4172410

File tree

15 files changed

+572
-1
lines changed

15 files changed

+572
-1
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ jobs:
7070
7171
- name: Run integration tests
7272
run: npm run test:integration
73+
env:
74+
CAMUNDA_VERSION: ${{ matrix.camunda }}
7375

7476
- name: Stop Camunda
7577
if: always()

src/commands/completion.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ _c8ctl_completions() {
5050
local help_resources="list get create complete await search deploy run watch cancel resolve fail activate publish correlate upgrade downgrade init profiles profile plugin plugins"
5151
5252
# Global flags
53-
local flags="--help --version --profile --from --all --bpmnProcessId --id --processInstanceKey --processDefinitionKey --parentProcessInstanceKey --variables --state --assignee --type --correlationKey --timeToLive --maxJobsToActivate --timeout --worker --retries --errorMessage --baseUrl --clientId --clientSecret --audience --oAuthUrl --defaultTenantId --awaitCompletion --fetchVariables --requestTimeout --sortBy --asc --desc --limit --name --key --elementId --errorType --value --scopeKey --fullValue --userTask --ut --processDefinition --pd --iname --iid --iassignee --ierrorMessage --itype --ivalue"
53+
local flags="--help --version --profile --from --all --bpmnProcessId --id --processInstanceKey --processDefinitionKey --parentProcessInstanceKey --variables --state --assignee --type --correlationKey --timeToLive --maxJobsToActivate --timeout --worker --retries --errorMessage --baseUrl --clientId --clientSecret --audience --oAuthUrl --defaultTenantId --awaitCompletion --fetchVariables --requestTimeout --sortBy --asc --desc --limit --between --dateField --name --key --elementId --errorType --value --scopeKey --fullValue --userTask --ut --processDefinition --pd --iname --iid --iassignee --ierrorMessage --itype --ivalue"
5454
5555
case \${cword} in
5656
1)
@@ -237,6 +237,8 @@ _c8ctl() {
237237
'--asc[Sort in ascending order (default)]'
238238
'--desc[Sort in descending order]'
239239
'--limit[Maximum number of items to fetch]:number:'
240+
'--between[Filter by date range (from..to)]:range:'
241+
'--dateField[Date field to filter on with --between]:field:'
240242
'--name[Variable or resource name]:name:'
241243
'--key[Resource key]:key:'
242244
'--elementId[Element ID]:id:'
@@ -576,6 +578,10 @@ complete -c c8ctl -l desc -d 'Sort in descending order'
576578
complete -c c8 -l desc -d 'Sort in descending order'
577579
complete -c c8ctl -l limit -d 'Maximum number of items to fetch' -r
578580
complete -c c8 -l limit -d 'Maximum number of items to fetch' -r
581+
complete -c c8ctl -l between -d 'Filter by date range (from..to)' -r
582+
complete -c c8 -l between -d 'Filter by date range (from..to)' -r
583+
complete -c c8ctl -l dateField -d 'Date field to filter on with --between' -r
584+
complete -c c8 -l dateField -d 'Date field to filter on with --between' -r
579585
complete -c c8ctl -l name -d 'Variable or resource name' -r
580586
complete -c c8 -l name -d 'Variable or resource name' -r
581587
complete -c c8ctl -l key -d 'Resource key' -r

src/commands/help.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ Flags:
9595
--asc Sort in ascending order (default)
9696
--desc Sort in descending order
9797
--limit <n> Maximum number of items to fetch (default: 1000000)
98+
--between <from>..<to> Filter by date range (use with 'list' or 'search'; short dates YYYY-MM-DD or ISO 8601)
99+
--dateField <field> Date field to filter on with --between (default depends on resource)
98100
--version, -v Show version
99101
--help, -h Show help
100102
@@ -257,6 +259,8 @@ Resources and their available flags:
257259
--id <id> Filter by process definition ID (alias: --bpmnProcessId)
258260
--state <state> Filter by state (ACTIVE, COMPLETED, etc.)
259261
--all List all instances (pagination)
262+
--between <from>..<to> Filter by date range (default field: startDate)
263+
--dateField <field> Date field for --between (startDate, endDate)
260264
--sortBy <column> Sort by column (Key, Process ID, State, Version, Start Date, Tenant ID)
261265
--asc Sort in ascending order (default)
262266
--desc Sort in descending order
@@ -275,6 +279,8 @@ Resources and their available flags:
275279
--state <state> Filter by state (CREATED, COMPLETED, etc.)
276280
--assignee <name> Filter by assignee
277281
--all List all tasks (pagination)
282+
--between <from>..<to> Filter by date range (default field: creationDate)
283+
--dateField <field> Date field for --between (creationDate, completionDate, followUpDate, dueDate)
278284
--sortBy <column> Sort by column (Key, Name, State, Assignee, Created, Process Instance, Tenant ID)
279285
--asc Sort in ascending order (default)
280286
--desc Sort in descending order
@@ -284,6 +290,7 @@ Resources and their available flags:
284290
incidents (inc)
285291
--state <state> Filter by state (ACTIVE, RESOLVED, etc.)
286292
--processInstanceKey <key> Filter by process instance
293+
--between <from>..<to> Filter by date range (field: creationTime)
287294
--sortBy <column> Sort by column (Key, Type, Message, State, Created, Process Instance, Tenant ID)
288295
--asc Sort in ascending order (default)
289296
--desc Sort in descending order
@@ -293,6 +300,8 @@ Resources and their available flags:
293300
jobs
294301
--state <state> Filter by state (ACTIVATABLE, ACTIVATED, etc.)
295302
--type <type> Filter by job type
303+
--between <from>..<to> Filter by date range (default field: creationTime)
304+
--dateField <field> Date field for --between (creationTime, lastUpdateTime)
296305
--sortBy <column> Sort by column (Key, Type, State, Retries, Created, Process Instance, Tenant ID)
297306
--asc Sort in ascending order (default)
298307
--desc Sort in descending order
@@ -308,13 +317,18 @@ Resources and their available flags:
308317
309318
Examples:
310319
c8ctl list pi --state=ACTIVE
320+
c8ctl list pi --between=2024-01-01..2024-12-31
321+
c8ctl list pi --between=2024-01-01T00:00:00Z..2024-06-30T23:59:59Z --dateField=endDate
311322
c8ctl list pi --sortBy=State
312323
c8ctl list pi --sortBy=State --desc
313324
c8ctl list ut --assignee=john.doe
325+
c8ctl list ut --between=2024-01-01..2024-03-31 --dateField=dueDate
314326
c8ctl list ut --sortBy=Assignee
315327
c8ctl list inc --processInstanceKey=123456
328+
c8ctl list inc --between=2024-06-01..2024-06-30
316329
c8ctl list inc --sortBy=Type --desc
317330
c8ctl list jobs --type=email-service
331+
c8ctl list jobs --between=2024-01-01..2024-12-31
318332
c8ctl list jobs --sortBy=Retries --asc
319333
c8ctl list profiles
320334
c8ctl list plugins
@@ -534,6 +548,8 @@ Resources and their available flags:
534548
--state <state> Filter by state (ACTIVE, COMPLETED, etc.)
535549
--key <key> Filter by key
536550
--parentProcessInstanceKey <key> Filter by parent process instance key
551+
--between <from>..<to> Filter by date range (default field: startDate)
552+
--dateField <field> Date field for --between (startDate, endDate)
537553
--sortBy <column> Sort by column (Key, Process ID, State, Version, Tenant ID)
538554
--asc Sort in ascending order (default)
539555
--desc Sort in descending order
@@ -557,6 +573,8 @@ Resources and their available flags:
557573
--processInstanceKey <key> Filter by process instance key
558574
--processDefinitionKey <key> Filter by process definition key
559575
--elementId <id> Filter by element ID
576+
--between <from>..<to> Filter by date range (default field: creationDate)
577+
--dateField <field> Date field for --between (creationDate, completionDate, followUpDate, dueDate)
560578
--sortBy <column> Sort by column (Key, Name, State, Assignee, Process Instance, Tenant ID)
561579
--asc Sort in ascending order (default)
562580
--desc Sort in descending order
@@ -571,6 +589,7 @@ Resources and their available flags:
571589
--errorType <type> Filter by error type
572590
--errorMessage <msg> Filter by error message
573591
--ierrorMessage <pattern> Case-insensitive --errorMessage filter
592+
--between <from>..<to> Filter by date range (field: creationTime)
574593
--sortBy <column> Sort by column (Key, Type, Message, State, Process Instance, Tenant ID)
575594
--asc Sort in ascending order (default)
576595
--desc Sort in descending order
@@ -582,6 +601,8 @@ Resources and their available flags:
582601
--itype <pattern> Case-insensitive --type filter
583602
--processInstanceKey <key> Filter by process instance key
584603
--processDefinitionKey <key> Filter by process definition key
604+
--between <from>..<to> Filter by date range (default field: creationTime)
605+
--dateField <field> Date field for --between (creationTime, lastUpdateTime)
585606
--sortBy <column> Sort by column (Key, Type, State, Retries, Process Instance, Tenant ID)
586607
--asc Sort in ascending order (default)
587608
--desc Sort in descending order
@@ -601,6 +622,14 @@ Resources and their available flags:
601622
--limit <n> Maximum number of items to fetch (default: 1000000)
602623
--profile <name> Use specific profile
603624
625+
Date Range Filter:
626+
Use --between <from>..<to> to filter results by a date range.
627+
Dates can be short (YYYY-MM-DD) or full ISO 8601 datetimes.
628+
Short dates: 'from' is expanded to T00:00:00.000Z, 'to' to T23:59:59.999Z.
629+
Use --dateField to specify which date field to filter on (default depends on resource).
630+
Example: --between=2024-01-01..2024-12-31
631+
Example: --between=2024-01-01T00:00:00Z..2024-06-30T23:59:59Z --dateField=endDate
632+
604633
Wildcard Search:
605634
String filters support wildcards: * (any chars) and ? (single char).
606635
Example: --name='*main*' matches all names containing "main".
@@ -613,15 +642,20 @@ Case-Insensitive Search:
613642
Examples:
614643
c8ctl search pi --state=ACTIVE
615644
c8ctl search pi --bpmnProcessId=order-process
645+
c8ctl search pi --between=2024-01-01..2024-12-31
646+
c8ctl search pi --between=2024-01-01..2024-06-30 --dateField=endDate
616647
c8ctl search pd --name='*main*'
617648
c8ctl search pd --iname='*order*'
618649
c8ctl search pd --sortBy=Name --desc
619650
c8ctl search ut --assignee=john.doe
620651
c8ctl search ut --iassignee=John
652+
c8ctl search ut --between=2024-01-01..2024-03-31 --dateField=dueDate
621653
c8ctl search ut --sortBy=State --asc
622654
c8ctl search inc --state=ACTIVE --processInstanceKey=123456
655+
c8ctl search inc --between=2024-06-01..2024-06-30
623656
c8ctl search jobs --type=email-service
624657
c8ctl search jobs --itype='*SERVICE*'
658+
c8ctl search jobs --between=2024-01-01..2024-12-31
625659
c8ctl search jobs --sortBy=Type --desc
626660
c8ctl search variables --name=orderId
627661
c8ctl search variables --value=12345 --fullValue

src/commands/incidents.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getLogger } from '../logger.ts';
66
import { sortTableData, type SortOrder } from '../logger.ts';
77
import { createClient, fetchAllPages } from '../client.ts';
88
import { resolveTenantId } from '../config.ts';
9+
import { parseBetween, buildDateFilter } from '../date-filter.ts';
910

1011
/**
1112
* List incidents
@@ -17,6 +18,7 @@ export async function listIncidents(options: {
1718
sortBy?: string;
1819
sortOrder?: SortOrder;
1920
limit?: number;
21+
between?: string;
2022
}): Promise<void> {
2123
const logger = getLogger();
2224
const client = createClient(options.profile);
@@ -37,6 +39,16 @@ export async function listIncidents(options: {
3739
filter.filter.processInstanceKey = options.processInstanceKey;
3840
}
3941

42+
if (options.between) {
43+
const parsed = parseBetween(options.between);
44+
if (parsed) {
45+
filter.filter.creationTime = buildDateFilter(parsed.from, parsed.to);
46+
} else {
47+
logger.error('Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31 or ISO 8601 datetimes)');
48+
process.exit(1);
49+
}
50+
}
51+
4052
const allItems = await fetchAllPages(
4153
(f, opts) => client.searchIncidents(f, opts),
4254
filter,

src/commands/jobs.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getLogger } from '../logger.ts';
66
import { sortTableData, type SortOrder } from '../logger.ts';
77
import { createClient, fetchAllPages } from '../client.ts';
88
import { resolveTenantId } from '../config.ts';
9+
import { parseBetween, buildDateFilter } from '../date-filter.ts';
910

1011
/**
1112
* List jobs
@@ -17,6 +18,8 @@ export async function listJobs(options: {
1718
sortBy?: string;
1819
sortOrder?: SortOrder;
1920
limit?: number;
21+
between?: string;
22+
dateField?: string;
2023
}): Promise<void> {
2124
const logger = getLogger();
2225
const client = createClient(options.profile);
@@ -37,6 +40,17 @@ export async function listJobs(options: {
3740
filter.filter.type = options.type;
3841
}
3942

43+
if (options.between) {
44+
const parsed = parseBetween(options.between);
45+
if (parsed) {
46+
const field = options.dateField ?? 'creationTime';
47+
filter.filter[field] = buildDateFilter(parsed.from, parsed.to);
48+
} else {
49+
logger.error('Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31 or ISO 8601 datetimes)');
50+
process.exit(1);
51+
}
52+
}
53+
4054
const allItems = await fetchAllPages(
4155
(f, opts) => client.searchJobs(f, opts),
4256
filter,

src/commands/process-instances.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getLogger } from '../logger.ts';
66
import { sortTableData, type SortOrder } from '../logger.ts';
77
import { createClient, fetchAllPages } from '../client.ts';
88
import { resolveTenantId } from '../config.ts';
9+
import { parseBetween, buildDateFilter } from '../date-filter.ts';
910
import type { ProcessInstanceCreationInstructionById } from '@camunda8/orchestration-cluster-api';
1011

1112
/**
@@ -19,6 +20,8 @@ export async function listProcessInstances(options: {
1920
sortBy?: string;
2021
sortOrder?: SortOrder;
2122
limit?: number;
23+
between?: string;
24+
dateField?: string;
2225
}): Promise<{ items: Array<Record<string, unknown>>; total?: number } | undefined> {
2326
const logger = getLogger();
2427
const client = createClient(options.profile);
@@ -42,6 +45,17 @@ export async function listProcessInstances(options: {
4245
filter.filter.state = 'ACTIVE';
4346
}
4447

48+
if (options.between) {
49+
const parsed = parseBetween(options.between);
50+
if (parsed) {
51+
const field = options.dateField ?? 'startDate';
52+
filter.filter[field] = buildDateFilter(parsed.from, parsed.to);
53+
} else {
54+
logger.error('Invalid --between value. Expected format: <from>..<to> (e.g. 2024-01-01..2024-12-31 or ISO 8601 datetimes)');
55+
process.exit(1);
56+
}
57+
}
58+
4559
const allItems = await fetchAllPages(
4660
(f, opts) => client.searchProcessInstances(f, opts),
4761
filter,

0 commit comments

Comments
 (0)