shell.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package command
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/security"
  5. "github.com/chrislusf/seaweedfs/weed/shell"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. "github.com/spf13/viper"
  8. )
  9. var (
  10. shellOptions shell.ShellOptions
  11. shellInitialFilerUrl *string
  12. )
  13. func init() {
  14. cmdShell.Run = runShell // break init cycle
  15. shellOptions.Masters = cmdShell.Flag.String("master", "localhost:9333", "comma-separated master servers")
  16. shellInitialFilerUrl = cmdShell.Flag.String("filer.url", "http://localhost:8888/", "initial filer url")
  17. }
  18. var cmdShell = &Command{
  19. UsageLine: "shell",
  20. Short: "run interactive administrative commands",
  21. Long: `run interactive administrative commands.
  22. `,
  23. }
  24. func runShell(command *Command, args []string) bool {
  25. util.LoadConfiguration("security", false)
  26. shellOptions.GrpcDialOption = security.LoadClientTLS(viper.Sub("grpc"), "client")
  27. var filerPwdErr error
  28. shellOptions.FilerHost, shellOptions.FilerPort, shellOptions.Directory, filerPwdErr = util.ParseFilerUrl(*shellInitialFilerUrl)
  29. if filerPwdErr != nil {
  30. fmt.Printf("failed to parse url filer.url=%s : %v\n", *shellInitialFilerUrl, filerPwdErr)
  31. return false
  32. }
  33. shell.RunShell(shellOptions)
  34. return true
  35. }