Skip to content

Commit 6d59715

Browse files
committed
Don't exit the process immediately when rendering non-JSON orders list
Since we're adding interactivity (scrolling) to the orders, we want to exit the process based on user action instead of after command is finished running
1 parent af145b2 commit 6d59715

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/lib/orders/index.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import type { Command } from "commander";
22
import dayjs from "dayjs";
3+
import { render } from "ink";
34
import duration from "npm:[email protected]/plugin/duration.js";
45
import relativeTime from "npm:[email protected]/plugin/relativeTime.js";
6+
import React from "react";
57
import { getAuthToken, isLoggedIn } from "../../helpers/config.ts";
68
import {
79
logAndQuit,
@@ -10,11 +12,9 @@ import {
1012
} from "../../helpers/errors.ts";
1113
import { fetchAndHandleErrors } from "../../helpers/fetch.ts";
1214
import { getApiUrl } from "../../helpers/urls.ts";
13-
import { render, Text } from "ink";
15+
import { parseStartAsDate } from "../buy/index.tsx";
1416
import { OrderDisplay } from "./OrderDisplay.tsx";
1517
import type { HydratedOrder, ListResponseBody } from "./types.ts";
16-
import React from "react";
17-
import { parseStartAsDate } from "../buy/index.tsx";
1818

1919
dayjs.extend(relativeTime);
2020
dayjs.extend(duration);
@@ -169,11 +169,16 @@ export function registerOrders(program: Command) {
169169

170170
if (options.json) {
171171
console.log(JSON.stringify(sortedOrders, null, 2));
172+
process.exit(0);
172173
} else {
173174
render(<OrderDisplay orders={sortedOrders} />);
174-
}
175175

176-
process.exit(0);
176+
// Automatically exit the process if there are no orders
177+
// Otherwise leave the process running so the user can interact (scroll) to see the orders
178+
if (sortedOrders.length === 0) {
179+
process.exit(0);
180+
}
181+
}
177182
});
178183

179184
ordersCommand

0 commit comments

Comments
 (0)