aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSaiyed Shizain <saiyedshizain@gmail.com>2026-07-13 20:21:01 +0530
committerGitHub <noreply@github.com>2026-07-13 20:21:01 +0530
commitccd5a186594d9e9d174cca862953ab8355c1312f (patch)
tree02e4356c671e3a71ef3910bd3c0635daf9d12aaa
parent5d4eaf85434658f6fed621016e0bc2bae59e88d1 (diff)
parent72ef8ea5ac664b40b2b3cff632b821d8a06453c0 (diff)
downloadgalleryd-ccd5a186594d9e9d174cca862953ab8355c1312f.tar.xz
galleryd-ccd5a186594d9e9d174cca862953ab8355c1312f.zip
Merge pull request #9 from RanXom/feat/cli
Feat/cli: add commandline configuration
-rw-r--r--cmd/galleryd/defaults.go27
-rw-r--r--cmd/galleryd/flags.go15
-rw-r--r--cmd/galleryd/log.go15
-rw-r--r--cmd/galleryd/main.go41
4 files changed, 91 insertions, 7 deletions
diff --git a/cmd/galleryd/defaults.go b/cmd/galleryd/defaults.go
new file mode 100644
index 0000000..17d097d
--- /dev/null
+++ b/cmd/galleryd/defaults.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "log"
+ "os"
+ "path/filepath"
+)
+
+// defaultPicturesDir returns the user's Pictures directory.
+func defaultPicturesDir() string {
+ home, err := os.UserHomeDir()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ return filepath.Join(home, "Pictures")
+}
+
+// defaultCacheDir returns the default galleryd cache directory.
+func defaultCacheDir() string {
+ cache, err := os.UserCacheDir()
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ return filepath.Join(cache, "galleryd")
+}
diff --git a/cmd/galleryd/flags.go b/cmd/galleryd/flags.go
new file mode 100644
index 0000000..d3240d7
--- /dev/null
+++ b/cmd/galleryd/flags.go
@@ -0,0 +1,15 @@
+package main
+
+import "strings"
+
+// stringSliceFlag collects repeated string flags.
+type stringSliceFlag []string
+
+func (f *stringSliceFlag) String() string {
+ return strings.Join(*f, ",")
+}
+
+func (f *stringSliceFlag) Set(value string) error {
+ *f = append(*f, value)
+ return nil
+}
diff --git a/cmd/galleryd/log.go b/cmd/galleryd/log.go
new file mode 100644
index 0000000..08c2065
--- /dev/null
+++ b/cmd/galleryd/log.go
@@ -0,0 +1,15 @@
+package main
+
+import (
+ "fmt"
+ "strings"
+)
+
+func listenURL(addr string) string {
+ switch {
+ case strings.HasPrefix(addr, ":"):
+ return fmt.Sprintf("http://localhost%s", addr)
+ default:
+ return fmt.Sprintf("http://%s", addr)
+ }
+}
diff --git a/cmd/galleryd/main.go b/cmd/galleryd/main.go
index 41b62cf..1edd68a 100644
--- a/cmd/galleryd/main.go
+++ b/cmd/galleryd/main.go
@@ -2,10 +2,10 @@ package main
import (
"context"
+ "flag"
"log"
"os"
"os/signal"
- "path/filepath"
"syscall"
"github.com/RanXom/galleryd/internal/api"
@@ -17,6 +17,35 @@ import (
)
func main() {
+ cacheDir := flag.String(
+ "cache-dir",
+ defaultCacheDir(),
+ "thumbnail cache directory",
+ )
+
+ addr := flag.String(
+ "addr",
+ ":8082",
+ "HTTP listen address (e.g. :8082, localhost:8082, 0.0.0.0:8082)",
+ )
+
+ var dirs stringSliceFlag
+
+ flag.Var(
+ &dirs,
+ "dir",
+ "gallery directory (may be specified multiple times)",
+ )
+
+ flag.Parse()
+
+ if len(dirs) == 0 {
+ dirs = append(
+ dirs,
+ defaultPicturesDir(),
+ )
+ }
+
ctx, stop := signal.NotifyContext(
context.Background(),
os.Interrupt,
@@ -25,9 +54,7 @@ func main() {
defer stop()
scanner := scanner.New(scanner.Config{
- Roots: []string{
- filepath.Join(os.Getenv("HOME"), "Pictures"),
- },
+ Roots: dirs,
})
reader := metadata.New()
@@ -42,18 +69,18 @@ func main() {
log.Fatal(err)
}
- thumbnailGenerator, err := thumbnail.New(".cache/galleryd")
+ thumbnailGenerator, err := thumbnail.New(*cacheDir)
if err != nil {
log.Fatal(err)
}
server := api.New(api.Config{
- Address: ":8082",
+ Address: *addr,
Gallery: galleryService,
Thumbnails: thumbnailGenerator,
})
- log.Println("galleryd listening on :8082")
+ log.Printf("galleryd listening on %s", listenURL(*addr))
if err := server.Run(ctx); err != nil {
log.Fatal(err)