scaffold.go 1.6 KB

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