diff --git a/.example-config b/.example-config index ff4d1fd..dab8846 100644 --- a/.example-config +++ b/.example-config @@ -1,4 +1,4 @@ -license_token = 'AAAAA1bcDFgHJKLmnOPqrsTUvwXYZ12o3lmNOjR2xWiQRT3v5zxL4mKoWjxL82jD7sWx93KfYGsN2IkdPxsUw9PTas7oFbgR3nY9qpZmVyHFJKLPxT7sWmqErXyTn5iKoNpRtV7bPdQZ8qLmWoJpU2nKrXz6vW' arl_cookie = '1d9e90abb452a61b1b7463f0953e1b303c4e2e7e5fd404fde9b385f4de01c340ac0f62f1c8c1550405b0b9beded0e28c481e96a6148e8f4548351add5d7db746b2785ecf83b1768e5dd8cc73b1ad30c18d07c9cb37f5c6b9cd7a78a4de2aff11' +license_token = 'AAAAA1bcDFgHJKLmnOPqrsTUvwXYZ12o3lmNOjR2xWiQRT3v5zxL4mKoWjxL82jD7sWx93KfYGsN2IkdPxsUw9PTas7oFbgR3nY9qpZmVyHFJKLPxT7sWmqErXyTn5iKoNpRtV7bPdQZ8qLmWoJpU2nKrXz6vW' secret_key = 'hTv1IAw19qWy9i3f' iv = '0001020304050607' \ No newline at end of file diff --git a/cmd/download.go b/cmd/download.go index 5e704c0..879f988 100644 --- a/cmd/download.go +++ b/cmd/download.go @@ -21,7 +21,7 @@ var downloadCmd = &cobra.Command{ } func init() { - rootCmd.AddCommand(downloadCmd) + RootCmd.AddCommand(downloadCmd) downloadCmd.PersistentFlags().StringVarP(&outputDir, "output", "o", "", "output directory (default is current directory)") downloadCmd.PersistentFlags().StringVarP(&quality, "quality", "q", "", "download quality [mp3_128, mp3_320, flac, best] (default is best)") } @@ -38,7 +38,7 @@ func validateInput() { "best": true, } if !validQualities[quality] { - fmt.Fprintf(os.Stderr, "invalid quality option: %s\n", quality) + fmt.Fprintf(os.Stderr, "Error: invalid quality option: %s\n", quality) os.Exit(1) } } diff --git a/cmd/root.go b/cmd/root.go index 53d6bef..67a3cf8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -12,20 +12,16 @@ import ( var cfgFile string -var rootCmd = &cobra.Command{ +var RootCmd = &cobra.Command{ Use: "godeez", Short: "GoDeez is a tool to download music from Deezer", -} - -func Execute() { - if err := rootCmd.Execute(); err != nil { - fmt.Fprintf(os.Stderr, "could not execute command: %v\n", err) - os.Exit(1) - } + Run: func(cmd *cobra.Command, args []string) { + cmd.Help() + }, } func init() { - rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.godeez)") + RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.godeez)") cobra.OnInitialize(initConfig) } @@ -35,17 +31,17 @@ func initConfig() { } else { homedir, err := os.UserHomeDir() if err != nil { - fmt.Fprintf(os.Stderr, "could not get home directory: %v\n", err) + fmt.Fprintf(os.Stderr, "Error: could not get home directory: %v\n", err) os.Exit(1) } path := path.Join(homedir, ".godeez") if _, err := os.Stat(path); os.IsNotExist(err) { - fmt.Printf("config file not found, creating one at %s\n", path) + fmt.Printf("Config file not found, creating one at %s\n", path) - content := []byte("license_token: \nsecret_key: \niv: \n") + content := []byte("arl_cookie = ''\nlicense_token = ''\nsecret_key = ''\niv = '0001020304050607'\n") if err := os.WriteFile(path, content, 0644); err != nil { - fmt.Fprintf(os.Stderr, "could not create config file: %v\n", err) + fmt.Fprintf(os.Stderr, "Error: could not create config file: %v\n", err) os.Exit(1) } } @@ -57,26 +53,26 @@ func initConfig() { viper.SetConfigType("toml") viper.AutomaticEnv() if err := viper.ReadInConfig(); err != nil { - fmt.Fprintf(os.Stderr, "could not read config file: %v\n", err) + fmt.Fprintf(os.Stderr, "Error: could not read config file: %v\n", err) os.Exit(1) } cfg := &config.Cfg if err := viper.Unmarshal(&cfg); err != nil { - fmt.Fprintf(os.Stderr, "could not unmarshal config: %v\n", err) + fmt.Fprintf(os.Stderr, "Error: could not unmarshal config file: %v\n", err) os.Exit(1) } if cfg.LicenseToken == "" { - fmt.Fprintln(os.Stderr, "license_token is not set in config file") + fmt.Fprintln(os.Stderr, "Error: license_token is not set in config file") os.Exit(1) } if cfg.SecretKey == "" { - fmt.Fprintln(os.Stderr, "secret_key is not set in config file") + fmt.Fprintln(os.Stderr, "Error: secret_key is not set in config file") os.Exit(1) } if cfg.IV == "" { - fmt.Fprintln(os.Stderr, "iv is not set in config file") + fmt.Fprintln(os.Stderr, "Error: iv is not set in config file") os.Exit(1) } } diff --git a/main.go b/main.go index c2e1461..853e490 100644 --- a/main.go +++ b/main.go @@ -3,5 +3,5 @@ package main import "github.com/mathismqn/godeez/cmd" func main() { - cmd.Execute() + cmd.RootCmd.Execute() }