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.

lsp.go 1.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package cmdline
  2. import (
  3. "fmt"
  4. "strconv"
  5. "strings"
  6. "github.com/jedib0t/go-pretty/v6/table"
  7. "github.com/spf13/cobra"
  8. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  9. )
  10. func init() {
  11. var usePkgID *bool
  12. cmd := &cobra.Command{
  13. Use: "lsp",
  14. Short: "List package information",
  15. Args: cobra.ExactArgs(1),
  16. Run: func(cmd *cobra.Command, args []string) {
  17. cmdCtx := GetCmdCtx(cmd)
  18. if usePkgID != nil && *usePkgID {
  19. id, err := strconv.ParseInt(args[0], 10, 64)
  20. if err != nil {
  21. fmt.Printf("Invalid package id: %s\n", args[0])
  22. return
  23. }
  24. lspOneByID(cmdCtx, cdssdk.PackageID(id))
  25. } else {
  26. lspByPath(cmdCtx, args[0])
  27. }
  28. },
  29. }
  30. usePkgID = cmd.Flags().BoolP("id", "i", false, "List with package id instead of path")
  31. rootCmd.AddCommand(cmd)
  32. }
  33. func lspByPath(cmdCtx *CommandContext, path string) {
  34. userID := cdssdk.UserID(1)
  35. comps := strings.Split(strings.Trim(path, cdssdk.ObjectPathSeparator), cdssdk.ObjectPathSeparator)
  36. if len(comps) != 2 {
  37. fmt.Printf("Package path must be in format of <bucket>/<package>")
  38. return
  39. }
  40. pkg, err := cmdCtx.Cmdline.Svc.PackageSvc().GetByFullName(userID, comps[0], comps[1])
  41. if err != nil {
  42. fmt.Println(err)
  43. return
  44. }
  45. wr := table.NewWriter()
  46. wr.AppendHeader(table.Row{"ID", "Name", "State"})
  47. wr.AppendRow(table.Row{pkg.PackageID, pkg.Name, pkg.State})
  48. fmt.Println(wr.Render())
  49. }
  50. func lspOneByID(cmdCtx *CommandContext, id cdssdk.PackageID) {
  51. userID := cdssdk.UserID(1)
  52. pkg, err := cmdCtx.Cmdline.Svc.PackageSvc().Get(userID, id)
  53. if err != nil {
  54. fmt.Println(err)
  55. return
  56. }
  57. wr := table.NewWriter()
  58. wr.AppendHeader(table.Row{"ID", "Name", "State"})
  59. wr.AppendRow(table.Row{pkg.PackageID, pkg.Name, pkg.State})
  60. fmt.Println(wr.Render())
  61. }

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