Skip to content

Commit 2b5f848

Browse files
committed
Corrected types
1 parent 3f462f7 commit 2b5f848

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

pkg/commands/kvstoreentry/create.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io/fs"
99
"os"
1010
"path/filepath"
11+
"strconv"
1112
"strings"
1213
"sync"
1314
"sync/atomic"
@@ -42,7 +43,7 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
4243
c.CmdClause.Flag("dir-allow-hidden", "Allow hidden files (e.g. dot files) to be included (skipped by default)").BoolVar(&c.dirAllowHidden)
4344
c.CmdClause.Flag("dir-concurrency", "Limit the number of concurrent network resources allocated").Default("50").IntVar(&c.dirConcurrency)
4445
c.CmdClause.Flag("file", `Path to a file containing individual JSON objects (e.g., {"key":"...","value":"base64_encoded_value"}) separated by new-line delimiter`).StringVar(&c.filePath)
45-
c.CmdClause.Flag("if-generation-match", "Value which must match the current generation marker in an item for an update operation to proceed").IntVar(&c.ifGenMatch)
46+
c.CmdClause.Flag("if-generation-match", "Value which must match the current generation marker in an item for an update operation to proceed").StringVar(&c.ifGenMatch)
4647
c.CmdClause.Flag("metadata", "An arbitrary data field which can contain up to 2000 bytes of data").StringVar(&c.metadata)
4748
c.CmdClause.Flag("prepend", "If an item with the specified key exists, the value provided in the operation is prepended to the existing value instead of replacing it (Default: false)").Default("false").BoolVar(&c.prepend)
4849
c.RegisterFlagBool(c.JSONFlag()) // --json
@@ -65,7 +66,7 @@ type CreateCommand struct {
6566
dirConcurrency int
6667
dirPath string
6768
filePath string
68-
ifGenMatch int
69+
ifGenMatch string
6970
metadata string
7071
prepend bool
7172
stdin bool
@@ -103,7 +104,16 @@ func (c *CreateCommand) Exec(in io.Reader, out io.Writer) error {
103104
c.Input.Add = c.add
104105
c.Input.Append = c.append
105106
c.Input.BackgroundFetch = c.backFetch
106-
c.Input.IfGenerationMatch = uint64(c.ifGenMatch)
107+
108+
// Parse generation match if provided.
109+
if c.ifGenMatch != "" {
110+
inputGeneration, err := strconv.ParseUint(c.ifGenMatch, 10, 64)
111+
if err != nil {
112+
return fmt.Errorf("invalid generation value: %s", c.ifGenMatch)
113+
}
114+
c.Input.IfGenerationMatch = inputGeneration
115+
}
116+
107117
c.Input.Metadata = &c.metadata
108118
c.Input.Prepend = c.prepend
109119

pkg/commands/kvstoreentry/kvstoreentry_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ func TestCreateCommand(t *testing.T) {
122122
},
123123
WantOutput: fstfmt.Success("Created key '%s' in KV Store '%s'", itemKey, storeID),
124124
},
125+
{
126+
Name: "validate --if-generation-match with invalid value",
127+
Args: fmt.Sprintf("--store-id %s --key %s --value %s --if-generation-match invalid", storeID, itemKey, itemValue),
128+
WantError: "invalid generation value: invalid",
129+
},
125130
{
126131
Name: "validate --metadata flag",
127132
Args: fmt.Sprintf("--store-id %s --key %s --value %s --metadata %s", storeID, itemKey, itemValue, "test-metadata"),

0 commit comments

Comments
 (0)