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