@@ -55,6 +55,9 @@ type SQLCmdArguments struct {
5555 Headers int `short:"h" help:"Specifies the number of rows to print between the column headings. Use -h-1 to specify that headers not be printed."`
5656 UnicodeOutputFile bool `short:"u" help:"Specifies that all output files are encoded with little-endian Unicode"`
5757 Version bool `help:"Show the sqlcmd version information"`
58+ ColumnSeparator string `short:"s" help:"Specifies the column separator character. Sets the SQLCMDCOLSEP variable."`
59+ ScreenWidth * int `short:"w" help:"Specifies the screen width for output. Sets the SQLCMDCOLWIDTH variable."`
60+ TrimSpaces bool `short:"W" help:"Remove trailing spaces from a column."`
5861 // Keep Help at the end of the list
5962 Help bool `short:"?" help:"Show syntax summary."`
6063}
@@ -68,6 +71,9 @@ func (a *SQLCmdArguments) Validate() error {
6871 if a .Headers < - 1 {
6972 return fmt .Errorf (`'-h %d': header value must be either -1 or a value between 1 and 2147483647` , a .Headers )
7073 }
74+ if a .ScreenWidth != nil && (* a .ScreenWidth < 9 || * a .ScreenWidth > 65535 ) {
75+ return fmt .Errorf (`'-w %d': value must be greater than 8 and less than 65536.` , * a .ScreenWidth )
76+ }
7177 return nil
7278}
7379
@@ -155,11 +161,21 @@ func setVars(vars *sqlcmd.Variables, args *SQLCmdArguments) {
155161 }
156162 return ""
157163 },
158- sqlcmd .SQLCMDUSER : func (a * SQLCmdArguments ) string { return a .UserName },
159- sqlcmd .SQLCMDSTATTIMEOUT : func (a * SQLCmdArguments ) string { return "" },
160- sqlcmd .SQLCMDHEADERS : func (a * SQLCmdArguments ) string { return fmt .Sprint (a .Headers ) },
161- sqlcmd .SQLCMDCOLSEP : func (a * SQLCmdArguments ) string { return "" },
162- sqlcmd .SQLCMDCOLWIDTH : func (a * SQLCmdArguments ) string { return "" },
164+ sqlcmd .SQLCMDUSER : func (a * SQLCmdArguments ) string { return a .UserName },
165+ sqlcmd .SQLCMDSTATTIMEOUT : func (a * SQLCmdArguments ) string { return "" },
166+ sqlcmd .SQLCMDHEADERS : func (a * SQLCmdArguments ) string { return fmt .Sprint (a .Headers ) },
167+ sqlcmd .SQLCMDCOLSEP : func (a * SQLCmdArguments ) string {
168+ if a .ColumnSeparator != "" {
169+ return string (a .ColumnSeparator [0 ])
170+ }
171+ return ""
172+ },
173+ sqlcmd .SQLCMDCOLWIDTH : func (a * SQLCmdArguments ) string {
174+ if a .ScreenWidth != nil {
175+ return fmt .Sprint (* a .ScreenWidth )
176+ }
177+ return ""
178+ },
163179 sqlcmd .SQLCMDMAXVARTYPEWIDTH : func (a * SQLCmdArguments ) string { return "" },
164180 sqlcmd .SQLCMDMAXFIXEDTYPEWIDTH : func (a * SQLCmdArguments ) string { return "" },
165181 sqlcmd .SQLCMDFORMAT : func (a * SQLCmdArguments ) string { return a .Format },
@@ -246,7 +262,7 @@ func run(vars *sqlcmd.Variables, args *SQLCmdArguments) (int, error) {
246262 }
247263
248264 s .Connect = & connectConfig
249- s .Format = sqlcmd .NewSQLCmdDefaultFormatter (false )
265+ s .Format = sqlcmd .NewSQLCmdDefaultFormatter (args . TrimSpaces )
250266 if args .OutputFile != "" {
251267 err = s .RunCommand (s .Cmd ["OUT" ], []string {args .OutputFile })
252268 if err != nil {
0 commit comments