-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
af145b2
commit 6d59715
Showing
1 changed file
with
10 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
@@ -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); | ||
|
@@ -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 | ||
|