summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-01-11 00:45:02 +0200
committerPaul Buetow <paul@buetow.org>2025-01-11 00:45:02 +0200
commit94d9b5f48147ee9cc6ca57177e00f8679224603d (patch)
treec3ae81b6c31c5deb0582fca475f156718a6dd380 /internal
parent97b93252dfcb0242bb1cd5e3e5793a8ae73b17a9 (diff)
add gosc binary
Diffstat (limited to 'internal')
-rw-r--r--internal/main.go73
-rw-r--r--internal/run.go2
-rw-r--r--internal/version.go10
3 files changed, 84 insertions, 1 deletions
diff --git a/internal/main.go b/internal/main.go
new file mode 100644
index 0000000..c3d6b19
--- /dev/null
+++ b/internal/main.go
@@ -0,0 +1,73 @@
+package internal
+
+import (
+ "context"
+ "flag"
+ "log"
+ "os"
+ "path/filepath"
+ "strings"
+ "time"
+
+ "codeberg.org/snonux/gos/internal/config"
+)
+
+func Main(composeEntryDefault bool) {
+ dry := flag.Bool("dry", false, "Dry run")
+ version := flag.Bool("version", false, "Display version")
+ 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")
+ secretsConfigPath := filepath.Join(os.Getenv("HOME"), ".config/gos/gosec.json")
+ secretsConfigPath = *flag.String("secretsConfig", secretsConfigPath, "Gos' secret config")
+ platforms := flag.String("platforms", "Mastodon:500,LinkedIn:1000", "Platforms enabled plus their post size limits")
+ target := flag.Int("target", 2, "How many posts per week are the target?")
+ minQueued := flag.Int("minQueued", 4, "Minimum of queued items until printing a warn message!")
+ maxDaysQueued := flag.Int("maxDaysQueued", 365, "Maximum days worth of queued posts until target++ and pauseDays--")
+ pauseDays := flag.Int("pauseDays", 3, "How many days until next post can be posted?")
+ lookback := flag.Int("lookback", 30, "How many days look back in time for posting history")
+ summaryFor := flag.String("summaryFor", "", "Generate a summary in Gemtext format, format is coma separated string of months, e.g. 202410,202411")
+ gemtexterEnable := flag.Bool("gemtexterEnable", true, "Add special Gemtexter tags to the Gemtext summary")
+ composeEntry := flag.Bool("compose", composeEntryDefault, "Compose a new entry")
+ flag.Parse()
+
+ secrets, err := config.NewSecrets(secretsConfigPath)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ args := config.Args{
+ DryRun: *dry,
+ GosDir: *gosDir,
+ Target: *target,
+ MinQueued: *minQueued,
+ MaxDaysQueued: *maxDaysQueued,
+ PauseDays: *pauseDays,
+ Lookback: time.Duration(*lookback) * time.Hour * 24,
+ SecretsConfigPath: secretsConfigPath,
+ CacheDir: *cacheDir,
+ Secrets: secrets,
+ OAuth2Browser: *browser,
+ GemtexterEnable: *gemtexterEnable,
+ ComposeEntry: *composeEntry,
+ }
+ if *summaryFor != "" {
+ args.SummaryFor = strings.Split(*summaryFor, ",")
+ }
+
+ if err := args.ParsePlatforms(*platforms); err != nil {
+ log.Fatal(err)
+ }
+
+ if *version {
+ printVersion()
+ return
+ }
+
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+
+ if err := run(ctx, args); err != nil {
+ log.Fatal(err)
+ }
+}
diff --git a/internal/run.go b/internal/run.go
index 904477b..b1f85e8 100644
--- a/internal/run.go
+++ b/internal/run.go
@@ -15,7 +15,7 @@ import (
"codeberg.org/snonux/gos/internal/summary"
)
-func Run(ctx context.Context, args config.Args) error {
+func run(ctx context.Context, args config.Args) error {
if len(args.SummaryFor) > 0 {
return summary.Run(ctx, args)
}
diff --git a/internal/version.go b/internal/version.go
new file mode 100644
index 0000000..0a2511c
--- /dev/null
+++ b/internal/version.go
@@ -0,0 +1,10 @@
+package internal
+
+import "fmt"
+
+const versionStr = "v0.0.3"
+
+func printVersion() {
+ fmt.Printf("This is Gos version %s; (C) by Paul Buetow\n", versionStr)
+ fmt.Println("https://codeberg.org/snonux/gos")
+}