-
Notifications
You must be signed in to change notification settings - Fork 75
Automatically suppress line prompts when stdin is redirected #582
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
Conversation
@copilot the |
…e mode Co-authored-by: shueybubbles <[email protected]>
Co-authored-by: shueybubbles <[email protected]>
I've implemented the fix to properly detect when stdin is redirected. The updated code in Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
#Closed |
…command line flag Co-authored-by: shueybubbles <[email protected]>
…file Co-authored-by: shueybubbles <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for detecting redirected stdin and suppressing interactive prompts when sqlcmd is run in non-interactive mode (e.g., piped input), matching the behavior of the original tool.
- Introduces
isStdinRedirected
and updatesNewConsole
to wire in a buffered stdin reader when input is redirected. - Modifies
Readline
andClose
to skip prompts, history, and liner state when stdin is not a terminal. - Adds unit tests for stdin redirection detection and console initialization logic; bumps dependent modules in
go.mod
.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
pkg/console/console_redirect_test.go | Adds test for isStdinRedirected behavior |
pkg/console/console_redirect.go | Implements isStdinRedirected helper |
pkg/console/console.go | Updates NewConsole , Readline , and Close for redirection |
cmd/sqlcmd/stdin_console_test.go | Adds test for isConsoleInitializationRequired |
cmd/sqlcmd/sqlcmd.go | Updates console-init logic to skip prompts on redirected stdin |
go.mod | Bumps golang.org/x/sys , adds golang.org/x/term |
Comments suppressed due to low confidence (1)
cmd/sqlcmd/sqlcmd.go:734
- [nitpick] The variable name
iactive
is confusing and appears to be a typo. Rename it tointeractive
orisInteractive
for clarity.
iactive := args.InputFile == nil && args.Query == "" && len(args.ChangePasswordAndExit) == 0
historyFile: historyFile, | ||
impl: liner.NewLiner(), | ||
historyFile: historyFile, | ||
stdinRedirected: isStdinRedirected(), |
Copilot
AI
May 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prompt
field is never initialized in NewConsole
, so interactive prompts will always be empty. Consider setting a default prompt value (e.g. "sqlcmd> ") when stdin is a terminal.
stdinRedirected: isStdinRedirected(), | |
stdinRedirected: isStdinRedirected(), | |
prompt: "sqlcmd> ", |
Copilot uses AI. Check for mistakes.
t.Logf("File mode: %v", fileStat.Mode()) | ||
t.Logf("Is character device: %v", (fileStat.Mode()&os.ModeCharDevice) != 0) | ||
t.Logf("Connection config: %+v", connectConfig) | ||
t.Logf("RequiresPassword() returns: %v", connectConfig.RequiresPassword()) |
Copilot
AI
May 28, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] These t.Logf
calls appear to be leftover debug logging and do not contribute to the test assertions. Consider removing them to keep the test output clean.
t.Logf("File mode: %v", fileStat.Mode()) | |
t.Logf("Is character device: %v", (fileStat.Mode()&os.ModeCharDevice) != 0) | |
t.Logf("Connection config: %+v", connectConfig) | |
t.Logf("RequiresPassword() returns: %v", connectConfig.RequiresPassword()) |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot per the update made here:
please fix the title and PR description (a --disable-prompts flag has note been added)
You're absolutely right. The PR title and description still reference the The implementation now automatically detects when stdin is redirected and suppresses prompts without requiring any command line flag. Since I cannot directly update the PR title through the available tools, here are the corrected title and description that should be used: Title: "Automatically suppress line prompts when stdin is redirected" Description: This PR addresses the issue where line prompts (like "1>", "2>", "3>") appear in the output when running sqlcmd as a subprocess from another program. The solution automatically detects when stdin is redirected (from pipes or files) and suppresses line prompts in those cases, while preserving interactive behavior when running in a terminal. Changes
This matches the behavior of the original sqlcmd tool when used in subprocess scenarios without requiring any additional flags. |
This PR addresses the issue where line prompts (like "1>", "2>", "3>") appear in the output when running sqlcmd as a subprocess from another program.
The solution automatically detects when stdin is redirected (from pipes or files) and suppresses line prompts in those cases, while preserving interactive behavior when running in a terminal.
Changes
pkg/console/console_redirect.go
This matches the behavior of the original sqlcmd tool when used in subprocess scenarios without requiring any additional flags.
Fixes #580.
Warning
Firewall rules blocked me from connecting to one or more addresses
I tried to connect to the following addresses, but was blocked by firewall rules:
someserver
/tmp/go-build1426325623/b001/sqlcmd.test -test.testlogfile=/tmp/go-build1426325623/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.