From 94d9b5f48147ee9cc6ca57177e00f8679224603d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 11 Jan 2025 00:45:02 +0200 Subject: add gosc binary --- internal/main.go | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++ internal/run.go | 2 +- internal/version.go | 10 ++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 internal/main.go create mode 100644 internal/version.go (limited to 'internal') 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") +} -- cgit v1.2.3