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

Warning via CLI (Windows, Git Bash) #15

Closed
anthonybaldwin opened this issue Jul 27, 2022 · 3 comments
Closed

Warning via CLI (Windows, Git Bash) #15

anthonybaldwin opened this issue Jul 27, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@anthonybaldwin
Copy link

anthonybaldwin commented Jul 27, 2022

Figured I'd mention in case others run into this and load your history w/ unidentified-script requests...if not just me (I started the issue before realizing it's only Git Bash). Will have to look into a possible solution later... For now, I'll just use PowerShell or Command Prompt.


nxapi/src/cli.ts

Lines 57 to 58 in fe725f9

} else if (!process.stdout.isTTY) {
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 + '.');


Git Bash:

$ nxapi --version
[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 https://gitlab.fancy.org.uk/samuel/nxapi#user-agent-strings.
1.2.0

✔️ PowerShell:

PS D:\> nxapi --version
1.2.0

✔️ Command Prompt:

D:\>nxapi --version
1.2.0
@anthonybaldwin anthonybaldwin changed the title Warning via CLI (Windows, Git BASH) Warning via CLI (Windows, Git Bash) Jul 27, 2022
@samuelthomas2774
Copy link
Owner

samuelthomas2774 commented Jul 27, 2022

This should happen (but also shouldn't...) when redirecting output, as process.stdout will be a pipe/file instead of a TTY. This shouldn't happen in an actual terminal.

It looks like this is because Git Bash doesn't actually create a Windows console, so I don't think there's any way to fix this (other than using CMD/PowerShell/WSL, or possibly detecting Git Bash/Cygwin/others specifically).


I have just thought of a way to maybe stop it detecting a script when redirecting output: I used process.stdout.isTTY because that's what the Node.js docs say to use, but process.stderr shouldn't ever be redirected, unless it's not running in a terminal. Will test if that works later...

@anthonybaldwin
Copy link
Author

but process.stderr shouldn't ever be redirected, unless it's not running in a terminal.

I'll give it a go this evening if you don't beat me to it.

@samuelthomas2774 samuelthomas2774 added the bug Something isn't working label Jul 27, 2022
@samuelthomas2774
Copy link
Owner

Closing this as it's not really an issue with nxapi, but feel free to create a pull request to detect Git Bash specifically as a terminal (see the linked commit below for where this is checked).


For detecting a terminal while redirecting output: 3395861 changes the process.stdout.isTTY check to use both stdin and stderr instead, as currently there are no real uses for redirecting these streams:

samuel nxapi % node bin/nxapi.js --version | cat -                   
  nxapi:update git repository exists, skipping update check +0ms
1.3.0
samuel nxapi % echo | node bin/nxapi.js --version | cat -
[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 https://gitlab.fancy.org.uk/samuel/nxapi#user-agent-strings.
  nxapi:update git repository exists, skipping update check +0ms
1.3.0

@samuelthomas2774 samuelthomas2774 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants