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