Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/violet-bats-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@workflow/cli": patch
---

Add -i / --interactive flag for enabling pagination bindings, new default being off
1 change: 1 addition & 0 deletions packages/cli/src/commands/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function toInspectOptions(flags: any): InspectCLIOptions {
workflowName: flags.workflowName,
withData: flags.withData,
backend: flags.backend,
interactive: flags.interactive,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/cli/src/lib/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export type InspectCLIOptions = {
withData?: boolean;
backend?: string;
disableRelativeDates?: boolean;
interactive?: boolean;
};
8 changes: 8 additions & 0 deletions packages/cli/src/lib/inspect/flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,12 @@ export const cliFlags = {
helpLabel: '--limit',
helpValue: 'NUMBER',
}),
interactive: Flags.boolean({
description: 'Enable interactive pagination with keyboard controls',
required: false,
char: 'i',
default: false,
helpGroup: 'Output',
helpLabel: '-i, --interactive',
}),
};
4 changes: 4 additions & 0 deletions packages/cli/src/lib/inspect/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ export const listRuns = async (world: World, opts: InspectCLIOptions = {}) => {

await setupListPagination<WorkflowRun>({
initialCursor: opts.cursor,
interactive: opts.interactive,
fetchPage: async (cursor) => {
try {
const runs = await world.runs.list({
Expand Down Expand Up @@ -680,6 +681,7 @@ export const listSteps = async (

await setupListPagination<Step>({
initialCursor: opts.cursor,
interactive: opts.interactive,
fetchPage: async (cursor) => {
logger.debug(`Fetching steps for run ${runId}`);
try {
Expand Down Expand Up @@ -888,6 +890,7 @@ export const listEvents = async (

await setupListPagination<Event>({
initialCursor: opts.cursor,
interactive: opts.interactive,
fetchPage: async (cursor) => {
logger.debug(`Fetching events for run ${filterId}`);
try {
Expand Down Expand Up @@ -957,6 +960,7 @@ export const listHooks = async (world: World, opts: InspectCLIOptions = {}) => {
// Setup pagination with new mechanism
await setupListPagination<Hook>({
initialCursor: opts.cursor,
interactive: opts.interactive,
fetchPage: async (cursor) => {
if (!runId) {
logger.debug('Fetching all hooks');
Expand Down
25 changes: 20 additions & 5 deletions packages/cli/src/lib/inspect/pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ export interface ListPaginationOptions<TData> {
* Optional callback for when fetching starts
*/
onFetchStart?: (pageIndex: number) => void;

/**
* Enable interactive pagination with keyboard controls
*/
interactive?: boolean;
}

/**
Expand All @@ -151,7 +156,11 @@ export interface ListPaginationOptions<TData> {
export async function setupListPagination<TData>(
options: ListPaginationOptions<TData>
): Promise<void> {
const { initialCursor, fetchPage, displayPage, onFetchStart } = options;
const { initialCursor, fetchPage, displayPage, onFetchStart, interactive } =
options;

// Interactive mode requires both TTY support and explicit --interactive flag
const enableInteractive = interactive && isInteractive();

// Pages stack - stores all fetched pages
const pages: PageData<TData>[] = [];
Expand All @@ -172,7 +181,7 @@ export async function setupListPagination<TData>(
pageIndex = index;

// Clear screen for subsequent pages in interactive mode
if (isInteractive()) {
if (enableInteractive) {
console.clear();
}

Expand All @@ -183,7 +192,13 @@ export async function setupListPagination<TData>(
// Fetch and display first page
const firstPage = await showPage(0, initialCursor);

if (!isInteractive()) {
// In non-interactive mode, show info if there are more pages
if (!enableInteractive) {
if (firstPage.hasMore) {
logger.info(
'\nMore results available. Use --interactive (-i) to paginate through results.'
);
}
return;
}

Expand All @@ -208,7 +223,7 @@ export async function setupListPagination<TData>(
pageIndex = newPageIndex;
const cachedPage = pages[newPageIndex];

if (isInteractive()) {
if (enableInteractive) {
console.clear();
}

Expand Down Expand Up @@ -257,7 +272,7 @@ export async function setupListPagination<TData>(
pageIndex--;
const prevPage = pages[pageIndex];

if (isInteractive()) {
if (enableInteractive) {
console.clear();
}

Expand Down
Loading