123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- package main
- import (
- "strconv"
- "github.com/langgenius/dify-plugin-daemon/cmd/commandline/bundle"
- "github.com/langgenius/dify-plugin-daemon/internal/types/entities/bundle_entities"
- "github.com/langgenius/dify-plugin-daemon/internal/utils/log"
- "github.com/spf13/cobra"
- )
- var (
- bundleCreateCommand = &cobra.Command{
- Use: "init",
- Short: "Create a bundle",
- Long: "Create a bundle",
- Run: func(c *cobra.Command, args []string) {
- bundle.InitBundle()
- },
- }
- bundleAnalyzeCommand = &cobra.Command{
- Use: "analyze",
- Short: "List all dependencies",
- Long: "List all dependencies",
- Run: func(c *cobra.Command, args []string) {
- bundlePath := c.Flag("bundle_path").Value.String()
- bundle.ListDependencies(bundlePath)
- },
- }
- bundleAppendDependencyCommand = &cobra.Command{
- Use: "append",
- Short: "Append a dependency",
- Long: "Append a dependency",
- }
- bundleAppendGithubDependencyCommand = &cobra.Command{
- Use: "github",
- Short: "Append a github dependency",
- Long: "Append a github dependency",
- Run: func(c *cobra.Command, args []string) {
- bundlePath := c.Flag("bundle_path").Value.String()
- repoPattern := c.Flag("repo_pattern").Value.String()
- githubPattern, err := bundle_entities.NewGithubRepoPattern(repoPattern)
- if err != nil {
- log.Error("Invalid github repo pattern: %v", err)
- return
- }
- bundle.AddGithubDependency(bundlePath, githubPattern)
- },
- }
- bundleAppendMarketplaceDependencyCommand = &cobra.Command{
- Use: "marketplace",
- Short: "Append a marketplace dependency",
- Long: "Append a marketplace dependency",
- Run: func(c *cobra.Command, args []string) {
- bundlePath := c.Flag("bundle_path").Value.String()
- marketplacePatternString := c.Flag("marketplace_pattern").Value.String()
- marketplacePattern, err := bundle_entities.NewMarketplacePattern(marketplacePatternString)
- if err != nil {
- log.Error("Invalid marketplace pattern: %v", err)
- return
- }
- bundle.AddMarketplaceDependency(bundlePath, marketplacePattern)
- },
- }
- bundleAppendPackageDependencyCommand = &cobra.Command{
- Use: "package",
- Short: "Append a local package dependency",
- Long: "Append a local package dependency",
- Run: func(c *cobra.Command, args []string) {
- bundlePath := c.Flag("bundle_path").Value.String()
- packagePath := c.Flag("package_path").Value.String()
- bundle.AddPackageDependency(bundlePath, packagePath)
- },
- }
- bundleRegenerateCommand = &cobra.Command{
- Use: "regenerate",
- Short: "Regenerate the bundle",
- Long: "Regenerate the bundle",
- Run: func(c *cobra.Command, args []string) {
- bundlePath := c.Flag("bundle_path").Value.String()
- bundle.RegenerateBundle(bundlePath)
- },
- }
- bundleRemoveDependencyCommand = &cobra.Command{
- Use: "remove",
- Short: "Remove a dependency",
- Long: "Remove a dependency",
- Run: func(c *cobra.Command, args []string) {
- bundlePath := c.Flag("bundle_path").Value.String()
- index := c.Flag("index").Value.String()
- indexInt, err := strconv.Atoi(index)
- if err != nil {
- log.Error("Invalid index: %v", err)
- return
- }
- bundle.RemoveDependency(bundlePath, indexInt)
- },
- }
- bundleBumpVersionCommand = &cobra.Command{
- Use: "bump",
- Short: "Bump the version of the bundle",
- Long: "Bump the version of the bundle",
- Run: func(c *cobra.Command, args []string) {
- bundlePath := c.Flag("bundle_path").Value.String()
- targetVersion := c.Flag("target_version").Value.String()
- bundle.BumpVersion(bundlePath, targetVersion)
- },
- }
- bundlePackageCommand = &cobra.Command{
- Use: "package",
- Short: "Package the bundle",
- Long: "Package the bundle",
- Run: func(c *cobra.Command, args []string) {
- bundlePath := c.Flag("bundle_path").Value.String()
- outputPath := c.Flag("output_path").Value.String()
- bundle.PackageBundle(bundlePath, outputPath)
- },
- }
- )
- func init() {
- bundleCommand.AddCommand(bundleCreateCommand)
- bundleCommand.AddCommand(bundleAppendDependencyCommand)
- bundleAppendDependencyCommand.AddCommand(bundleAppendGithubDependencyCommand)
- bundleAppendDependencyCommand.AddCommand(bundleAppendMarketplaceDependencyCommand)
- bundleAppendDependencyCommand.AddCommand(bundleAppendPackageDependencyCommand)
- bundleCommand.AddCommand(bundleRemoveDependencyCommand)
- bundleCommand.AddCommand(bundleRegenerateCommand)
- bundleCommand.AddCommand(bundleBumpVersionCommand)
- bundleCommand.AddCommand(bundlePackageCommand)
- bundleCommand.AddCommand(bundleAnalyzeCommand)
- bundleAppendGithubDependencyCommand.Flags().StringP("repo_pattern", "r", "", "github repo pattern")
- bundleAppendGithubDependencyCommand.Flags().StringP("bundle_path", "i", "", "path to the bundle file")
- bundleAppendGithubDependencyCommand.MarkFlagRequired("repo_pattern")
- bundleAppendGithubDependencyCommand.MarkFlagRequired("bundle_path")
- bundleAppendMarketplaceDependencyCommand.Flags().StringP("marketplace_pattern", "m", "", "marketplace pattern")
- bundleAppendMarketplaceDependencyCommand.Flags().StringP("bundle_path", "i", "", "path to the bundle file")
- bundleAppendMarketplaceDependencyCommand.MarkFlagRequired("marketplace_pattern")
- bundleAppendMarketplaceDependencyCommand.MarkFlagRequired("bundle_path")
- bundleAppendPackageDependencyCommand.Flags().StringP("package_path", "p", "", "path to the package")
- bundleAppendPackageDependencyCommand.Flags().StringP("bundle_path", "i", "", "path to the bundle file")
- bundleAppendPackageDependencyCommand.MarkFlagRequired("package_path")
- bundleAppendPackageDependencyCommand.MarkFlagRequired("bundle_path")
- bundleRemoveDependencyCommand.Flags().StringP("index", "i", "", "index of the dependency")
- bundleRemoveDependencyCommand.Flags().StringP("bundle_path", "b", "", "path to the bundle file")
- bundleRemoveDependencyCommand.MarkFlagRequired("index")
- bundleRemoveDependencyCommand.MarkFlagRequired("bundle_path")
- bundleBumpVersionCommand.Flags().StringP("target_version", "t", "", "target version")
- bundleBumpVersionCommand.Flags().StringP("bundle_path", "b", "", "path to the bundle file")
- bundleBumpVersionCommand.MarkFlagRequired("target_version")
- bundleBumpVersionCommand.MarkFlagRequired("bundle_path")
- bundlePackageCommand.Flags().StringP("output_path", "o", "", "output path")
- bundlePackageCommand.Flags().StringP("bundle_path", "b", "", "path to the bundle file")
- bundlePackageCommand.MarkFlagRequired("output_path")
- bundlePackageCommand.MarkFlagRequired("bundle_path")
- bundleAnalyzeCommand.Flags().StringP("bundle_path", "b", "", "path to the bundle file")
- bundleAnalyzeCommand.MarkFlagRequired("bundle_path")
- }
|