summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-02-24 21:09:14 +0200
committerPaul Buetow <paul@buetow.org>2025-02-24 21:09:14 +0200
commite735b56a704b7328e7e84def46fd6d248c51e38d (patch)
tree34c2bf458d6d0a136439d6891afe490eac64faa3
parente957564316024f6412399015d2e8a7861e05ec82 (diff)
compose mode does not require any secrets
-rw-r--r--internal/config/args.go2
-rw-r--r--internal/config/secrets.go7
-rw-r--r--internal/main.go8
-rw-r--r--internal/oi/oi.go32
-rw-r--r--internal/run.go9
-rw-r--r--internal/schedule/stats.go4
6 files changed, 36 insertions, 26 deletions
diff --git a/internal/config/args.go b/internal/config/args.go
index cdaed8a..e2b9dc1 100644
--- a/internal/config/args.go
+++ b/internal/config/args.go
@@ -24,7 +24,7 @@ type Args struct {
GeminiSummaryFor []string
GemtexterEnable bool
GeminiCapsules []string
- ComposeEntry bool
+ ComposeMode bool
}
func (a *Args) ParsePlatforms(platformStrs string) error {
diff --git a/internal/config/secrets.go b/internal/config/secrets.go
index 338d17a..b4e629f 100644
--- a/internal/config/secrets.go
+++ b/internal/config/secrets.go
@@ -22,8 +22,13 @@ type Secrets struct {
LinkedInPersonID string `json:"LinkedInPersonID,omitempty"`
}
-func NewSecrets(configPath string) (Secrets, error) {
+func NewSecrets(configPath string, composeEntry bool) (Secrets, error) {
var sec Secrets
+ if composeEntry {
+ // In compose mode, no need to read the secrets.
+ return sec, nil
+ }
+
file, err := os.Open(configPath)
if err != nil {
return sec, fmt.Errorf("failed to open file: %w", err)
diff --git a/internal/main.go b/internal/main.go
index 842f010..7ae8390 100644
--- a/internal/main.go
+++ b/internal/main.go
@@ -13,10 +13,10 @@ import (
"codeberg.org/snonux/gos/internal/table"
)
-func Main(composeEntryDefault bool) {
+func Main(composeModeDefault bool) {
dry := flag.Bool("dry", false, "Dry run")
version := flag.Bool("version", false, "Display version")
- composeEntry := flag.Bool("compose", composeEntryDefault, "Compose a new entry")
+ 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")
browser := flag.String("browser", "firefox", "OAuth2 browser")
@@ -43,7 +43,7 @@ func Main(composeEntryDefault bool) {
os.Exit(0)
}
- secrets, err := config.NewSecrets(secretsConfigPath)
+ secrets, err := config.NewSecrets(secretsConfigPath, *composeMode)
if err != nil {
log.Fatal(err)
}
@@ -62,7 +62,7 @@ func Main(composeEntryDefault bool) {
OAuth2Browser: *browser,
GemtexterEnable: *gemtexterEnable,
GeminiCapsules: strings.Split(*geminiCapsules, ","),
- ComposeEntry: *composeEntry,
+ ComposeMode: *composeMode,
}
if *geminiSummaryFor != "" {
args.GeminiSummaryFor = strings.Split(*geminiSummaryFor, ",")
diff --git a/internal/oi/oi.go b/internal/oi/oi.go
index 824c0bd..2f1bc1a 100644
--- a/internal/oi/oi.go
+++ b/internal/oi/oi.go
@@ -49,7 +49,22 @@ func ReadDirCh[T any](dir string, cb func(file os.DirEntry) (T, bool)) (chan T,
return ch, nil
}
-func TraverseDir(dir string, cb func(file os.DirEntry) error) error {
+func ReadDir[T any](dir string, cb func(file os.DirEntry) (T, bool)) ([]T, error) {
+ var results []T
+
+ ch, err := ReadDirCh(dir, cb)
+ if err != nil {
+ return results, err
+ }
+
+ for file := range ch {
+ results = append(results, file)
+ }
+
+ return results, nil
+}
+
+func ForeachDirEntry(dir string, cb func(file os.DirEntry) error) error {
if err := EnsureDir(dir); err != nil {
return err
}
@@ -69,21 +84,6 @@ func TraverseDir(dir string, cb func(file os.DirEntry) error) error {
return errors.Join(errs...)
}
-func ReadDir[T any](dir string, cb func(file os.DirEntry) (T, bool)) ([]T, error) {
- var results []T
-
- ch, err := ReadDirCh(dir, cb)
- if err != nil {
- return results, err
- }
-
- for file := range ch {
- results = append(results, file)
- }
-
- return results, nil
-}
-
func ReadDirRandom[T any](dir string, cb func(file os.DirEntry) (T, bool)) (T, error) {
results, err := ReadDir(dir, cb)
diff --git a/internal/run.go b/internal/run.go
index ff25112..ac3f75e 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -20,7 +20,7 @@ func run(ctx context.Context, args config.Args) error {
return summary.Run(ctx, args)
}
- if args.ComposeEntry {
+ if args.ComposeMode {
entryPath := fmt.Sprintf("%s/%d.ask.txt", args.GosDir, time.Now().Unix())
if err := prompt.EditFile(entryPath); err != nil {
return err
@@ -63,9 +63,14 @@ func runPlatform(ctx context.Context, args config.Args, platform platforms.Platf
case err != nil:
return err
}
+
+ if args.ComposeMode {
+ colour.Infoln("Not posting any entry in compose mode!")
+ return nil
+ }
+
err = platform.Post(ctx, args, sizeLimit, en)
if errors.Is(err, prompt.ErrRamdomOther) || errors.Is(err, prompt.ErrDeleted) {
-
return runPlatform(ctx, args, platform, sizeLimit)
}
return err
diff --git a/internal/schedule/stats.go b/internal/schedule/stats.go
index c1b32f3..eba2eee 100644
--- a/internal/schedule/stats.go
+++ b/internal/schedule/stats.go
@@ -79,7 +79,7 @@ func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error {
totalOldest time.Time = now // All time oldest
)
- err := oi.TraverseDir(dir, func(file os.DirEntry) error {
+ err := oi.ForeachDirEntry(dir, func(file os.DirEntry) error {
filePath := filepath.Join(dir, file.Name())
ent, err := entry.New(filePath)
if err != nil {
@@ -127,7 +127,7 @@ func (s *stats) gatherPostedStats(dir string, lookbackTime time.Time) error {
func (s *stats) gatherQueuedStats(dir string) error {
var firstQueuedPath string
- err := oi.TraverseDir(dir, func(file os.DirEntry) error {
+ err := oi.ForeachDirEntry(dir, func(file os.DirEntry) error {
filePath := filepath.Join(dir, file.Name())
ent, err := entry.New(filePath)
if err != nil {