aboutsummaryrefslogtreecommitdiff
path: root/weed/shell/command_fs_cd.go
diff options
context:
space:
mode:
authorbingoohuang <bingoo.huang@gmail.com>2019-07-16 11:13:23 +0800
committerGitHub <noreply@github.com>2019-07-16 11:13:23 +0800
commitd19bbee98d89ec6cd603572bd9c5d55749610e61 (patch)
tree8d760dcee4dfcb4404af90b7d5e64def4549b4cc /weed/shell/command_fs_cd.go
parent01060c992591f412b0d5e180bde29991747a9462 (diff)
parent5b5e443d5b9985fd77f3d5470f1d5885a88bf2b9 (diff)
downloadseaweedfs-d19bbee98d89ec6cd603572bd9c5d55749610e61.tar.xz
seaweedfs-d19bbee98d89ec6cd603572bd9c5d55749610e61.zip
keep update from original (#1)
keep update from original
Diffstat (limited to 'weed/shell/command_fs_cd.go')
-rw-r--r--weed/shell/command_fs_cd.go59
1 files changed, 59 insertions, 0 deletions
diff --git a/weed/shell/command_fs_cd.go b/weed/shell/command_fs_cd.go
new file mode 100644
index 000000000..408ec86c8
--- /dev/null
+++ b/weed/shell/command_fs_cd.go
@@ -0,0 +1,59 @@
+package shell
+
+import (
+ "context"
+ "io"
+)
+
+func init() {
+ Commands = append(Commands, &commandFsCd{})
+}
+
+type commandFsCd struct {
+}
+
+func (c *commandFsCd) Name() string {
+ return "fs.cd"
+}
+
+func (c *commandFsCd) Help() string {
+ return `change directory to http://<filer_server>:<port>/dir/
+
+ The full path can be too long to type. For example,
+ fs.ls http://<filer_server>:<port>/some/path/to/file_name
+
+ can be simplified as
+
+ fs.cd http://<filer_server>:<port>/some/path
+ fs.ls to/file_name
+`
+}
+
+func (c *commandFsCd) Do(args []string, commandEnv *CommandEnv, writer io.Writer) (err error) {
+
+ input := findInputDirectory(args)
+
+ filerServer, filerPort, path, err := commandEnv.parseUrl(input)
+ if err != nil {
+ return err
+ }
+
+ if path == "/" {
+ commandEnv.option.FilerHost = filerServer
+ commandEnv.option.FilerPort = filerPort
+ commandEnv.option.Directory = "/"
+ return nil
+ }
+
+ ctx := context.Background()
+
+ err = commandEnv.checkDirectory(ctx, filerServer, filerPort, path)
+
+ if err == nil {
+ commandEnv.option.FilerHost = filerServer
+ commandEnv.option.FilerPort = filerPort
+ commandEnv.option.Directory = path
+ }
+
+ return err
+}