Skip to content

Commit

Permalink
fix: fix error when model missing in transform command
Browse files Browse the repository at this point in the history
  • Loading branch information
rhamzeh committed Sep 18, 2023
1 parent d5a045b commit 4d9d8d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/authorizationmodel/read-from-input.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"strings"

"github.com/openfga/cli/internal/clierrors"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -71,17 +72,17 @@ func ReadFromInputFileOrArg(

switch {
case fileName != "":
if err = ReadFromFile(fileName, input, format, storeName); err != nil {
return err
}
return ReadFromFile(fileName, input, format, storeName)
case len(args) > 0 && args[0] != "-":
*input = args[0]
// if the input format is set as the default, set it from the file extension (and default to fga)
if *format == ModelFormatDefault {
*format = ModelFormatFGA
}
case !isOptional:
return cmd.Help() //nolint:wrapcheck
_ = cmd.Help() // print out the help message so users know what the command expects

return fmt.Errorf("%w", clierrors.ErrModelInputMissing)
}

return nil
Expand Down
1 change: 1 addition & 0 deletions internal/clierrors/clierrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var (
ErrInvalidFormat = errors.New("invalid format")
ErrStoreNotFound = errors.New("store not found")
ErrAuthorizationModelNotFound = errors.New("authorization model not found")
ErrModelInputMissing = errors.New("model input not provided")
)

func ValidationError(op string, details string) error {
Expand Down

0 comments on commit 4d9d8d7

Please sign in to comment.