Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks for mutually-exclusive sf orders ls flags #66

Merged
merged 10 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ jobs:

steps:
- uses: actions/checkout@v2
- uses: denoland/setup-deno@v2
- run: deno install
- run: deno fmt --check
- run: deno check ./src/index.ts
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ sf --version # 0.1.0
- Test changes with
- `deno run devv` to test against local API
- `deno run prod` to test against production API
- The `deno run <env>` is an alias to the user facing `sf` command. So if you wanted to run `sf login` locally against the local API, run `deno run devv login`
- The `deno run <env>` is an alias to the user facing `sf` command. So if you
wanted to run `sf login` locally against the local API, run
`deno run devv login`

## New Release

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@
"typescript": "^5.6.2"
},
"version": "0.1.35"
}
}
6 changes: 3 additions & 3 deletions src/checkVersion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ async function checkProductionCLIVersion() {
// Fetch from network
try {
const response = await fetch(
"https://raw.githubusercontent.com/sfcompute/cli/refs/heads/main/package.json"
"https://raw.githubusercontent.com/sfcompute/cli/refs/heads/main/package.json",
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
Expand Down Expand Up @@ -102,7 +102,7 @@ export async function checkVersion() {

if (isPatchUpdate) {
console.log(
chalk.cyan(`Automatically upgrading ${version} → ${latestVersion}`)
chalk.cyan(`Automatically upgrading ${version} → ${latestVersion}`),
);
try {
execSync("sf upgrade", { stdio: "inherit" });
Expand Down Expand Up @@ -130,7 +130,7 @@ Run 'sf upgrade' to update to the latest version
padding: 1,
borderColor: "yellow",
borderStyle: "round",
})
}),
);
}
}
2 changes: 1 addition & 1 deletion src/helpers/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ConfigDefaults = process.env.IS_DEVELOPMENT_CLI_ENV
// --

export async function saveConfig(
config: Partial<Config>
config: Partial<Config>,
): Promise<{ success: boolean }> {
const configPath = getConfigPath();
const configDir = join(homedir(), ".sfcompute");
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export function logLoginMessageAndQuit(): never {
export async function logSessionTokenExpiredAndQuit(): Promise<never> {
await clearAuthFromConfig();
logAndQuit(
`\nYour session has expired. Please login again.\n\n\t$ ${loginCommand}\n`
`\nYour session has expired. Please login again.\n\n\t$ ${loginCommand}\n`,
);
}

export function failedToConnect(): never {
logAndQuit(
"Failed to connect to the server. Please check your internet connection and try again."
"Failed to connect to the server. Please check your internet connection and try again.",
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/helpers/price.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export function pricePerGPUHourToTotalPriceCents(
pricePerGPUHourCents: Cents,
durationSeconds: number,
nodes: number,
gpusPerNode: number
gpusPerNode: number,
): Cents {
const totalGPUs = nodes * gpusPerNode;
const totalHours = durationSeconds / 3600;
Expand All @@ -16,7 +16,7 @@ export function totalPriceToPricePerGPUHour(
priceCents: number,
durationSeconds: number,
nodes: number,
gpusPerNode: number
gpusPerNode: number,
): Cents {
const totalGPUs = nodes * gpusPerNode;
const totalHours = durationSeconds / 3600;
Expand Down
9 changes: 5 additions & 4 deletions src/helpers/units.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export function roundStartDate(startDate: Date): Date {

export function computeApproximateDurationSeconds(
startDate: Date | "NOW",
endDate: Date
endDate: Date,
): number {
const startEpoch =
startDate === "NOW" ? currentEpoch() : dateToEpoch(startDate);
const startEpoch = startDate === "NOW"
? currentEpoch()
: dateToEpoch(startDate);
const endEpoch = dateToEpoch(endDate);
return dayjs(epochToDate(endEpoch)).diff(dayjs(epochToDate(startEpoch)), "s");
}
Expand All @@ -57,7 +58,7 @@ interface PriceWholeToCentsReturn {
invalid: boolean;
}
export function priceWholeToCents(
price: string | number
price: string | number,
): PriceWholeToCentsReturn {
if (
price === null ||
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/urls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const apiPaths = {

export async function getWebAppUrl(
key: keyof typeof webPaths,
params?: any
params?: any,
): Promise<string> {
const config = await loadConfig();
const path = webPaths[key];
Expand All @@ -51,7 +51,7 @@ export async function getWebAppUrl(

export async function getApiUrl(
key: keyof typeof apiPaths,
params?: any
params?: any,
): Promise<string> {
const config = await loadConfig();
const path = apiPaths[key];
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/waitingForOrder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getOrder } from "./fetchers.ts";

export async function waitForOrderToNotBePending(orderId: string) {
const spinner = ora(
`Order ${orderId} - pending (this can take a moment)`
`Order ${orderId} - pending (this can take a moment)`,
).start();

// 1 minute
Expand All @@ -18,7 +18,7 @@ export async function waitForOrderToNotBePending(orderId: string) {
spinner.succeed();
return order;
}
await new Promise(resolve => setTimeout(resolve, 500));
await new Promise((resolve) => setTimeout(resolve, 500));
}

spinner.fail();
Expand Down
12 changes: 7 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { registerDev } from "./lib/dev.ts";
import { registerLogin } from "./lib/login.ts";
import { registerMe } from "./lib/me.ts";
import { registerOrders } from "./lib/orders/index.tsx";
import { IS_TRACKING_DISABLED, analytics } from "./lib/posthog.ts";
import { analytics, IS_TRACKING_DISABLED } from "./lib/posthog.ts";
import { registerSell } from "./lib/sell.ts";
import { registerTokens } from "./lib/tokens.ts";
import { registerScale } from "./lib/updown.tsx";
Expand Down Expand Up @@ -68,7 +68,7 @@ const main = async () => {
}
}

program.exitOverride(error => {
program.exitOverride((error) => {
let isError = true;

switch (error.code) {
Expand All @@ -91,8 +91,8 @@ const main = async () => {
const nextArg = arr[i + 1];
if (nextArg && !nextArg.startsWith("-")) {
(acc as Record<string, string | number | boolean>)[key] = isNaN(
Number(nextArg)
)
Number(nextArg),
)
? nextArg
: Number(nextArg);
} else {
Expand All @@ -103,7 +103,9 @@ const main = async () => {
}, {});

analytics.track({
event: `${process.argv[2] || "unknown"}${process.argv[3] ? "_" + process.argv[3] : ""}`,
event: `${process.argv[2] || "unknown"}${
process.argv[3] ? "_" + process.argv[3] : ""
}`,
properties: {
...args,
shell: process.env.SHELL,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ConfirmInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ConfirmInput: React.FC<ConfirmInputProps> = ({
(newValue: string) => {
onSubmit(yn(newValue, { default: isChecked }));
},
[isChecked, onSubmit]
[isChecked, onSubmit],
);

return (
Expand Down
24 changes: 12 additions & 12 deletions src/lib/Quote.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ export default function QuoteDisplay(props: { quote: Quote }) {

export type Quote =
| {
price: number;
quantity: number;
start_at: string;
end_at: string;
instance_type: string;
}
price: number;
quantity: number;
start_at: string;
end_at: string;
instance_type: string;
}
| {
price: number;
quantity: number;
start_at: string;
end_at: string;
contract_id: string;
}
price: number;
quantity: number;
start_at: string;
end_at: string;
contract_id: string;
}
| null;
6 changes: 3 additions & 3 deletions src/lib/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function registerBalance(program: Command) {
.command("balance")
.description("Get account balance")
.option("--json", "Output in JSON format")
.action(async options => {
.action(async (options) => {
const {
available: { whole: availableWhole, cents: availableCents },
reserved: { whole: reservedWhole, cents: reservedCents },
Expand Down Expand Up @@ -57,7 +57,7 @@ export function registerBalance(program: Command) {
"Reserved",
chalk.gray(formattedReserved),
chalk.gray(reservedCents.toLocaleString()),
]
],
);

console.log(table.toString() + "\n");
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function getBalance(): Promise<BalanceUsdCents> {

if (!data) {
return logAndQuit(
`Failed to get balance: Unexpected response from server: ${response}`
`Failed to get balance: Unexpected response from server: ${response}`,
);
}

Expand Down
Loading
Loading