summaryrefslogtreecommitdiff
path: root/internal/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/main.go')
-rw-r--r--internal/main.go36
1 files changed, 22 insertions, 14 deletions
diff --git a/internal/main.go b/internal/main.go
index 198a584..ea5d527 100644
--- a/internal/main.go
+++ b/internal/main.go
@@ -13,15 +13,18 @@ import (
"codeberg.org/snonux/gos/internal/schedule"
)
+// Main is the entry point for the Gos application.
+// It parses command-line flags, loads configuration, and starts the main run loop.
+// composeModeDefault determines whether the compose mode is enabled by default.
func Main(composeModeDefault bool) {
+ // Parse flags
dry := flag.Bool("dry", false, "Dry run")
version := flag.Bool("version", false, "Display version")
composeMode := flag.Bool("compose", composeModeDefault, "Compose a new entry")
gosDir := flag.String("gosDir", filepath.Join(os.Getenv("HOME"), ".gosdir"), "Gos' queue and DB directory")
- cacheDir := flag.String("cacheDir", filepath.Join(*gosDir, "cache"), "Go's cache dir")
+ // cacheDir := flag.String("cacheDir", filepath.Join(*gosDir, "cache"), "Go's cache dir")
browser := flag.String("browser", "firefox", "OAuth2 browser")
- configPath := filepath.Join(os.Getenv("HOME"), ".config/gos/gos.json")
- configPath = *flag.String("configPath", configPath, "Gos' config file path")
+ configPath := flag.String("configPath", filepath.Join(os.Getenv("HOME"), ".config/gos/gos.json"), "Gos' config file path")
platforms := flag.String("platforms", "Mastodon:500,LinkedIn:1000,Noop:2000", "Platforms enabled plus their post size limits")
target := flag.Int("target", 2, "How many posts per week are the target?")
minQueued := flag.Int("minQueued", 42, "Minimum of queued items until printing a warn message!")
@@ -30,16 +33,19 @@ func Main(composeModeDefault bool) {
runInterval := flag.Int("runInterval", 6, "How many hours to wait for the next run.")
lookback := flag.Int("lookback", 42, "How many days look back in time for posting history")
geminiSummaryFor := flag.String("geminiSummaryFor", "", "Generate a summary in Gemini Gemtext format, format is coma separated string of months, e.g. 202410,202411")
- geminiCapsules := flag.String("geminiCapsules", "foo.zone", "Comma sepaeated list Gemini capsules. Used by geminiEnable to detect Gemtext links")
+ geminiCapsules := flag.String("geminiCapsules", "foo.zone", "Comma separated list Gemini capsules. Used by geminiEnable to detect Gemtext links")
gemtexterEnable := flag.Bool("gemtexterEnable", false, "Add special Gemtexter (the static site generator) tags to the Gemini Gemtext summary")
statsOnly := flag.Bool("stats", false, "Print statistics for all social networks and exit")
+
flag.Parse()
- conf, err := config.New(configPath, *composeMode)
- if err != nil {
- log.Fatal(err)
+ // Handle version flag
+ if *version {
+ printVersion()
+ return
}
+ // Create args from parsed flags
args := config.Args{
DryRun: *dry,
GosDir: *gosDir,
@@ -49,9 +55,7 @@ func Main(composeModeDefault bool) {
PauseDays: *pauseDays,
RunInterval: time.Duration(*runInterval) * time.Hour, // TODO: Document
Lookback: time.Duration(*lookback) * time.Hour * 24,
- ConfigPath: configPath,
- Config: conf,
- CacheDir: *cacheDir,
+ ConfigPath: *configPath,
OAuth2Browser: *browser,
GemtexterEnable: *gemtexterEnable,
GeminiCapsules: strings.Split(*geminiCapsules, ","),
@@ -62,15 +66,19 @@ func Main(composeModeDefault bool) {
args.GeminiSummaryFor = strings.Split(*geminiSummaryFor, ",")
}
- if err := args.ParsePlatforms(*platforms); err != nil {
+ // Load configuration
+ conf, err := config.New(args.ConfigPath, args.ComposeMode)
+ if err != nil {
log.Fatal(err)
}
+ args.Config = conf
- if *version {
- printVersion()
- return
+ // Parse platforms
+ if err := args.ParsePlatforms(*platforms); err != nil {
+ log.Fatal(err)
}
+ // Handle stats only flag
if args.StatsOnly {
// Call the new function to print all stats
schedule.PrintAllStats(args)