Skip to content

Commit 0cbb884

Browse files
Fix review comments for PR microsoft#631
- Add 'p' to checkDefaultValue for bare -p flag support - Fix error message to show both '0' and '1' as valid values - Remove trailing space in colon-separated format output - Add test cases for -p and -p 1 flags
1 parent 8dc992e commit 0cbb884

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

cmd/sqlcmd/sqlcmd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,7 @@ func checkDefaultValue(args []string, i int) (val string) {
332332
'k': "0",
333333
'L': "|", // | is the sentinel for no value since users are unlikely to use it. It's "reserved" in most shells
334334
'X': "0",
335+
'p': "0",
335336
}
336337
if isFlag(args[i]) && len(args[i]) == 2 && (len(args) == i+1 || args[i+1][0] == '-') {
337338
if v, ok := flags[rune(args[i][1])]; ok {
@@ -552,7 +553,7 @@ func normalizeFlags(cmd *cobra.Command) error {
552553
case "0", "1":
553554
return pflag.NormalizedName(name)
554555
default:
555-
err = invalidParameterError("-p", v, "1")
556+
err = invalidParameterError("-p", v, "0", "1")
556557
return pflag.NormalizedName("")
557558
}
558559
}

cmd/sqlcmd/sqlcmd_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ func TestValidCommandLineToArgsConversion(t *testing.T) {
9999
{[]string{"-k", "-X", "-r", "-z", "something"}, func(args SQLCmdArguments) bool {
100100
return args.warnOnBlockedCmd() && !args.useEnvVars() && args.getControlCharacterBehavior() == sqlcmd.ControlRemove && *args.ErrorsToStderr == 0 && args.ChangePassword == "something"
101101
}},
102+
{[]string{"-p"}, func(args SQLCmdArguments) bool {
103+
return args.PrintStatistics != nil && *args.PrintStatistics == 0
104+
}},
105+
{[]string{"-p", "1"}, func(args SQLCmdArguments) bool {
106+
return args.PrintStatistics != nil && *args.PrintStatistics == 1
107+
}},
102108
{[]string{"-N"}, func(args SQLCmdArguments) bool {
103109
return args.EncryptConnection == "true"
104110
}},

pkg/sqlcmd/sqlcmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ func (s *Sqlcmd) printStatistics(elapsedMs int64, numBatches int) {
612612
if *s.PrintStatistics == 1 {
613613
// Colon-separated format: n:x:t1:t2:t3
614614
// packetSize:numBatches:totalTime:avgTime:batchesPerSec
615-
fmt.Fprintf(out, "\n%d:%d:%d:%.2f:%.2f \n", packetSize, numBatches, elapsedMs, avgTime, batchesPerSec)
615+
fmt.Fprintf(out, "\n%d:%d:%d:%.2f:%.2f\n", packetSize, numBatches, elapsedMs, avgTime, batchesPerSec)
616616
} else {
617617
// Standard format
618618
fmt.Fprintf(out, "\nNetwork packet size (bytes): %d\n", packetSize)

0 commit comments

Comments
 (0)