root.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package cmd
  2. import (
  3. "fmt"
  4. "github.com/ente-io/cli/pkg"
  5. "os"
  6. "runtime"
  7. "github.com/spf13/viper"
  8. "github.com/spf13/cobra"
  9. )
  10. const AppVersion = "0.1.11"
  11. var ctrl *pkg.ClICtrl
  12. // rootCmd represents the base command when called without any subcommands
  13. var rootCmd = &cobra.Command{
  14. Use: "ente",
  15. Short: "CLI tool for exporting your photos from ente.io",
  16. Long: `Start by creating a config file in your home directory:`,
  17. // Uncomment the following line if your bare application
  18. // has an action associated with it:
  19. Run: func(cmd *cobra.Command, args []string) {
  20. fmt.Sprintf("Hello World")
  21. },
  22. }
  23. // Execute adds all child commands to the root command and sets flags appropriately.
  24. // This is called by main.main(). It only needs to happen once to the rootCmd.
  25. func Execute(controller *pkg.ClICtrl) {
  26. ctrl = controller
  27. err := rootCmd.Execute()
  28. if err != nil {
  29. os.Exit(1)
  30. }
  31. }
  32. func init() {
  33. // Here you will define your flags and configuration settings.
  34. // Cobra supports persistent flags, which, if defined here,
  35. // will be global for your application.
  36. // rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cli-go.yaml)")
  37. // Cobra also supports local flags, which will only run
  38. // when this action is called directly.
  39. rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
  40. viper.SetConfigName("config") // Name of your configuration file (e.g., config.yaml)
  41. viper.AddConfigPath(".") // Search for config file in the current directory
  42. viper.ReadInConfig() // Read the configuration file if it exists
  43. }
  44. func recoverWithLog() {
  45. if r := recover(); r != nil {
  46. fmt.Println("Panic occurred:", r)
  47. // Print the stack trace
  48. stackTrace := make([]byte, 1024*8)
  49. stackTrace = stackTrace[:runtime.Stack(stackTrace, false)]
  50. fmt.Printf("Stack Trace:\n%s", stackTrace)
  51. }
  52. }