mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-08-20 01:25:31 -05:00
Prevent detecting a script when redirecting output
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user