diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-13 10:01:59 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-13 10:01:59 +0200 |
| commit | 44a426c883a2c448d40a19903c822d03e5cf70af (patch) | |
| tree | dbb1fe11db1993c2cac7daf1c9930e37f44b38d1 /internal/run.go | |
| parent | cfddc5696f4956081630e3d394ef3d8c652af02e (diff) | |
chore: complete code quality audit fixesv1.2.6
- Fixed failing test in config_test.go (hardcoded date)
- Addressed unchecked error returns from Close() operations
- Refactored large functions to follow SRP (run.go and main.go)
- Added documentation to exported identifiers
- Fixed linting errors (error message capitalization, errcheck)
- Bumped version to v1.2.6
Diffstat (limited to 'internal/run.go')
| -rw-r--r-- | internal/run.go | 102 |
1 files changed, 72 insertions, 30 deletions
diff --git a/internal/run.go b/internal/run.go index 34874fc..43874bf 100644 --- a/internal/run.go +++ b/internal/run.go @@ -23,49 +23,33 @@ func run(ctx context.Context, args config.Args) error { printLogo() // Check if posting is paused - paused, err := args.Config.IsPaused() - if err != nil { - return fmt.Errorf("error checking pause status: %w", err) - } - if paused { - colour.Infoln("Posting is paused until", args.Config.PauseEnd, "- skipping all posts") - return nil + if err := checkPauseStatus(args); err != nil { + return err } + // Handle compose mode if args.ComposeMode { - entryPath := fmt.Sprintf("%s/%d.ask.txt", args.GosDir, now) - if err := prompt.EditFile(entryPath); err != nil { + if err := handleComposeMode(args); err != nil { return err } } - if err := queue.Run(args); err != nil { - if !softError(err) { - return err - } - colour.Infoln(err) + // Run queue operations + if err := runQueueOperations(args); err != nil { + return err } - sinceLastRun := time.Duration(now-args.Config.LastRunEpoch) * time.Second - if sinceLastRun < args.RunInterval { - colour.Infoln("Run interval of", args.RunInterval, "with", sinceLastRun, "not yet reached. Not posting anything!") - return nil + // Check run interval + if err := checkRunInterval(args); err != nil { + return err } - for platformStr, sizeLimit := range args.Platforms { - platform, err := platforms.New(platformStr) - if err != nil { - return err - } - if err := runPlatform(ctx, args, platform, sizeLimit); err != nil { - if softError(err) { - colour.Infoln(err) - continue - } - return err - } + // Post to platforms + if err := postToPlatforms(ctx, args); err != nil { + return err } + // Update last run time args.Config.LastRunEpoch = now return args.Config.WriteToDisk(args.ConfigPath) } @@ -95,6 +79,64 @@ func runPlatform(ctx context.Context, args config.Args, platform platforms.Platf return err } +func checkPauseStatus(args config.Args) error { + // Check if posting is paused + paused, err := args.Config.IsPaused() + if err != nil { + return fmt.Errorf("error checking pause status: %w", err) + } + if paused { + colour.Infoln("Posting is paused until", args.Config.PauseEnd, "- skipping all posts") + return nil + } + return nil +} + +func handleComposeMode(args config.Args) error { + entryPath := fmt.Sprintf("%s/%d.ask.txt", args.GosDir, time.Now().Unix()) + if err := prompt.EditFile(entryPath); err != nil { + return err + } + return nil +} + +func runQueueOperations(args config.Args) error { + if err := queue.Run(args); err != nil { + if !softError(err) { + return err + } + colour.Infoln(err) + } + return nil +} + +func checkRunInterval(args config.Args) error { + now := time.Now().Unix() + sinceLastRun := time.Duration(now-args.Config.LastRunEpoch) * time.Second + if sinceLastRun < args.RunInterval { + colour.Infoln("Run interval of", args.RunInterval, "with", sinceLastRun, "not yet reached. Not posting anything!") + return nil + } + return nil +} + +func postToPlatforms(ctx context.Context, args config.Args) error { + for platformStr, sizeLimit := range args.Platforms { + platform, err := platforms.New(platformStr) + if err != nil { + return err + } + if err := runPlatform(ctx, args, platform, sizeLimit); err != nil { + if softError(err) { + colour.Infoln(err) + continue + } + return err + } + } + return nil +} + func softError(err error) bool { return errors.Is(err, prompt.ErrAborted) } |
