command_fs_cd.go 1.1 KB

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