about summary refs log tree commit diff stats
path: root/searchix.go
diff options
context:
space:
mode:
authorAlan Pearce2024-05-20 18:10:43 +0200
committerAlan Pearce2024-05-20 18:10:43 +0200
commit60a15699657cef86d1a644c0d13b0d117a818633 (patch)
tree491ac1e698958acb0f9f9ad7d51ce7dd06d76900 /searchix.go
parent6037d5c33e9b98360f61a4fe4f09659d0e3e6160 (diff)
downloadsearchix-60a15699657cef86d1a644c0d13b0d117a818633.tar.lz
searchix-60a15699657cef86d1a644c0d13b0d117a818633.tar.zst
searchix-60a15699657cef86d1a644c0d13b0d117a818633.zip
feat: show default configuration with --print-default-config
Diffstat (limited to 'searchix.go')
-rw-r--r--searchix.go27
1 files changed, 23 insertions, 4 deletions
diff --git a/searchix.go b/searchix.go
index c2cd19d..605db55 100644
--- a/searchix.go
+++ b/searchix.go
@@ -23,10 +23,19 @@ import (
 var buildVersion string
 
 var (
-	configFile = flag.String("config", "config.toml", "config `file` to use")
+	configFile         = flag.String("config", "config.toml", "config `file` to use")
+	printDefaultConfig = flag.Bool(
+		"print-default-config",
+		false,
+		"print default configuration and exit",
+	)
 	liveReload = flag.Bool("live", false, "whether to enable live reloading (development)")
-	replace    = flag.Bool("replace", false, "whether to replace existing database, if it exists")
-	version    = flag.Bool("version", false, "print version information")
+	replace    = flag.Bool(
+		"replace",
+		false,
+		"whether to replace existing database, if it exists",
+	)
+	version = flag.Bool("version", false, "print version information")
 )
 
 func nextOccurrenceOfLocalTime(t toml.LocalTime) time.Time {
@@ -56,7 +65,17 @@ func main() {
 		if buildVersion != config.CommitSHA && buildVersion != config.ShortSHA {
 			fmt.Fprintf(os.Stderr, " %s", config.CommitSHA)
 		}
-		fmt.Fprint(os.Stderr, "\n")
+		_, err := fmt.Fprint(os.Stderr, "\n")
+		if err != nil {
+			panic("can't write to standard error?!")
+		}
+		os.Exit(0)
+	}
+	if *printDefaultConfig {
+		_, err := fmt.Print(config.GetDefaultConfig())
+		if err != nil {
+			panic("can't write to standard output?!")
+		}
 		os.Exit(0)
 	}