Skip to content

Commit ce8af82

Browse files
authored
Add option to hide successful tuple imports and display import summary (#437)
2 parents 187134f + 9ef2836 commit ce8af82

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

cmd/tuple/write.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ import (
3232

3333
const writeCommandArgumentsCount = 3
3434

35+
var hideImportedTuples bool
36+
37+
type ImportStats struct {
38+
TotalTuples int
39+
SuccessfulTuples int
40+
FailedTuples int
41+
}
42+
3543
// writeCmd represents the write command.
3644
var writeCmd = &cobra.Command{
3745
Use: "write",
@@ -142,7 +150,21 @@ func writeTuplesFromFile(flags *flag.FlagSet, fgaClient *client.OpenFgaClient) e
142150
return err
143151
}
144152

145-
return output.Display(response) //nolint:wrapcheck
153+
outputResponse := make(map[string]interface{})
154+
155+
if !hideImportedTuples && len(response.Successful) > 0 {
156+
outputResponse["successful"] = response.Successful
157+
}
158+
159+
if len(response.Failed) > 0 {
160+
outputResponse["failed"] = response.Failed
161+
}
162+
163+
outputResponse["total_count"] = len(tuples)
164+
outputResponse["successful_count"] = len(response.Successful)
165+
outputResponse["failed_count"] = len(response.Failed)
166+
167+
return output.Display(outputResponse) //nolint:wrapcheck
146168
}
147169

148170
func init() {
@@ -152,4 +174,5 @@ func init() {
152174
writeCmd.Flags().String("condition-context", "", "Condition Context (as a JSON string)")
153175
writeCmd.Flags().Int32("max-tuples-per-write", MaxTuplesPerWrite, "Max tuples per write chunk.")
154176
writeCmd.Flags().Int32("max-parallel-requests", MaxParallelRequests, "Max number of requests to issue to the server in parallel.")
177+
writeCmd.Flags().BoolVar(&hideImportedTuples, "hide-imported-tuples", false, "Hide successfully imported tuples from output")
155178
}

tests/tuple-test-cases.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ tests:
1414
stdout:
1515
json:
1616
successful.0.user: "user:anne"
17+
003 - it shows only counts when hide-imported-tuples is true:
18+
command: fga tuple write --file=./tests/fixtures/basic-tuples.json --hide-imported-tuples --store-id=$(./tests/scripts/test-data/get-store-id.sh) --model-id=$(./tests/scripts/test-data/get-model-id.sh)
19+
exit-code: 0
20+
stdout:
21+
json:
22+
total_count: "1"
23+
successful_count: "1"
24+
failed_count: "0"

0 commit comments

Comments
 (0)