Skip to content

Commit 27ac524

Browse files
authored
Merge pull request #38 from twmb/raw-req
kcl misc raw-req: trust an input version if one exists
2 parents 2572bb0 + 38a8e62 commit 27ac524

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

commands/misc/misc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,12 @@ func probeVersion(cl *client.Client) {
257257
fmt.Println("Kafka " + v.VersionGuess())
258258
}
259259

260+
type pinReq struct {
261+
kmsg.Request
262+
}
263+
264+
func (*pinReq) SetVersion(int16) {}
265+
260266
func rawCommand(cl *client.Client) *cobra.Command {
261267
var key int16
262268
var b int
@@ -269,9 +275,16 @@ func rawCommand(cl *client.Client) *cobra.Command {
269275
if req == nil {
270276
out.Die("request key %d unknown", key)
271277
}
278+
req.SetVersion(-1)
272279
raw, err := io.ReadAll(os.Stdin)
273280
out.MaybeDie(err, "unable to read stdin: %v", err)
274281
err = json.Unmarshal(raw, req)
282+
// If the raw json specified a Version field, it
283+
// overwrote our -1. We want to pin the version to
284+
// what the user specified.
285+
if req.GetVersion() != -1 {
286+
req = &pinReq{req}
287+
}
275288
out.MaybeDie(err, "unable to unmarshal stdin: %v", err)
276289
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
277290
defer cancel()

0 commit comments

Comments
 (0)