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.6 kB

7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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/storage2/client/types"
  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. comps := strings.Split(strings.Trim(path, cdssdk.ObjectPathSeparator), cdssdk.ObjectPathSeparator)
  35. if len(comps) != 2 {
  36. fmt.Printf("Package path must be in format of <bucket>/<package>")
  37. return
  38. }
  39. pkg, err := cmdCtx.Cmdline.Svc.PackageSvc().GetByFullName(comps[0], comps[1])
  40. if err != nil {
  41. fmt.Println(err)
  42. return
  43. }
  44. wr := table.NewWriter()
  45. wr.AppendHeader(table.Row{"ID", "Name"})
  46. wr.AppendRow(table.Row{pkg.PackageID, pkg.Name})
  47. fmt.Println(wr.Render())
  48. }
  49. func lspOneByID(cmdCtx *CommandContext, id cdssdk.PackageID) {
  50. pkg, err := cmdCtx.Cmdline.Svc.PackageSvc().Get(id)
  51. if err != nil {
  52. fmt.Println(err)
  53. return
  54. }
  55. wr := table.NewWriter()
  56. wr.AppendHeader(table.Row{"ID", "Name"})
  57. wr.AppendRow(table.Row{pkg.PackageID, pkg.Name})
  58. fmt.Println(wr.Render())
  59. }

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