You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

pin.go 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package pkg
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "github.com/spf13/cobra"
  7. cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
  8. jcstypes "gitlink.org.cn/cloudream/jcs-pub/common/types"
  9. "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
  10. )
  11. func init() {
  12. var opt pinOpt
  13. cd := cobra.Command{
  14. Use: "pin <bucket_name>/<package_name>",
  15. Args: cobra.ExactArgs(1),
  16. RunE: func(c *cobra.Command, args []string) error {
  17. ctx := cmd.GetCmdCtx(c)
  18. return pin(c, ctx, opt, args, true)
  19. },
  20. }
  21. cd.Flags().BoolVar(&opt.UseID, "id", false, "treat first argument as package ID")
  22. PackageCmd.AddCommand(&cd)
  23. var unpinOpt pinOpt
  24. cd = cobra.Command{
  25. Use: "unpin <bucket_name>/<package_name>",
  26. Args: cobra.ExactArgs(1),
  27. RunE: func(c *cobra.Command, args []string) error {
  28. ctx := cmd.GetCmdCtx(c)
  29. return pin(c, ctx, unpinOpt, args, false)
  30. },
  31. }
  32. cd.Flags().BoolVar(&unpinOpt.UseID, "id", false, "treat first argument as package ID")
  33. PackageCmd.AddCommand(&cd)
  34. }
  35. type pinOpt struct {
  36. UseID bool
  37. }
  38. func pin(c *cobra.Command, ctx *cmd.CommandContext, opt pinOpt, args []string, pin bool) error {
  39. var pkgID jcstypes.PackageID
  40. if opt.UseID {
  41. id, err := strconv.ParseInt(args[0], 10, 64)
  42. if err != nil {
  43. return fmt.Errorf("invalid package ID: %v", args[0])
  44. }
  45. pkgID = jcstypes.PackageID(id)
  46. } else {
  47. comps := strings.Split(args[0], "/")
  48. if len(comps) != 2 {
  49. return fmt.Errorf("invalid package name: %v", args[0])
  50. }
  51. getPkg, err := ctx.Client.Package().GetByFullName(cliapi.PackageGetByFullName{
  52. BucketName: comps[0],
  53. PackageName: comps[1],
  54. })
  55. if err != nil {
  56. return fmt.Errorf("get package by name %v: %v", args[0], err)
  57. }
  58. pkgID = getPkg.Package.PackageID
  59. }
  60. if _, err := ctx.Client.Package().Pin(cliapi.PackagePin{
  61. PackageID: pkgID,
  62. Pin: false,
  63. }); err != nil {
  64. return fmt.Errorf("unpin package %v: %v", pkgID, err)
  65. }
  66. return nil
  67. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。