MCPcopy
hub / github.com/writefreely/writefreely / Configure

Function Configure

config/setup.go:30–396  ·  view source on GitHub ↗
(fname string, configSections string)

Source from the content-addressed store, hash-verified

28}
29
30func Configure(fname string, configSections string) (*SetupData, error) {
31 data := &SetupData{}
32 var err error
33 if fname == "" {
34 fname = FileName
35 }
36
37 data.Config, err = Load(fname)
38 var action string
39 isNewCfg := false
40 if err != nil {
41 fmt.Printf("No %s configuration yet. Creating new.\n", fname)
42 data.Config = New()
43 action = "generate"
44 isNewCfg = true
45 } else {
46 fmt.Printf("Loaded configuration %s.\n", fname)
47 action = "update"
48 }
49 title := color.New(color.Bold, color.BgGreen).PrintFunc()
50
51 intro := color.New(color.Bold, color.FgWhite).PrintlnFunc()
52 fmt.Println()
53 intro(" ✍ WriteFreely Configuration ✍")
54 fmt.Println()
55 fmt.Println(wordwrap.WrapString(" This quick configuration process will "+action+" the application's config file, "+fname+".\n\n It validates your input along the way, so you can be sure any future errors aren't caused by a bad configuration. If you'd rather configure your server manually, instead run: writefreely --create-config and edit that file.", 75))
56 fmt.Println()
57
58 tmpls := &promptui.PromptTemplates{
59 Success: "{{ . | bold | faint }}: ",
60 }
61 selTmpls := &promptui.SelectTemplates{
62 Selected: `{{.Label}} {{ . | faint }}`,
63 }
64
65 var selPrompt promptui.Select
66 var prompt promptui.Prompt
67
68 if strings.Contains(configSections, "server") {
69 title(" Server setup ")
70 fmt.Println()
71
72 // Environment selection
73 selPrompt = promptui.Select{
74 Templates: selTmpls,
75 Label: "Environment",
76 Items: []string{"Development", "Production, standalone", "Production, behind reverse proxy"},
77 }
78 _, envType, err := selPrompt.Run()
79 if err != nil {
80 return data, err
81 }
82 isDevEnv := envType == "Development"
83 isStandalone := envType == "Production, standalone"
84
85 _, isDocker := os.LookupEnv("WRITEFREELY_DOCKER")
86
87 data.Config.Server.Dev = isDevEnv

Callers 1

DoConfigFunction · 0.92

Calls 5

LoadFunction · 0.85
SaveFunction · 0.85
UseMySQLMethod · 0.80
UseSQLiteMethod · 0.80
NewFunction · 0.70

Tested by

no test coverage detected