scaffold.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package command
  2. import (
  3. "fmt"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. "path/filepath"
  6. "github.com/chrislusf/seaweedfs/weed/command/scaffold"
  7. )
  8. func init() {
  9. cmdScaffold.Run = runScaffold // break init cycle
  10. }
  11. var cmdScaffold = &Command{
  12. UsageLine: "scaffold -config=[filer|notification|replication|security|master]",
  13. Short: "generate basic configuration files",
  14. Long: `Generate filer.toml with all possible configurations for you to customize.
  15. The options can also be overwritten by environment variables.
  16. For example, the filer.toml mysql password can be overwritten by environment variable
  17. export WEED_MYSQL_PASSWORD=some_password
  18. Environment variable rules:
  19. * Prefix the variable name with "WEED_"
  20. * Upppercase the reset of variable name.
  21. * Replace '.' with '_'
  22. `,
  23. }
  24. var (
  25. outputPath = cmdScaffold.Flag.String("output", "", "if not empty, save the configuration file to this directory")
  26. config = cmdScaffold.Flag.String("config", "filer", "[filer|notification|replication|security|master] the configuration file to generate")
  27. )
  28. func runScaffold(cmd *Command, args []string) bool {
  29. content := ""
  30. switch *config {
  31. case "filer":
  32. content = scaffold.Filer
  33. case "notification":
  34. content = scaffold.Notification
  35. case "replication":
  36. content = scaffold.Replication
  37. case "security":
  38. content = scaffold.Security
  39. case "master":
  40. content = scaffold.Master
  41. case "shell":
  42. content = scaffold.Shell
  43. }
  44. if content == "" {
  45. println("need a valid -config option")
  46. return false
  47. }
  48. if *outputPath != "" {
  49. util.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0644)
  50. } else {
  51. fmt.Println(content)
  52. }
  53. return true
  54. }