Skip to content

Commit

Permalink
Fixed error handling for #113
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasdille committed Dec 17, 2023
1 parent 1a1d988 commit f0315ef
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 37 deletions.
28 changes: 0 additions & 28 deletions cmd/test/main.go

This file was deleted.

48 changes: 39 additions & 9 deletions cmd/uniget/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ func init() {
}

func main() {
var err error

rootCmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
logging.Error.Writer = os.Stderr
pterm.Warning.Writer = os.Stderr
Expand Down Expand Up @@ -253,15 +255,43 @@ func main() {

viper.AutomaticEnv()
viper.SetEnvPrefix("uniget")
viper.BindPFlag("log-level", pf.Lookup("log-level"))
viper.BindPFlag("debug", pf.Lookup("debug"))
viper.BindPFlag("trace", pf.Lookup("trace"))
viper.BindPFlag("prefix", pf.Lookup("prefix"))
viper.BindPFlag("target", pf.Lookup("target"))
viper.BindPFlag("user", pf.Lookup("user"))
viper.BindEnv("no-interactive", "UNIGET_NO_INTERACTIVE")

err := rootCmd.Execute()
err = viper.BindPFlag("log-level", pf.Lookup("log-level"))
if err != nil {
logging.Error.Printfln("Error binding log-level flag: %s", err)
os.Exit(1)
}
err = viper.BindPFlag("debug", pf.Lookup("debug"))
if err != nil {
logging.Error.Printfln("Error binding debug flag: %s", err)
os.Exit(1)
}
err = viper.BindPFlag("trace", pf.Lookup("trace"))
if err != nil {
logging.Error.Printfln("Error binding trace flag: %s", err)
os.Exit(1)
}
err = viper.BindPFlag("prefix", pf.Lookup("prefix"))
if err != nil {
logging.Error.Printfln("Error binding prefix flag: %s", err)
os.Exit(1)
}
err = viper.BindPFlag("target", pf.Lookup("target"))
if err != nil {
logging.Error.Printfln("Error binding target flag: %s", err)
os.Exit(1)
}
err = viper.BindPFlag("user", pf.Lookup("user"))
if err != nil {
logging.Error.Printfln("Error binding user flag: %s", err)
os.Exit(1)
}
err = viper.BindEnv("no-interactive", "UNIGET_NO_INTERACTIVE")
if err != nil {
logging.Error.Printfln("Error binding no-interactive flag: %s", err)
os.Exit(1)
}

err = rootCmd.Execute()
if err != nil {
os.Exit(1)
}
Expand Down

0 comments on commit f0315ef

Please sign in to comment.