From 1d5c396327c036b2448628d806f351ea516191ce Mon Sep 17 00:00:00 2001 From: Michael Demetriou Date: Thu, 20 Jun 2019 23:14:36 +0300 Subject: [PATCH] Add --sections flag to app.go and pass it to setup.go Add --sections flag to app.go according to T657, parse them into a string array (check for invalid arguments and abort) and pass them to Configure(). For now Configure() doesn't do anything with them yet. --- app.go | 16 +++++++++++++++- config/setup.go | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index 540b496..f7c8d08 100644 --- a/app.go +++ b/app.go @@ -198,6 +198,9 @@ func Serve() { // 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") @@ -229,7 +232,18 @@ func Serve() { } os.Exit(0) } else if *doConfig { - d, err := config.Configure(app.cfgFile) + if *configSections == "" { + *configSections = "server db app" + } + configSectionsArray := strings.Split(*configSections, " ") + + // let's check there aren't any garbage in the list + 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\"") + } + } + d, err := config.Configure(app.cfgFile, configSectionsArray) if err != nil { log.Error("Unable to configure: %v", err) os.Exit(1) diff --git a/config/setup.go b/config/setup.go index 4950bc3..5d806ea 100644 --- a/config/setup.go +++ b/config/setup.go @@ -24,7 +24,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 == "" {