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.

ls.go 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package ls
  2. import (
  3. "fmt"
  4. "strings"
  5. "github.com/spf13/cobra"
  6. "gitlink.org.cn/cloudream/jcs-pub/jcsctl/cmd"
  7. )
  8. func init() {
  9. var opt option
  10. c := &cobra.Command{
  11. Use: "ls [bucket_name]/[package_name]:[object_path]",
  12. Short: "download package all files to local disk",
  13. Args: cobra.MaximumNArgs(1),
  14. RunE: func(c *cobra.Command, args []string) error {
  15. ctx := cmd.GetCmdCtx(c)
  16. return ls(c, ctx, opt, args)
  17. },
  18. }
  19. c.Flags().Int64Var(&opt.BucketID, "bid", 0, "bucket id, if set, you should not set any path")
  20. c.Flags().Int64Var(&opt.PackageID, "pid", 0, "package id, if set, you should not set <bucket_name>/<package_name>")
  21. c.Flags().BoolVarP(&opt.Recursive, "recursive", "r", false, "list all files in package recursively, only valid when list in a package")
  22. c.Flags().BoolVarP(&opt.Long, "long", "l", false, "show more details")
  23. cmd.RootCmd.AddCommand(c)
  24. }
  25. type option struct {
  26. Long bool
  27. BucketID int64
  28. PackageID int64
  29. Recursive bool
  30. }
  31. func ls(c *cobra.Command, ctx *cmd.CommandContext, opt option, args []string) error {
  32. if opt.PackageID != 0 {
  33. objPath := ""
  34. if len(args) > 0 {
  35. objPath = args[0]
  36. }
  37. return lsObject(ctx, opt, "", "", objPath)
  38. }
  39. if opt.BucketID != 0 {
  40. if len(args) > 0 {
  41. return fmt.Errorf("list package objects is not supported when use bucket id")
  42. }
  43. return lsPackage(ctx, opt, "")
  44. }
  45. if len(args) == 0 {
  46. return lsBucket(ctx, opt)
  47. }
  48. comps := strings.SplitN(args[0], ":", 2)
  49. if len(comps) > 1 {
  50. objPath := comps[1]
  51. comps = strings.SplitN(comps[0], "/", 2)
  52. if len(comps) != 2 {
  53. return fmt.Errorf("invalid path format, should be <bucket_name>/<package_name>:<object_path>")
  54. }
  55. return lsObject(ctx, opt, comps[0], comps[1], objPath)
  56. }
  57. comps = strings.SplitN(args[0], "/", 2)
  58. if len(comps) == 1 {
  59. return lsPackage(ctx, opt, comps[0])
  60. }
  61. return lsObject(ctx, opt, comps[0], comps[1], "")
  62. }

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