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.

50 lines
802 B

  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 a directory /path/to/dir
  15. The full path can be too long to type. For example,
  16. fs.ls /some/path/to/file_name
  17. can be simplified as
  18. fs.cd /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. path, err := commandEnv.parseUrl(findInputDirectory(args))
  24. if err != nil {
  25. return err
  26. }
  27. if path == "/" {
  28. commandEnv.option.Directory = "/"
  29. return nil
  30. }
  31. err = commandEnv.checkDirectory(path)
  32. if err == nil {
  33. commandEnv.option.Directory = path
  34. }
  35. return err
  36. }