2019-04-03 15:20:00 +08:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
2019-06-05 16:30:24 +08:00
|
|
|
Commands = append(Commands, &commandFsCd{})
|
2019-04-03 15:20:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
type commandFsCd struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsCd) Name() string {
|
|
|
|
return "fs.cd"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *commandFsCd) Help() string {
|
2020-03-24 11:46:17 +08:00
|
|
|
return `change directory to a directory /path/to/dir
|
2019-04-03 15:20:00 +08:00
|
|
|
|
|
|
|
The full path can be too long to type. For example,
|
2020-03-24 11:46:17 +08:00
|
|
|
fs.ls /some/path/to/file_name
|
2019-04-03 15:20:00 +08:00
|
|
|
|
|
|
|
can be simplified as
|
|
|
|
|
2020-03-24 11:46:17 +08:00
|
|
|
fs.cd /some/path
|
2019-04-03 15:20:00 +08:00
|
|
|
fs.ls to/file_name
|
|
|
|
`
|
|
|
|
}
|
|
|
|
|
2024-09-30 01:38:22 +08:00
|
|
|
func (c *commandFsCd) HasTag(CommandTag) bool {
|
2024-09-29 11:22:57 +08:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-06-05 16:30:24 +08:00
|
|
|
func (c *commandFsCd) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
|
2019-04-03 15:20:00 +08:00
|
|
|
|
2020-03-24 12:26:15 +08:00
|
|
|
path, err := commandEnv.parseUrl(findInputDirectory(args))
|
2019-04-03 15:20:00 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-04-05 10:27:51 +08:00
|
|
|
if path == "/" {
|
|
|
|
commandEnv.option.Directory = "/"
|
|
|
|
return nil
|
2019-04-03 15:20:00 +08:00
|
|
|
}
|
|
|
|
|
2020-03-24 12:26:15 +08:00
|
|
|
err = commandEnv.checkDirectory(path)
|
2019-04-03 15:20:00 +08:00
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
commandEnv.option.Directory = path
|
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|