@@ -55,6 +55,9 @@ type SQLCmdArguments struct {
55
55
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."`
56
56
UnicodeOutputFile bool `short:"u" help:"Specifies that all output files are encoded with little-endian Unicode"`
57
57
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."`
58
61
// Keep Help at the end of the list
59
62
Help bool `short:"?" help:"Show syntax summary."`
60
63
}
@@ -68,6 +71,9 @@ func (a *SQLCmdArguments) Validate() error {
68
71
if a .Headers < - 1 {
69
72
return fmt .Errorf (`'-h %d': header value must be either -1 or a value between 1 and 2147483647` , a .Headers )
70
73
}
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
+ }
71
77
return nil
72
78
}
73
79
@@ -155,11 +161,21 @@ func setVars(vars *sqlcmd.Variables, args *SQLCmdArguments) {
155
161
}
156
162
return ""
157
163
},
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
+ },
163
179
sqlcmd .SQLCMDMAXVARTYPEWIDTH : func (a * SQLCmdArguments ) string { return "" },
164
180
sqlcmd .SQLCMDMAXFIXEDTYPEWIDTH : func (a * SQLCmdArguments ) string { return "" },
165
181
sqlcmd .SQLCMDFORMAT : func (a * SQLCmdArguments ) string { return a .Format },
@@ -246,7 +262,7 @@ func run(vars *sqlcmd.Variables, args *SQLCmdArguments) (int, error) {
246
262
}
247
263
248
264
s .Connect = & connectConfig
249
- s .Format = sqlcmd .NewSQLCmdDefaultFormatter (false )
265
+ s .Format = sqlcmd .NewSQLCmdDefaultFormatter (args . TrimSpaces )
250
266
if args .OutputFile != "" {
251
267
err = s .RunCommand (s .Cmd ["OUT" ], []string {args .OutputFile })
252
268
if err != nil {
0 commit comments