Skip to content

Commit adff5ef

Browse files
Copilotshueybubbles
andcommitted
Add --disable-prompts flag to suppress line prompts in non-interactive mode
Co-authored-by: shueybubbles <[email protected]>
1 parent 2c8331b commit adff5ef

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

cmd/sqlcmd/sqlcmd.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type SQLCmdArguments struct {
7878
EnableColumnEncryption bool
7979
ChangePassword string
8080
ChangePasswordAndExit string
81+
DisablePrompts bool
8182
// Keep Help at the end of the list
8283
Help bool
8384
}
@@ -438,6 +439,7 @@ func setFlags(rootCmd *cobra.Command, args *SQLCmdArguments) {
438439
rootCmd.Flags().BoolVarP(&args.EnableColumnEncryption, "enable-column-encryption", "g", false, localizer.Sprintf("Enable column encryption"))
439440
rootCmd.Flags().StringVarP(&args.ChangePassword, "change-password", "z", "", localizer.Sprintf("New password"))
440441
rootCmd.Flags().StringVarP(&args.ChangePasswordAndExit, "change-password-exit", "Z", "", localizer.Sprintf("New password and exit"))
442+
rootCmd.Flags().BoolVar(&args.DisablePrompts, "disable-prompts", false, localizer.Sprintf("Disables line prompts when running as a subprocess"))
441443
}
442444

443445
func setScriptVariable(v string) string {
@@ -738,6 +740,7 @@ func run(vars *sqlcmd.Variables, args *SQLCmdArguments) (int, error) {
738740
s.SetupCloseHandler()
739741
defer s.StopCloseHandler()
740742
s.UnicodeOutputFile = args.UnicodeOutputFile
743+
s.DisablePrompts = args.DisablePrompts
741744

742745
if args.DisableCmd != nil {
743746
s.Cmd.DisableSysCommands(args.errorOnBlockedCmd())

pkg/sqlcmd/sqlcmd.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ type Sqlcmd struct {
8686
UnicodeOutputFile bool
8787
// EchoInput tells the GO command to print the batch text before running the query
8888
EchoInput bool
89+
// DisablePrompts suppresses printing of line prompts like "1>" when running in non-interactive mode
90+
DisablePrompts bool
8991
colorizer color.Colorizer
9092
termchan chan os.Signal
9193
}
@@ -349,7 +351,9 @@ func (s *Sqlcmd) IncludeFile(path string, processAll bool) error {
349351
ln = append(ln, line...)
350352
}
351353
if err == nil && echoFileLines {
352-
_, _ = s.GetOutput().Write([]byte(s.Prompt()))
354+
if !s.DisablePrompts {
355+
_, _ = s.GetOutput().Write([]byte(s.Prompt()))
356+
}
353357
_, _ = s.GetOutput().Write(ln)
354358
_, _ = s.GetOutput().Write([]byte(SqlcmdEol))
355359
}

0 commit comments

Comments
 (0)