Skip to content

Commit

Permalink
Don't exit the process immediately when rendering non-JSON orders list
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JohnPhamous committed Jan 3, 2025
1 parent af145b2 commit 6d59715
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/lib/orders/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type { Command } from "commander";
import dayjs from "dayjs";
import { render } from "ink";
import duration from "npm:[email protected]/plugin/duration.js";
import relativeTime from "npm:[email protected]/plugin/relativeTime.js";
import React from "react";
import { getAuthToken, isLoggedIn } from "../../helpers/config.ts";
import {
logAndQuit,
Expand All @@ -10,11 +12,9 @@ import {
} from "../../helpers/errors.ts";
import { fetchAndHandleErrors } from "../../helpers/fetch.ts";
import { getApiUrl } from "../../helpers/urls.ts";
import { render, Text } from "ink";
import { parseStartAsDate } from "../buy/index.tsx";
import { OrderDisplay } from "./OrderDisplay.tsx";
import type { HydratedOrder, ListResponseBody } from "./types.ts";
import React from "react";
import { parseStartAsDate } from "../buy/index.tsx";

dayjs.extend(relativeTime);
dayjs.extend(duration);
Expand Down Expand Up @@ -169,11 +169,16 @@ export function registerOrders(program: Command) {

if (options.json) {
console.log(JSON.stringify(sortedOrders, null, 2));
process.exit(0);
} else {
render(<OrderDisplay orders={sortedOrders} />);
}

process.exit(0);
// Automatically exit the process if there are no orders
// Otherwise leave the process running so the user can interact (scroll) to see the orders
if (sortedOrders.length === 0) {
process.exit(0);
}
}
});

ordersCommand
Expand Down

0 comments on commit 6d59715

Please sign in to comment.