Prevent detecting a script when redirecting output

This commit is contained in:
Samuel Elliott
2022-08-13 00:49:22 +01:00
parent f24dc2c63c
commit 33958618b0
2 changed files with 6 additions and 2 deletions

View File

@@ -49,12 +49,15 @@ export function createYargs(argv: string[]) {
export type Arguments = YargsArguments<ReturnType<typeof createYargs>>;
// Node.js docs recommend using process.stdout.isTTY (see https://github.com/samuelthomas2774/nxapi/issues/15)
const is_terminal = process.stdin.isTTY && process.stderr.isTTY;
export async function main(argv = process.argv.slice(2)) {
addUserAgent('nxapi-cli');
if (process.env.NXAPI_USER_AGENT) {
addUserAgent(process.env.NXAPI_USER_AGENT);
} else if (!process.stdout.isTTY) {
} else if (!is_terminal) {
console.warn('[warn] The nxapi command is not running in a terminal. If using the nxapi command in a script or other program, the NXAPI_USER_AGENT environment variable should be set. See ' + USER_AGENT_INFO_URL + '.');
addUserAgent('unidentified-script');
}

View File

@@ -8,7 +8,8 @@ const debug = createDebug('nxapi:auth:util');
// a script/some other program, which should be limited in case it continues to run the command
// if it fails. The Electron app overrides this as the parent process (probably) won't be a
// terminal, but most attempts to call getToken won't be automated.
export const SHOULD_LIMIT_USE = !process.stdout.isTTY;
// Node.js docs recommend using process.stdout.isTTY (see https://github.com/samuelthomas2774/nxapi/issues/15).
export const SHOULD_LIMIT_USE = !process.stdin.isTTY || !process.stderr.isTTY;
export const LIMIT_REQUESTS = 4;
export const LIMIT_PERIOD = 60 * 60 * 1000; // 60 minutes