From 24b98083ef892e6bcb7b038757ed33c3fb5a0dad Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Wed, 10 Apr 2024 10:23:45 +0100 Subject: [PATCH 1/2] doc(model/write): add missing example to readme, correct help text example --- README.md | 3 ++- cmd/model/write.go | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 433f1f4..2212609 100644 --- a/README.md +++ b/README.md @@ -355,7 +355,8 @@ fga model **write** * `--format`: Authorization model input format. Can be "fga", "json", or "modular". Defaults to the file extension if provided (optional) ###### Example -* `fga model write --store-id=01H0H015178Y2V4CX10C2KGHF4 --file model.fga` +* `fga model write --store-id=01H0H015178Y2V4CX10C2KGHF4 --file=model.fga` +* `fga model write --store-id=01H0H015178Y2V4CX10C2KGHF4 --file=fga.mod` * `fga model write --store-id=01H0H015178Y2V4CX10C2KGHF4 '{"type_definitions": [ { "type": "user" }, { "type": "document", "relations": { "can_view": { "this": {} } }, "metadata": { "relations": { "can_view": { "directly_related_user_types": [ { "type": "user" } ] }}}} ], "schema_version": "1.1"}' --format json` ###### Response diff --git a/cmd/model/write.go b/cmd/model/write.go index 6e0df1c..4712744 100644 --- a/cmd/model/write.go +++ b/cmd/model/write.go @@ -54,7 +54,8 @@ var writeCmd = &cobra.Command{ Short: "Write Authorization Model", Long: "Writes a new authorization model.", Example: `fga model write --store-id=01H0H015178Y2V4CX10C2KGHF4 --file=model.json -fga model write --store-id=01H0H015178Y2V4CX10C2KGHF4 '{"type_definitions":[{"type":"user"},{"type":"document","relations":{"can_view":{"this":{}}},"metadata":{"relations":{"can_view":{"directly_related_user_types":[{"type":"user"}]}}}}],"schema_version":"1.1"}'`, //nolint:lll +fga model write --store-id=01H0H015178Y2V4CX10C2KGHF4 --file=fga.mod +fga model write --store-id=01H0H015178Y2V4CX10C2KGHF4 '{"type_definitions":[{"type":"user"},{"type":"document","relations":{"can_view":{"this":{}}},"metadata":{"relations":{"can_view":{"directly_related_user_types":[{"type":"user"}]}}}}],"schema_version":"1.1"}' --format=json`, //nolint:lll Args: cobra.MaximumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { clientConfig := cmdutils.GetClientConfig(cmd) @@ -97,7 +98,7 @@ var writeInputFormat = authorizationmodel.ModelFormatDefault func init() { writeCmd.Flags().String("store-id", "", "Store ID") writeCmd.Flags().String("file", "", "File Name. The file should have the model in the JSON or DSL format") - writeCmd.Flags().Var(&writeInputFormat, "format", `Authorization model input format. Can be "fga" or "json"`) + writeCmd.Flags().Var(&writeInputFormat, "format", `Authorization model input format. Can be "fga", "json", or "modular"`) //nolint:lll if err := writeCmd.MarkFlagRequired("store-id"); err != nil { fmt.Printf("error setting flag as required - %v: %v\n", "cmd/models/write", err) From 604118ffb54beb8d629620ed84f560f86e176952 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Thu, 11 Apr 2024 14:03:39 +0100 Subject: [PATCH 2/2] refactor: change modelformat type to improve help text --- internal/authorizationmodel/format.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/authorizationmodel/format.go b/internal/authorizationmodel/format.go index 964ee06..f15ecf1 100644 --- a/internal/authorizationmodel/format.go +++ b/internal/authorizationmodel/format.go @@ -47,5 +47,5 @@ func (format *ModelFormat) Set(v string) error { } func (format *ModelFormat) Type() string { - return "ModelFormat" + return "format" }