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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package cmdline
  2. /*
  3. import (
  4. "fmt"
  5. "strconv"
  6. "strings"
  7. "github.com/jedib0t/go-pretty/v6/table"
  8. "github.com/spf13/cobra"
  9. cdssdk "gitlink.org.cn/cloudream/jcs-pub/client/types"
  10. )
  11. func init() {
  12. var usePkgID *bool
  13. cmd := &cobra.Command{
  14. Use: "lsp",
  15. Short: "List package information",
  16. Args: cobra.ExactArgs(1),
  17. Run: func(cmd *cobra.Command, args []string) {
  18. cmdCtx := GetCmdCtx(cmd)
  19. if usePkgID != nil && *usePkgID {
  20. id, err := strconv.ParseInt(args[0], 10, 64)
  21. if err != nil {
  22. fmt.Printf("Invalid package id: %s\n", args[0])
  23. return
  24. }
  25. lspOneByID(cmdCtx, cdssdk.PackageID(id))
  26. } else {
  27. lspByPath(cmdCtx, args[0])
  28. }
  29. },
  30. }
  31. usePkgID = cmd.Flags().BoolP("id", "i", false, "List with package id instead of path")
  32. RootCmd.AddCommand(cmd)
  33. }
  34. func lspByPath(cmdCtx *CommandContext, path string) {
  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(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"})
  47. wr.AppendRow(table.Row{pkg.PackageID, pkg.Name})
  48. fmt.Println(wr.Render())
  49. }
  50. func lspOneByID(cmdCtx *CommandContext, id cdssdk.PackageID) {
  51. pkg, err := cmdCtx.Cmdline.Svc.PackageSvc().Get(id)
  52. if err != nil {
  53. fmt.Println(err)
  54. return
  55. }
  56. wr := table.NewWriter()
  57. wr.AppendHeader(table.Row{"ID", "Name"})
  58. wr.AppendRow(table.Row{pkg.PackageID, pkg.Name})
  59. fmt.Println(wr.Render())
  60. }
  61. */

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