From 2c9adcc4037d045542d5b159b2ba796a81581cbb Mon Sep 17 00:00:00 2001 From: gutmet Date: Wed, 8 Jan 2020 21:26:47 +0100 Subject: [PATCH] change newgallery command to be non-interactive --- gallery/new.go | 33 ++++++++++++++++++++++++--------- initer/initer.go | 3 ++- wombat.go | 2 +- 3 files changed, 27 insertions(+), 11 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 - } - return New(name) +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) + } } 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 {