bundle.go 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package main
  2. import (
  3. "strconv"
  4. "github.com/langgenius/dify-plugin-daemon/cmd/commandline/bundle"
  5. "github.com/langgenius/dify-plugin-daemon/internal/types/entities/bundle_entities"
  6. "github.com/langgenius/dify-plugin-daemon/internal/utils/log"
  7. "github.com/spf13/cobra"
  8. )
  9. var (
  10. bundleCreateCommand = &cobra.Command{
  11. Use: "init",
  12. Short: "Create a bundle",
  13. Long: "Create a bundle",
  14. Run: func(c *cobra.Command, args []string) {
  15. bundle.InitBundle()
  16. },
  17. }
  18. bundleAnalyzeCommand = &cobra.Command{
  19. Use: "analyze",
  20. Short: "List all dependencies",
  21. Long: "List all dependencies",
  22. Run: func(c *cobra.Command, args []string) {
  23. bundlePath := c.Flag("bundle_path").Value.String()
  24. bundle.ListDependencies(bundlePath)
  25. },
  26. }
  27. bundleAppendDependencyCommand = &cobra.Command{
  28. Use: "append",
  29. Short: "Append a dependency",
  30. Long: "Append a dependency",
  31. }
  32. bundleAppendGithubDependencyCommand = &cobra.Command{
  33. Use: "github",
  34. Short: "Append a github dependency",
  35. Long: "Append a github dependency",
  36. Run: func(c *cobra.Command, args []string) {
  37. bundlePath := c.Flag("bundle_path").Value.String()
  38. repoPattern := c.Flag("repo_pattern").Value.String()
  39. githubPattern, err := bundle_entities.NewGithubRepoPattern(repoPattern)
  40. if err != nil {
  41. log.Error("Invalid github repo pattern: %v", err)
  42. return
  43. }
  44. bundle.AddGithubDependency(bundlePath, githubPattern)
  45. },
  46. }
  47. bundleAppendMarketplaceDependencyCommand = &cobra.Command{
  48. Use: "marketplace",
  49. Short: "Append a marketplace dependency",
  50. Long: "Append a marketplace dependency",
  51. Run: func(c *cobra.Command, args []string) {
  52. bundlePath := c.Flag("bundle_path").Value.String()
  53. marketplacePatternString := c.Flag("marketplace_pattern").Value.String()
  54. marketplacePattern, err := bundle_entities.NewMarketplacePattern(marketplacePatternString)
  55. if err != nil {
  56. log.Error("Invalid marketplace pattern: %v", err)
  57. return
  58. }
  59. bundle.AddMarketplaceDependency(bundlePath, marketplacePattern)
  60. },
  61. }
  62. bundleAppendPackageDependencyCommand = &cobra.Command{
  63. Use: "package",
  64. Short: "Append a local package dependency",
  65. Long: "Append a local package dependency",
  66. Run: func(c *cobra.Command, args []string) {
  67. bundlePath := c.Flag("bundle_path").Value.String()
  68. packagePath := c.Flag("package_path").Value.String()
  69. bundle.AddPackageDependency(bundlePath, packagePath)
  70. },
  71. }
  72. bundleRegenerateCommand = &cobra.Command{
  73. Use: "regenerate",
  74. Short: "Regenerate the bundle",
  75. Long: "Regenerate the bundle",
  76. Run: func(c *cobra.Command, args []string) {
  77. bundlePath := c.Flag("bundle_path").Value.String()
  78. bundle.RegenerateBundle(bundlePath)
  79. },
  80. }
  81. bundleRemoveDependencyCommand = &cobra.Command{
  82. Use: "remove",
  83. Short: "Remove a dependency",
  84. Long: "Remove a dependency",
  85. Run: func(c *cobra.Command, args []string) {
  86. bundlePath := c.Flag("bundle_path").Value.String()
  87. index := c.Flag("index").Value.String()
  88. indexInt, err := strconv.Atoi(index)
  89. if err != nil {
  90. log.Error("Invalid index: %v", err)
  91. return
  92. }
  93. bundle.RemoveDependency(bundlePath, indexInt)
  94. },
  95. }
  96. bundleBumpVersionCommand = &cobra.Command{
  97. Use: "bump",
  98. Short: "Bump the version of the bundle",
  99. Long: "Bump the version of the bundle",
  100. Run: func(c *cobra.Command, args []string) {
  101. bundlePath := c.Flag("bundle_path").Value.String()
  102. targetVersion := c.Flag("target_version").Value.String()
  103. bundle.BumpVersion(bundlePath, targetVersion)
  104. },
  105. }
  106. bundlePackageCommand = &cobra.Command{
  107. Use: "package",
  108. Short: "Package the bundle",
  109. Long: "Package the bundle",
  110. Run: func(c *cobra.Command, args []string) {
  111. bundlePath := c.Flag("bundle_path").Value.String()
  112. outputPath := c.Flag("output_path").Value.String()
  113. bundle.PackageBundle(bundlePath, outputPath)
  114. },
  115. }
  116. )
  117. func init() {
  118. bundleCommand.AddCommand(bundleCreateCommand)
  119. bundleCommand.AddCommand(bundleAppendDependencyCommand)
  120. bundleAppendDependencyCommand.AddCommand(bundleAppendGithubDependencyCommand)
  121. bundleAppendDependencyCommand.AddCommand(bundleAppendMarketplaceDependencyCommand)
  122. bundleAppendDependencyCommand.AddCommand(bundleAppendPackageDependencyCommand)
  123. bundleCommand.AddCommand(bundleRemoveDependencyCommand)
  124. bundleCommand.AddCommand(bundleRegenerateCommand)
  125. bundleCommand.AddCommand(bundleBumpVersionCommand)
  126. bundleCommand.AddCommand(bundlePackageCommand)
  127. bundleCommand.AddCommand(bundleAnalyzeCommand)
  128. bundleAppendGithubDependencyCommand.Flags().StringP("repo_pattern", "r", "", "github repo pattern")
  129. bundleAppendGithubDependencyCommand.Flags().StringP("bundle_path", "i", "", "path to the bundle file")
  130. bundleAppendGithubDependencyCommand.MarkFlagRequired("repo_pattern")
  131. bundleAppendGithubDependencyCommand.MarkFlagRequired("bundle_path")
  132. bundleAppendMarketplaceDependencyCommand.Flags().StringP("marketplace_pattern", "m", "", "marketplace pattern")
  133. bundleAppendMarketplaceDependencyCommand.Flags().StringP("bundle_path", "i", "", "path to the bundle file")
  134. bundleAppendMarketplaceDependencyCommand.MarkFlagRequired("marketplace_pattern")
  135. bundleAppendMarketplaceDependencyCommand.MarkFlagRequired("bundle_path")
  136. bundleAppendPackageDependencyCommand.Flags().StringP("package_path", "p", "", "path to the package")
  137. bundleAppendPackageDependencyCommand.Flags().StringP("bundle_path", "i", "", "path to the bundle file")
  138. bundleAppendPackageDependencyCommand.MarkFlagRequired("package_path")
  139. bundleAppendPackageDependencyCommand.MarkFlagRequired("bundle_path")
  140. bundleRemoveDependencyCommand.Flags().StringP("index", "i", "", "index of the dependency")
  141. bundleRemoveDependencyCommand.Flags().StringP("bundle_path", "b", "", "path to the bundle file")
  142. bundleRemoveDependencyCommand.MarkFlagRequired("index")
  143. bundleRemoveDependencyCommand.MarkFlagRequired("bundle_path")
  144. bundleBumpVersionCommand.Flags().StringP("target_version", "t", "", "target version")
  145. bundleBumpVersionCommand.Flags().StringP("bundle_path", "b", "", "path to the bundle file")
  146. bundleBumpVersionCommand.MarkFlagRequired("target_version")
  147. bundleBumpVersionCommand.MarkFlagRequired("bundle_path")
  148. bundlePackageCommand.Flags().StringP("output_path", "o", "", "output path")
  149. bundlePackageCommand.Flags().StringP("bundle_path", "b", "", "path to the bundle file")
  150. bundlePackageCommand.MarkFlagRequired("output_path")
  151. bundlePackageCommand.MarkFlagRequired("bundle_path")
  152. bundleAnalyzeCommand.Flags().StringP("bundle_path", "b", "", "path to the bundle file")
  153. bundleAnalyzeCommand.MarkFlagRequired("bundle_path")
  154. }