Skip to content

Commit 3ca3fb9

Browse files
authored
refactor: make overall CLI act more expected and consistent, and add quiet flag (#78)
1 parent 92610a9 commit 3ca3fb9

14 files changed

Lines changed: 380 additions & 104 deletions

File tree

auth.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
} from "@trpc/client";
1616
import { observable } from "@trpc/server/observable";
1717
import { Spinner } from "@std/cli/unstable-spinner";
18-
import { error } from "./util.ts";
18+
import { error, requireInteractive } from "./util.ts";
1919
import { EventSourcePolyfill } from "event-source-polyfill";
2020
import type { GlobalContext } from "./main.ts";
2121

@@ -180,15 +180,23 @@ export async function getAuth(
180180
return storedAuth;
181181
}
182182

183+
requireInteractive(
184+
context,
185+
"Set the DENO_DEPLOY_TOKEN environment variable or use --token.",
186+
);
187+
183188
const { code, exchangeToken, verifier } = await interactive(context);
184189

185190
const authUrl = `${context.endpoint}/auth?code=${code}`;
186191

187192
const spinner = new Spinner({
188-
message: `Visit ${authUrl} to authorize deploying your project.`,
193+
message: "",
189194
color: "yellow",
190195
});
191-
spinner.start();
196+
console.log(`Visit ${authUrl} to authorize deploying your project.`);
197+
if (!quiet) {
198+
spinner.start();
199+
}
192200

193201
await open(authUrl);
194202

@@ -215,12 +223,11 @@ export async function interactive(context: GlobalContext): Promise<
215223
});
216224

217225
if (!res.ok) {
218-
console.error("An error occurred during authentication, exiting...");
219-
if (context.debug) {
220-
console.log(res);
221-
console.log(await res.json());
222-
}
223-
Deno.exit(1);
226+
error(
227+
context,
228+
"An error occurred during authentication, exiting...",
229+
res,
230+
);
224231
}
225232

226233
const body = await res.json();

config.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createTrpcClient, getAuth } from "./auth.ts";
22
import type { GlobalContext } from "./main.ts";
3-
import { error } from "./util.ts";
3+
import { error, requireInteractive } from "./util.ts";
44
import {
55
type PromptEntry,
66
promptSelect,
@@ -42,6 +42,10 @@ export async function getOrg(
4242
} else if (orgs.length === 1) {
4343
org = orgs[0].slug;
4444
} else {
45+
requireInteractive(
46+
context,
47+
"Use --org to specify the organization.",
48+
);
4549
const selectedOrg = promptSelect(
4650
"Select an organization:",
4751
orgs.map((org) => ({ label: `${org.name} (${org.slug})`, value: org })),
@@ -109,6 +113,10 @@ export async function getApp(
109113
name: string;
110114
slug: string;
111115
}>;
116+
requireInteractive(
117+
context,
118+
"Use --app to specify the application.",
119+
);
112120
const appStrings: PromptEntry<{ name: string; slug: string } | null>[] =
113121
apps.map((app) => ({ label: app.slug, value: app }));
114122
if (canCreate) {
@@ -118,8 +126,7 @@ export async function getApp(
118126
clear: true,
119127
});
120128
if (!selectedApp) {
121-
console.error("No application was selected.");
122-
Deno.exit(1);
129+
error(context, "No application was selected.");
123130
}
124131

125132
if (selectedApp.value === null) {

deno.lock

Lines changed: 114 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deploy/create/flow.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
} from "@deno/framework-detect";
1717
import type { GlobalContext } from "../../main.ts";
1818
import type { CreateApp, Repo } from "./mod.ts";
19+
import { requireInteractive } from "../../util.ts";
1920

2021
export const AVAILABLE_BUILD_TIMEOUTS = [5, 10, 15, 20, 25, 30];
2122
export const AVAILABLE_BUILD_MEMORY_LIMITS = [1024, 2048, 3072, 4096];
@@ -63,6 +64,10 @@ export async function createFlow(
6364
rootPath: string,
6465
preselectedOrg?: string,
6566
): Promise<CreateApp> {
67+
requireInteractive(
68+
context,
69+
"Use explicit flags (--org, --app, --source, etc.) to create an app non-interactively.",
70+
);
6671
const trpcClient = createTrpcClient(context);
6772

6873
let org;

deploy/create/mod.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
import { publish, waitForRevision } from "../publish.ts";
2222
import { resolve } from "@std/path";
2323
import { error } from "../../util.ts";
24+
import { green } from "@std/fmt/colors";
2425

2526
export const createCommand = new Command<GlobalContext>()
2627
.description(
@@ -238,7 +239,7 @@ export const createCommand = new Command<GlobalContext>()
238239
buildDirectory = member?.path ??
239240
required(options.appDirectory, "app-directory");
240241
} else {
241-
buildDirectory = options.appDirectory || "/";
242+
buildDirectory = options.appDirectory || "";
242243
}
243244

244245
let buildConfig;
@@ -399,7 +400,9 @@ export async function createApp(
399400
});
400401

401402
console.log(
402-
`Created app, view it at ${context.endpoint}/${data.org}/${data.app}`,
403+
`${
404+
green("✔")
405+
} Created app, view it at ${context.endpoint}/${data.org}/${data.app}`,
403406
);
404407

405408
if (data.repo === undefined) {

0 commit comments

Comments
 (0)