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.

new.go 1.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package pkg
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/spf13/cobra"
  6. cliapi "gitlink.org.cn/cloudream/jcs-pub/client/sdk/api/v1"
  7. clitypes "gitlink.org.cn/cloudream/jcs-pub/client/types"
  8. "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
  9. )
  10. func init() {
  11. var opt newOpt
  12. cmd := cobra.Command{
  13. Use: "new <bucket_name>/<package_name>",
  14. Args: cobra.ExactArgs(1),
  15. RunE: func(c *cobra.Command, args []string) error {
  16. ctx := cmd.GetCmdCtx(c)
  17. return new(c, ctx, opt, args)
  18. },
  19. }
  20. cmd.Flags().Int64Var(&opt.BucketID, "bid", 0, "set bucket id, if set, you should not set bucket name")
  21. PackageCmd.AddCommand(&cmd)
  22. }
  23. type newOpt struct {
  24. BucketID int64
  25. }
  26. func new(c *cobra.Command, ctx *cmd.CommandContext, opt newOpt, args []string) error {
  27. if opt.BucketID != 0 {
  28. resp, err := ctx.Client.Package().Create(cliapi.PackageCreate{
  29. BucketID: clitypes.BucketID(opt.BucketID),
  30. Name: args[0],
  31. })
  32. if err != nil {
  33. return err
  34. }
  35. printOnePackage(resp.Package)
  36. return nil
  37. }
  38. comps := strings.Split(args[0], "/")
  39. if len(comps) != 2 {
  40. return fmt.Errorf("invalid package name")
  41. }
  42. bktResp, err := ctx.Client.Bucket().GetByName(cliapi.BucketGetByName{
  43. Name: comps[0],
  44. })
  45. if err != nil {
  46. return fmt.Errorf("get bucket by name %v: %v", comps[0], err)
  47. }
  48. resp, err := ctx.Client.Package().Create(cliapi.PackageCreate{
  49. BucketID: bktResp.Bucket.BucketID,
  50. Name: comps[1],
  51. })
  52. if err != nil {
  53. return fmt.Errorf("create package %v: %v", args[0], err)
  54. }
  55. printOnePackage(resp.Package)
  56. return nil
  57. }

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