ente/cli/cmd/root.go

70 lines
2 KiB
Go
Raw Normal View History

package cmd
import (
"fmt"
2023-10-21 09:26:13 +00:00
"github.com/ente-io/cli/pkg"
"github.com/spf13/cobra/doc"
"os"
2023-09-21 09:53:37 +00:00
"runtime"
2023-09-14 04:20:32 +00:00
"github.com/spf13/viper"
"github.com/spf13/cobra"
)
2024-03-13 06:08:30 +00:00
var version string
2023-09-13 08:51:05 +00:00
var ctrl *pkg.ClICtrl
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
2023-10-25 11:52:22 +00:00
Use: "ente",
Short: "CLI tool for exporting your photos from ente.io",
Long: `Start by creating a config file in your home directory:`,
// Uncomment the following line if your bare application
// has an action associated with it:
Run: func(cmd *cobra.Command, args []string) {
fmt.Sprintf("Hello World")
},
}
func GenerateDocs() error {
return doc.GenMarkdownTree(rootCmd, "./docs/generated")
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
2024-03-13 06:08:30 +00:00
func Execute(controller *pkg.ClICtrl, ver string) {
2023-09-13 08:51:05 +00:00
ctrl = controller
2024-03-13 06:08:30 +00:00
version = ver
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}
func init() {
// Here you will define your flags and configuration settings.
// Cobra supports persistent flags, which, if defined here,
// will be global for your application.
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.cli-go.yaml)")
// Cobra also supports local flags, which will only run
// when this action is called directly.
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
2023-09-13 02:50:15 +00:00
viper.SetConfigName("config") // Name of your configuration file (e.g., config.yaml)
viper.AddConfigPath(".") // Search for config file in the current directory
viper.ReadInConfig() // Read the configuration file if it exists
}
2023-09-21 09:53:37 +00:00
func recoverWithLog() {
if r := recover(); r != nil {
fmt.Println("Panic occurred:", r)
// Print the stack trace
stackTrace := make([]byte, 1024*8)
stackTrace = stackTrace[:runtime.Stack(stackTrace, false)]
fmt.Printf("Stack Trace:\n%s", stackTrace)
}
}