mirror of
https://github.com/davidallendj/opaal.git
synced 2025-12-20 11:37:01 -07:00
Fixed how config file worked
This commit is contained in:
parent
98b27bab28
commit
747ca162ed
2 changed files with 23 additions and 14 deletions
20
cmd/login.go
20
cmd/login.go
|
|
@ -2,7 +2,6 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
opaal "davidallendj/opaal/internal"
|
opaal "davidallendj/opaal/internal"
|
||||||
"davidallendj/opaal/internal/util"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -13,23 +12,15 @@ var loginCmd = &cobra.Command{
|
||||||
Use: "login",
|
Use: "login",
|
||||||
Short: "Start the login flow",
|
Short: "Start the login flow",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
// load config if found
|
for {
|
||||||
if configPath != "" {
|
err := opaal.Login(&config)
|
||||||
exists, err := util.PathExists(configPath)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("failed to load config")
|
fmt.Printf("%v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
} else if exists {
|
} else if config.RunOnce {
|
||||||
config = opaal.LoadConfig(configPath)
|
break
|
||||||
} else {
|
|
||||||
config = opaal.NewConfig()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err := opaal.Login(&config)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Print(err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -45,5 +36,6 @@ func init() {
|
||||||
loginCmd.Flags().BoolVar(&config.OpenBrowser, "open-browser", config.OpenBrowser, "automatically open link in browser")
|
loginCmd.Flags().BoolVar(&config.OpenBrowser, "open-browser", config.OpenBrowser, "automatically open link in browser")
|
||||||
loginCmd.Flags().BoolVar(&config.DecodeIdToken, "decode-id-token", config.DecodeIdToken, "decode and print ID token from identity provider")
|
loginCmd.Flags().BoolVar(&config.DecodeIdToken, "decode-id-token", config.DecodeIdToken, "decode and print ID token from identity provider")
|
||||||
loginCmd.Flags().BoolVar(&config.DecodeAccessToken, "decore-access-token", config.DecodeAccessToken, "decode and print access token from authorization server")
|
loginCmd.Flags().BoolVar(&config.DecodeAccessToken, "decore-access-token", config.DecodeAccessToken, "decode and print access token from authorization server")
|
||||||
|
loginCmd.Flags().BoolVar(&config.RunOnce, "once", config.RunOnce, "set whether to run login once and exit")
|
||||||
rootCmd.AddCommand(loginCmd)
|
rootCmd.AddCommand(loginCmd)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
17
cmd/root.go
17
cmd/root.go
|
|
@ -2,6 +2,7 @@ package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
opaal "davidallendj/opaal/internal"
|
opaal "davidallendj/opaal/internal"
|
||||||
|
"davidallendj/opaal/internal/util"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
|
@ -20,6 +21,21 @@ var rootCmd = &cobra.Command{
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func initConfig() {
|
||||||
|
// load config if found or create a new one
|
||||||
|
if configPath != "" {
|
||||||
|
exists, err := util.PathExists(configPath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("failed to load config")
|
||||||
|
os.Exit(1)
|
||||||
|
} else if exists {
|
||||||
|
config = opaal.LoadConfig(configPath)
|
||||||
|
} else {
|
||||||
|
config = opaal.NewConfig()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func Execute() {
|
func Execute() {
|
||||||
if err := rootCmd.Execute(); err != nil {
|
if err := rootCmd.Execute(); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "failed to start CLI: %s", err)
|
fmt.Fprintf(os.Stderr, "failed to start CLI: %s", err)
|
||||||
|
|
@ -28,5 +44,6 @@ func Execute() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
cobra.OnInitialize(initConfig)
|
||||||
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "set the config path")
|
rootCmd.PersistentFlags().StringVar(&configPath, "config", "", "set the config path")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue