From 97b4403b7aaae80e4801487d7edfce62ccf116da Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Wed, 24 May 2023 17:38:38 +0200 Subject: [PATCH] fix(cli): avoid looping infinitely and avoid prompt if interactive --- cli/login.ts | 4 ++++ cli/workspace.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cli/login.ts b/cli/login.ts index 6665fd3f7a..2960848481 100644 --- a/cli/login.ts +++ b/cli/login.ts @@ -3,6 +3,10 @@ import { colors, getAvailablePort, log, open, Secret, Select } from "./deps.ts"; export async function loginInteractive(remote: string) { let token: string | undefined; + if (!Deno.isatty(Deno.stdin.rid)) { + log.info("Not a TTY, can't login interactively."); + return undefined; + } if ( (await Select.prompt({ message: "How do you want to login", diff --git a/cli/workspace.ts b/cli/workspace.ts index 7dd8b5dae6..b4c94623a0 100644 --- a/cli/workspace.ts +++ b/cli/workspace.ts @@ -208,6 +208,10 @@ export async function add( remote = new URL(remote).toString(); // add trailing slash in all cases! let token = await tryGetLoginInfo(opts); + if (!token && !Deno.isatty(Deno.stdin.rid)) { + log.info("Not a TTY, can't login interactively. Pass the token in --token"); + return; + } while (!token) { token = await loginInteractive(remote); }