From dc43c71eb275b9a1dc4524beb5bdfbff9d883fbf Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Mon, 9 Sep 2024 08:45:24 +0100 Subject: [PATCH 1/2] fix: correct flag value type in delete, import, and write Fixes #387 --- cmd/store/import.go | 4 ++-- cmd/tuple/delete.go | 4 ++-- cmd/tuple/import.go | 8 ++++---- cmd/tuple/write.go | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/store/import.go b/cmd/store/import.go index f853753..f187e5a 100644 --- a/cmd/store/import.go +++ b/cmd/store/import.go @@ -245,8 +245,8 @@ var importCmd = &cobra.Command{ func init() { importCmd.Flags().String("file", "", "File Name. The file should have the store") importCmd.Flags().String("store-id", "", "Store ID") - importCmd.Flags().Int("max-tuples-per-write", tuple.MaxTuplesPerWrite, "Max tuples per write chunk.") - importCmd.Flags().Int("max-parallel-requests", tuple.MaxParallelRequests, "Max number of requests to issue to the server in parallel.") //nolint:lll + importCmd.Flags().Int32("max-tuples-per-write", tuple.MaxTuplesPerWrite, "Max tuples per write chunk.") + importCmd.Flags().Int32("max-parallel-requests", tuple.MaxParallelRequests, "Max number of requests to issue to the server in parallel.") //nolint:lll if err := importCmd.MarkFlagRequired("file"); err != nil { fmt.Printf("error setting flag as required - %v: %v\n", "cmd/models/write", err) diff --git a/cmd/tuple/delete.go b/cmd/tuple/delete.go index 52eb4d6..81b46b2 100644 --- a/cmd/tuple/delete.go +++ b/cmd/tuple/delete.go @@ -99,8 +99,8 @@ var deleteCmd = &cobra.Command{ func init() { deleteCmd.Flags().String("file", "", "Tuples file") deleteCmd.Flags().String("model-id", "", "Model ID") - deleteCmd.Flags().Int("max-tuples-per-write", MaxTuplesPerWrite, "Max tuples per write chunk.") - deleteCmd.Flags().Int("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.") //nolint:lll + deleteCmd.Flags().Int32("max-tuples-per-write", MaxTuplesPerWrite, "Max tuples per write chunk.") + deleteCmd.Flags().Int32("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.") //nolint:lll } func ExactArgsOrFlag(n int, flag string) cobra.PositionalArgs { diff --git a/cmd/tuple/import.go b/cmd/tuple/import.go index eb289c4..eb8efda 100644 --- a/cmd/tuple/import.go +++ b/cmd/tuple/import.go @@ -32,10 +32,10 @@ import ( ) // MaxTuplesPerWrite Limit the tuples in a single batch. -var MaxTuplesPerWrite = 1 +var MaxTuplesPerWrite = int32(1) // MaxParallelRequests Limit the parallel writes to the API. -var MaxParallelRequests = 10 +var MaxParallelRequests = int32(10) //nolint:mnd type failedWriteResponse struct { TupleKey client.ClientTupleKey `json:"tuple_key"` @@ -206,6 +206,6 @@ var importCmd = &cobra.Command{ func init() { importCmd.Flags().String("model-id", "", "Model ID") importCmd.Flags().String("file", "", "Tuples file") - importCmd.Flags().Int("max-tuples-per-write", MaxTuplesPerWrite, "Max tuples per write chunk.") - importCmd.Flags().Int("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.") //nolint:lll + importCmd.Flags().Int32("max-tuples-per-write", MaxTuplesPerWrite, "Max tuples per write chunk.") + importCmd.Flags().Int32("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.") //nolint:lll } diff --git a/cmd/tuple/write.go b/cmd/tuple/write.go index 76e7133..f98388f 100644 --- a/cmd/tuple/write.go +++ b/cmd/tuple/write.go @@ -150,6 +150,6 @@ func init() { writeCmd.Flags().String("file", "", "Tuples file") writeCmd.Flags().String("condition-name", "", "Condition Name") writeCmd.Flags().String("condition-context", "", "Condition Context (as a JSON string)") - writeCmd.Flags().Int("max-tuples-per-write", MaxTuplesPerWrite, "Max tuples per write chunk.") - writeCmd.Flags().Int("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.") + writeCmd.Flags().Int32("max-tuples-per-write", MaxTuplesPerWrite, "Max tuples per write chunk.") + writeCmd.Flags().Int32("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.") } From 57338c32e6b2e178cd19e41d34211646d1d11b6c Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Mon, 9 Sep 2024 11:54:57 +0100 Subject: [PATCH 2/2] refactor: remove nolint comment --- cmd/tuple/import.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/tuple/import.go b/cmd/tuple/import.go index eb8efda..1b0d2ef 100644 --- a/cmd/tuple/import.go +++ b/cmd/tuple/import.go @@ -31,11 +31,13 @@ import ( "github.com/openfga/cli/internal/output" ) -// MaxTuplesPerWrite Limit the tuples in a single batch. -var MaxTuplesPerWrite = int32(1) +const ( + // MaxTuplesPerWrite Limit the tuples in a single batch. + MaxTuplesPerWrite = 1 -// MaxParallelRequests Limit the parallel writes to the API. -var MaxParallelRequests = int32(10) //nolint:mnd + // MaxParallelRequests Limit the parallel writes to the API. + MaxParallelRequests = 10 +) type failedWriteResponse struct { TupleKey client.ClientTupleKey `json:"tuple_key"`