summaryrefslogtreecommitdiff
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
parent97b93252dfcb0242bb1cd5e3e5793a8ae73b17a9 (diff)
add gosc binary
-rw-r--r--.gitignore1
-rw-r--r--Taskfile.yml5
-rw-r--r--cmd/gos/main.go71
-rw-r--r--cmd/gosc/main.go9
-rw-r--r--internal/main.go73
-rw-r--r--internal/run.go2
-rw-r--r--internal/version.go10
7 files changed, 98 insertions, 73 deletions
diff --git a/.gitignore b/.gitignore
index 9ac4315..2b065ff 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
./gosdir
./gos
+./gosd
diff --git a/Taskfile.yml b/Taskfile.yml
index 27e2323..22d21d7 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -7,6 +7,7 @@ tasks:
deps: ["build"]
cmds:
- cp -v ./gos ~/go/bin/
+ - cp -v ./gosc ~/go/bin/
run:
deps: ["dev"]
cmds:
@@ -14,10 +15,12 @@ tasks:
build:
cmds:
- go build -o gos cmd/gos/main.go
+ - go build -o gosc cmd/gosc/main.go
dev:
deps: ["test", "vet", "lint"]
cmds:
- go build -race -o gos cmd/gos/main.go
+ - go build -race -o gosc cmd/gosc/main.go
test:
cmds:
- go clean -testcache
@@ -36,5 +39,3 @@ tasks:
cmds:
- go install golang.org/x/tools/gopls@latest
- go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
-
-
diff --git a/cmd/gos/main.go b/cmd/gos/main.go
index 4e3ef68..f89b740 100644
--- a/cmd/gos/main.go
+++ b/cmd/gos/main.go
@@ -1,78 +1,9 @@
package main
import (
- "context"
- "flag"
- "fmt"
- "log"
- "os"
- "path/filepath"
- "strings"
- "time"
-
"codeberg.org/snonux/gos/internal"
- "codeberg.org/snonux/gos/internal/config"
)
-const versionStr = "v0.0.2"
-
func main() {
- 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", false, "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 {
- fmt.Printf("This is Gos version %s; (C) by Paul Buetow\n", versionStr)
- fmt.Println("https://codeberg.org/snonux/gos")
- return
- }
-
- ctx, cancel := context.WithCancel(context.Background())
- defer cancel()
-
- if err := internal.Run(ctx, args); err != nil {
- log.Fatal(err)
- }
+ internal.Main(false)
}
diff --git a/cmd/gosc/main.go b/cmd/gosc/main.go
new file mode 100644
index 0000000..02eb0ae
--- /dev/null
+++ b/cmd/gosc/main.go
@@ -0,0 +1,9 @@
+package main
+
+import (
+ "codeberg.org/snonux/gos/internal"
+)
+
+func main() {
+ internal.Main(true)
+}
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")
+}