Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/sqlcmd/sqlcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type SQLCmdArguments struct {
EnableColumnEncryption bool
ChangePassword string
ChangePasswordAndExit string
DisablePrompts bool
// Keep Help at the end of the list
Help bool
}
Expand Down Expand Up @@ -438,6 +439,7 @@ func setFlags(rootCmd *cobra.Command, args *SQLCmdArguments) {
rootCmd.Flags().BoolVarP(&args.EnableColumnEncryption, "enable-column-encryption", "g", false, localizer.Sprintf("Enable column encryption"))
rootCmd.Flags().StringVarP(&args.ChangePassword, "change-password", "z", "", localizer.Sprintf("New password"))
rootCmd.Flags().StringVarP(&args.ChangePasswordAndExit, "change-password-exit", "Z", "", localizer.Sprintf("New password and exit"))
rootCmd.Flags().BoolVar(&args.DisablePrompts, "disable-prompts", false, localizer.Sprintf("Disables line prompts when running as a subprocess"))
}

func setScriptVariable(v string) string {
Expand Down Expand Up @@ -738,6 +740,7 @@ func run(vars *sqlcmd.Variables, args *SQLCmdArguments) (int, error) {
s.SetupCloseHandler()
defer s.StopCloseHandler()
s.UnicodeOutputFile = args.UnicodeOutputFile
s.DisablePrompts = args.DisablePrompts

if args.DisableCmd != nil {
s.Cmd.DisableSysCommands(args.errorOnBlockedCmd())
Expand Down
6 changes: 5 additions & 1 deletion pkg/sqlcmd/sqlcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ type Sqlcmd struct {
UnicodeOutputFile bool
// EchoInput tells the GO command to print the batch text before running the query
EchoInput bool
// DisablePrompts suppresses printing of line prompts like "1>" when running in non-interactive mode
DisablePrompts bool
colorizer color.Colorizer
termchan chan os.Signal
}
Expand Down Expand Up @@ -349,7 +351,9 @@ func (s *Sqlcmd) IncludeFile(path string, processAll bool) error {
ln = append(ln, line...)
}
if err == nil && echoFileLines {
_, _ = s.GetOutput().Write([]byte(s.Prompt()))
if !s.DisablePrompts {
_, _ = s.GetOutput().Write([]byte(s.Prompt()))
}
_, _ = s.GetOutput().Write(ln)
_, _ = s.GetOutput().Write([]byte(SqlcmdEol))
}
Expand Down