Merge pull request #127 from writeas/shorter-config-process

Shorter config process
pull/137/head
Matt Baer 6 years ago committed by GitHub
commit 18bafadc43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      app.go
  2. 5
      cmd/writefreely/main.go
  3. 23
      config/setup.go

@ -443,8 +443,19 @@ func CreateConfig(app *App) error {
}
// DoConfig runs the interactive configuration process.
func DoConfig(app *App) {
d, err := config.Configure(app.cfgFile)
func DoConfig(app *App, configSections string) {
if configSections == "" {
configSections = "server db app"
}
// let's check there aren't any garbage in the list
configSectionsArray := strings.Split(configSections, " ")
for _, element := range configSectionsArray {
if element != "server" && element != "db" && element != "app" {
log.Error("Invalid argument to --sections. Valid arguments are only \"server\", \"db\" and \"app\"")
os.Exit(1)
}
}
d, err := config.Configure(app.cfgFile, configSections)
if err != nil {
log.Error("Unable to configure: %v", err)
os.Exit(1)

@ -28,6 +28,9 @@ func main() {
// Setup actions
createConfig := flag.Bool("create-config", false, "Creates a basic configuration and exits")
doConfig := flag.Bool("config", false, "Run the configuration process")
configSections := flag.String("sections", "server db app", "Which sections of the configuration to go through (requires --config), "+
"valid values are any combination of 'server', 'db' and 'app' "+
"example: writefreely --config --sections \"db app\"")
genKeys := flag.Bool("gen-keys", false, "Generate encryption and authentication keys")
createSchema := flag.Bool("init-db", false, "Initialize app database")
migrate := flag.Bool("migrate", false, "Migrate the database")
@ -52,7 +55,7 @@ func main() {
}
os.Exit(0)
} else if *doConfig {
writefreely.DoConfig(app)
writefreely.DoConfig(app, *configSections)
os.Exit(0)
} else if *genKeys {
err := writefreely.GenerateKeyFiles(app)

@ -17,6 +17,7 @@ import (
"github.com/mitchellh/go-wordwrap"
"github.com/writeas/web-core/auth"
"strconv"
"strings"
)
type SetupData struct {
@ -24,7 +25,7 @@ type SetupData struct {
Config *Config
}
func Configure(fname string) (*SetupData, error) {
func Configure(fname string, configSections string) (*SetupData, error) {
data := &SetupData{}
var err error
if fname == "" {
@ -52,9 +53,6 @@ func Configure(fname string) (*SetupData, error) {
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))
fmt.Println()
title(" Server setup ")
fmt.Println()
tmpls := &promptui.PromptTemplates{
Success: "{{ . | bold | faint }}: ",
}
@ -62,8 +60,15 @@ func Configure(fname string) (*SetupData, error) {
Selected: fmt.Sprintf(`{{.Label}} {{ . | faint }}`),
}
var selPrompt promptui.Select
var prompt promptui.Prompt
if strings.Contains(configSections, "server") {
title(" Server setup ")
fmt.Println()
// Environment selection
selPrompt := promptui.Select{
selPrompt = promptui.Select{
Templates: selTmpls,
Label: "Environment",
Items: []string{"Development", "Production, standalone", "Production, behind reverse proxy"},
@ -77,7 +82,6 @@ func Configure(fname string) (*SetupData, error) {
data.Config.Server.Dev = isDevEnv
var prompt promptui.Prompt
if isDevEnv || !isStandalone {
// Running in dev environment or behind reverse proxy; ask for port
prompt = promptui.Prompt{
@ -138,6 +142,9 @@ func Configure(fname string) (*SetupData, error) {
}
fmt.Println()
}
if strings.Contains(configSections, "db") {
title(" Database setup ")
fmt.Println()
@ -228,6 +235,9 @@ func Configure(fname string) (*SetupData, error) {
}
fmt.Println()
}
if strings.Contains(configSections, "app") {
title(" App setup ")
fmt.Println()
@ -357,6 +367,7 @@ func Configure(fname string) (*SetupData, error) {
}
data.Config.App.Private = fedStatsType == "Private"
}
}
return data, Save(data.Config, fname)
}

Loading…
Cancel
Save