aboutsummaryrefslogtreecommitdiff
path: root/weed/command/shell.go
blob: 91aa8770a1f590bff4971694d4fd1b7a7a6f6885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package command

import (
	"fmt"
	"net/url"
	"strconv"
	"strings"

	"github.com/chrislusf/seaweedfs/weed/security"
	"github.com/chrislusf/seaweedfs/weed/shell"
	"github.com/chrislusf/seaweedfs/weed/util"
	"github.com/spf13/viper"
)

var (
	shellOptions         shell.ShellOptions
	shellInitialFilerUrl *string
)

func init() {
	cmdShell.Run = runShell // break init cycle
	shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers")
	shellInitialFilerUrl = cmdShell.Flag.String("filer.url", "http://localhost:8888/", "initial filer url")
}

var cmdShell = &Command{
	UsageLine: "shell",
	Short:     "run interactive administrative commands",
	Long: `run interactive administrative commands.

  `,
}

func runShell(command *Command, args []string) bool {

	util.LoadConfiguration("security", false)
	shellOptions.GrpcDialOption = security.LoadClientTLS(viper.Sub("grpc"), "client")

	var filerPwdErr error
	shellOptions.FilerHost, shellOptions.FilerPort, shellOptions.Directory, filerPwdErr = parseFilerUrl(*shellInitialFilerUrl)
	if filerPwdErr != nil {
		fmt.Printf("failed to parse url filer.url=%s : %v\n", *shellInitialFilerUrl, filerPwdErr)
		return false
	}

	shell.RunShell(shellOptions)

	return true

}

func parseFilerUrl(entryPath string) (filerServer string, filerPort int64, path string, err error) {
	if !strings.HasPrefix(entryPath, "http://") && !strings.HasPrefix(entryPath, "https://") {
		entryPath = "http://" + entryPath
	}

	var u *url.URL
	u, err = url.Parse(entryPath)
	if err != nil {
		return
	}
	filerServer = u.Hostname()
	portString := u.Port()
	if portString != "" {
		filerPort, err = strconv.ParseInt(portString, 10, 32)
	}
	path = u.Path
	return
}