seaweedfs/weed/command/scaffold.go

65 lines
1.7 KiB
Go
Raw Permalink Normal View History

2018-08-19 22:36:30 +00:00
package command
import (
"fmt"
"github.com/seaweedfs/seaweedfs/weed/util"
2018-08-19 22:36:30 +00:00
"path/filepath"
"github.com/seaweedfs/seaweedfs/weed/command/scaffold"
2018-08-19 22:36:30 +00:00
)
func init() {
cmdScaffold.Run = runScaffold // break init cycle
}
var cmdScaffold = &Command{
UsageLine: "scaffold -config=[filer|notification|replication|security|master]",
2018-08-19 22:36:30 +00:00
Short: "generate basic configuration files",
Long: `Generate filer.toml with all possible configurations for you to customize.
The options can also be overwritten by environment variables.
For example, the filer.toml mysql password can be overwritten by environment variable
2020-01-29 17:11:07 +00:00
export WEED_MYSQL_PASSWORD=some_password
Environment variable rules:
* Prefix the variable name with "WEED_".
* Uppercase the rest of the variable name.
* Replace '.' with '_'.
2018-08-19 22:36:30 +00:00
`,
}
var (
outputPath = cmdScaffold.Flag.String("output", "", "if not empty, save the configuration file to this directory")
config = cmdScaffold.Flag.String("config", "filer", "[filer|notification|replication|security|master] the configuration file to generate")
2018-08-19 22:36:30 +00:00
)
func runScaffold(cmd *Command, args []string) bool {
content := ""
switch *config {
case "filer":
content = scaffold.Filer
case "notification":
content = scaffold.Notification
2018-09-17 07:27:56 +00:00
case "replication":
content = scaffold.Replication
2019-02-10 05:07:12 +00:00
case "security":
content = scaffold.Security
case "master":
content = scaffold.Master
case "shell":
content = scaffold.Shell
2018-08-19 22:36:30 +00:00
}
if content == "" {
println("need a valid -config option")
return false
}
if *outputPath != "" {
2022-02-05 05:32:27 +00:00
util.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0644)
2018-08-19 22:36:30 +00:00
} else {
fmt.Println(content)
2018-08-19 22:36:30 +00:00
}
return true
}