github.com/openfga/openfga@v1.5.4-rc1/cmd/root.go (about) 1 // Package cmd contains all the commands included in the binary file. 2 package cmd 3 4 import ( 5 "strings" 6 7 "github.com/spf13/cobra" 8 "github.com/spf13/viper" 9 ) 10 11 const ( 12 datastoreEngineFlag = "datastore-engine" 13 datastoreEngineConf = "datastore.engine" 14 datastoreURIFlag = "datastore-uri" 15 datastoreURIConf = "datastore.uri" 16 ) 17 18 // NewRootCommand enables all children commands to read flags from CLI flags, environment variables prefixed with OPENFGA, or config.yaml (in that order). 19 func NewRootCommand() *cobra.Command { 20 viper.SetConfigName("config") 21 viper.SetConfigType("yaml") 22 23 viper.SetEnvPrefix("OPENFGA") 24 viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) 25 viper.AutomaticEnv() 26 27 configPaths := []string{"/etc/openfga", "$HOME/.openfga", "."} 28 for _, path := range configPaths { 29 viper.AddConfigPath(path) 30 } 31 32 viper.SetDefault(datastoreEngineFlag, "") 33 viper.SetDefault(datastoreURIFlag, "") 34 err := viper.ReadInConfig() 35 if err == nil { 36 viper.SetDefault(datastoreEngineFlag, viper.Get(datastoreEngineConf)) 37 viper.SetDefault(datastoreURIFlag, viper.Get(datastoreURIConf)) 38 } 39 40 return &cobra.Command{ 41 Use: "openfga", 42 Short: "A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar", 43 Long: `A high performance and flexible authorization/permission engine built for developers and inspired by Google Zanzibar. 44 45 OpenFGA is designed to make it easy for developers to model their application permissions, and to add and integrate fine-grained authorization into their applications. 46 Complete documentation is available at https://openfga.dev.`, 47 } 48 }