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.

54 lines
867 B

3 months ago
  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) HasTag(CommandTag) bool {
  23. return false
  24. }
  25. func (c *commandFsCd) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
  26. path, err := commandEnv.parseUrl(findInputDirectory(args))
  27. if err != nil {
  28. return err
  29. }
  30. if path == "/" {
  31. commandEnv.option.Directory = "/"
  32. return nil
  33. }
  34. err = commandEnv.checkDirectory(path)
  35. if err == nil {
  36. commandEnv.option.Directory = path
  37. }
  38. return err
  39. }