Skip to content

Commit

Permalink
Change flag names
Browse files Browse the repository at this point in the history
  • Loading branch information
atainter committed Aug 28, 2024
1 parent 4f156c9 commit 0721e4f
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions internal/cmd/fga.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ func init() {
fgaCmd.AddCommand(queryCmd)

// schema
convertSchemaCMD.Flags().StringP("output", "o", "json", "output format (schema or json)")
convertSchemaCMD.Flags().String("to", "json", "output to (schema or json)")
convertSchemaCMD.Flags().String("output-format", "pretty", "output format (pretty or raw). use raw for machine-readable output or writing to a file")
schemaCmd.AddCommand(convertSchemaCMD)
applySchemaCmd.Flags().BoolP("verbose", "v", false, "print extra details about the request")
applySchemaCmd.Flags().Bool("fail-on-warnings", false, "fail if there are warnings")
Expand Down Expand Up @@ -628,9 +629,13 @@ var convertSchemaCMD = &cobra.Command{
Example: `workos fga schema convert schema.txt -o json`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
output, err := cmd.Flags().GetString("output")
to, err := cmd.Flags().GetString("to")
if err != nil {
return errors.Wrap(err, "invalid output flag")
return errors.Wrap(err, "invalid to flag")
}
outputFormat, err := cmd.Flags().GetString("output-format")
if err != nil {
return errors.Wrap(err, "invalid raw flag")
}

bytes, err := os.ReadFile(args[0])
Expand All @@ -639,7 +644,7 @@ var convertSchemaCMD = &cobra.Command{
}

var response fga.ConvertSchemaResponse
switch output {
switch to {
case "json":
schemaString := string(bytes)
response, err = fga.ConvertSchemaToResourceTypes(context.Background(), fga.ConvertSchemaToResourceTypesOpts{
Expand All @@ -659,30 +664,40 @@ var convertSchemaCMD = &cobra.Command{
return convertSchemaError(err)
}
default:
return errors.Errorf("invalid output format: %s", output)
return errors.Errorf("invalid conversion: %s", to)
}

printer.PrintMsg("Version:")
printer.PrintMsg(fmt.Sprintf("%s\n", response.Version))
switch outputFormat {
case "pretty":
printer.PrintMsg("Version:")
printer.PrintMsg(fmt.Sprintf("%s\n", response.Version))

if response.Warnings != nil {
printer.PrintMsg("Warnings:")
for _, warning := range response.Warnings {
printer.PrintMsg(fmt.Sprintf("%s", warning.Message))
if response.Warnings != nil {
printer.PrintMsg("Warnings:")
for _, warning := range response.Warnings {
printer.PrintMsg(fmt.Sprintf("%s", warning.Message))

Check failure on line 678 in internal/cmd/fga.go

View workflow job for this annotation

GitHub Actions / Lint (golangci)

S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
}
printer.PrintMsg("\n")
}
printer.PrintMsg("\n")
}

if response.Schema != nil {
printer.PrintMsg("Schema:")
printer.PrintMsg(fmt.Sprintf("%s", *response.Schema))
}
if response.Schema != nil {
printer.PrintMsg("Schema:")
printer.PrintMsg(fmt.Sprintf("%s", *response.Schema))

Check failure on line 685 in internal/cmd/fga.go

View workflow job for this annotation

GitHub Actions / Lint (golangci)

S1025: the argument is already a string, there's no need to use fmt.Sprintf (gosimple)
}

if response.ResourceTypes != nil {
printer.PrintMsg("Resource Types:")
printer.PrintJson(response.ResourceTypes)
if response.ResourceTypes != nil {
printer.PrintMsg("Resource Types:")
printer.PrintJson(response.ResourceTypes)
}
case "raw":
if response.Schema != nil {
printer.PrintMsg(*response.Schema)
} else {
printer.PrintJson(response.ResourceTypes)
}
default:
return errors.Errorf("invalid output format: %s", outputFormat)
}

return nil
},
}
Expand Down

0 comments on commit 0721e4f

Please sign in to comment.