main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "github.com/langgenius/dify-plugin-daemon/cmd/commandline/cmd"
  6. "github.com/spf13/cobra"
  7. "github.com/spf13/viper"
  8. )
  9. var (
  10. cfgFile string
  11. rootCommand = &cobra.Command{
  12. Use: "dify",
  13. Short: "Dify",
  14. Long: "Dify is a cli tool to help you develop your Dify projects.",
  15. }
  16. pluginCommand = &cobra.Command{
  17. Use: "plugin",
  18. Short: "Plugin",
  19. Long: "Plugin related commands",
  20. }
  21. pluginInitCommand = &cobra.Command{
  22. Use: "init",
  23. Short: "Init",
  24. Long: "Init",
  25. Run: func(c *cobra.Command, args []string) {
  26. cmd.InitPlugin()
  27. },
  28. }
  29. )
  30. func init() {
  31. cobra.OnInitialize(initConfig)
  32. rootCommand.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.dify.yaml)")
  33. rootCommand.AddCommand(pluginCommand)
  34. pluginCommand.AddCommand(pluginInitCommand)
  35. }
  36. func initConfig() {
  37. if cfgFile != "" {
  38. // Use config file from the flag.
  39. viper.SetConfigFile(cfgFile)
  40. } else {
  41. // Find home directory.
  42. home, err := os.UserHomeDir()
  43. cobra.CheckErr(err)
  44. // Search config in home directory with name ".dify" (without extension).
  45. viper.AddConfigPath(home)
  46. viper.SetConfigType("yaml")
  47. viper.SetConfigName(".dify")
  48. }
  49. viper.AutomaticEnv()
  50. if err := viper.ReadInConfig(); err == nil {
  51. fmt.Println("Using config file:", viper.ConfigFileUsed())
  52. }
  53. }
  54. func main() {
  55. rootCommand.Execute()
  56. }