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.

commandline.go 914 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package cmdline
  2. import (
  3. "fmt"
  4. "os"
  5. "gitlink.org.cn/cloudream/client/internal/services"
  6. "gitlink.org.cn/cloudream/common/pkg/cmdtrie"
  7. )
  8. type CommandContext struct {
  9. Cmdline *Commandline
  10. }
  11. var commands cmdtrie.CommandTrie[CommandContext, error] = cmdtrie.NewCommandTrie[CommandContext, error]()
  12. type Commandline struct {
  13. Svc *services.Service
  14. }
  15. func NewCommandline(svc *services.Service) (*Commandline, error) {
  16. return &Commandline{
  17. Svc: svc,
  18. }, nil
  19. }
  20. func (c *Commandline) DispatchCommand(allArgs []string) {
  21. // TODO 需要区分nil数组和空数组
  22. cmdCtx := CommandContext{
  23. Cmdline: c,
  24. }
  25. cmdErr, err := commands.Execute(cmdCtx, allArgs, cmdtrie.ExecuteOption{ReplaceEmptyArrayWithNil: true})
  26. if err != nil {
  27. fmt.Printf("execute command failed, err: %s", err.Error())
  28. os.Exit(1)
  29. }
  30. if cmdErr != nil {
  31. fmt.Printf("execute command failed, err: %s", cmdErr.Error())
  32. os.Exit(1)
  33. }
  34. }

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