You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.1 KiB

  1. package shell
  2. import (
  3. "context"
  4. "io"
  5. )
  6. func init() {
  7. Commands = append(Commands, &commandFsCd{})
  8. }
  9. type commandFsCd struct {
  10. }
  11. func (c *commandFsCd) Name() string {
  12. return "fs.cd"
  13. }
  14. func (c *commandFsCd) Help() string {
  15. return `change directory to http://<filer_server>:<port>/dir/
  16. The full path can be too long to type. For example,
  17. fs.ls http://<filer_server>:<port>/some/path/to/file_name
  18. can be simplified as
  19. fs.cd http://<filer_server>:<port>/some/path
  20. fs.ls to/file_name
  21. `
  22. }
  23. func (c *commandFsCd) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  24. input := findInputDirectory(args)
  25. filerServer, filerPort, path, err := commandEnv.parseUrl(input)
  26. if err != nil {
  27. return err
  28. }
  29. if path == "/" {
  30. commandEnv.option.FilerHost = filerServer
  31. commandEnv.option.FilerPort = filerPort
  32. commandEnv.option.Directory = "/"
  33. return nil
  34. }
  35. ctx := context.Background()
  36. err = commandEnv.checkDirectory(ctx, filerServer, filerPort, path)
  37. if err == nil {
  38. commandEnv.option.FilerHost = filerServer
  39. commandEnv.option.FilerPort = filerPort
  40. commandEnv.option.Directory = path
  41. }
  42. return err
  43. }