aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgutmet <me.git@gutmet.org>2020-01-08 21:26:47 +0100
committergutmet <me.git@gutmet.org>2020-01-08 21:26:47 +0100
commit2c9adcc4037d045542d5b159b2ba796a81581cbb (patch)
tree5b9315a31e7b43e92457e065c3813351705c9d42
parent888fe75a34f078716682f8e89ed5746af03aec9a (diff)
downloadwombat-2c9adcc4037d045542d5b159b2ba796a81581cbb.tar.gz
change newgallery command to be non-interactive
-rw-r--r--gallery/new.go31
-rw-r--r--initer/initer.go3
-rw-r--r--wombat.go2
3 files changed, 26 insertions, 10 deletions
diff --git a/gallery/new.go b/gallery/new.go
index cfc46d7..a5328e1 100644
--- a/gallery/new.go
+++ b/gallery/new.go
@@ -1,21 +1,36 @@
package gallery
import (
+ "errors"
+ "flag"
finstr "git.gutmet.org/finstr.git/initer"
"git.gutmet.org/goutil.git"
)
-func New(name string) error {
- fl := finstr.IniterFlags{}
- fl.Dir = "photos" + name
+func New(fl finstr.IniterFlags) error {
+ fl.Dir = "photos" + fl.Dir
fl.Markdown = true
return finstr.Init(fl)
}
-func NewInteractive() error {
- name, err := goutil.AskFor("Name (one word)")
- if err != nil {
- return err
+type galleryFlags struct {
+ artsy bool
+ name string
+}
+
+func NewCommand() (goutil.CommandFlagsInit, goutil.CommandFunc) {
+ f := galleryFlags{}
+ flagsInit := func(s *flag.FlagSet) {
+ s.StringVar(&f.name, "name", "", "name to use for gallery and folder (mandatory)")
+ s.BoolVar(&f.artsy, "artsy", false, "mark gallery to generate thumbnails with original ratio instead of square")
+ }
+ return flagsInit, func([]string) error {
+ if f.name == "" {
+ return errors.New("need gallery name as argument")
+ }
+ fl := finstr.IniterFlags{}
+ fl.Dir = f.name
+ fl.Artsy = f.artsy
+ return New(fl)
}
- return New(name)
}
diff --git a/initer/initer.go b/initer/initer.go
index 1ec638f..d6f39e1 100644
--- a/initer/initer.go
+++ b/initer/initer.go
@@ -4,6 +4,7 @@ import (
"errors"
"flag"
"fmt"
+ finstr "git.gutmet.org/finstr.git/initer"
"git.gutmet.org/goutil.git"
"git.gutmet.org/wombat.git/gallery"
"os"
@@ -48,7 +49,7 @@ func dumpInitFiles(style Style) error {
if err != nil {
return err
}
- return gallery.New("")
+ return gallery.New(finstr.IniterFlags{})
}
func isInitialized() bool {
diff --git a/wombat.go b/wombat.go
index dab4b36..11d0f8c 100644
--- a/wombat.go
+++ b/wombat.go
@@ -23,7 +23,7 @@ func main() {
goutil.NewCommandWithFlags("post", post.Command, "create a new blogpost"),
goutil.NewCommand("serve", serve, "just execute web server"),
goutil.NewCommandWithFlags("genpics", gallery.Command, "generate galleries"),
- goutil.NewCommand("newgallery", func([]string) error { return gallery.NewInteractive() }, "init new gallery (interactive)"),
+ goutil.NewCommandWithFlags("newgallery", gallery.NewCommand, "init new gallery"),
}
err := goutil.Execute(commands)
if err != nil {