change newgallery command to be non-interactive

This commit is contained in:
gutmet 2020-01-08 21:26:47 +01:00
parent 888fe75a34
commit 2c9adcc403
3 changed files with 27 additions and 11 deletions

View File

@ -1,21 +1,36 @@
package gallery package gallery
import ( import (
"errors"
"flag"
finstr "git.gutmet.org/finstr.git/initer" finstr "git.gutmet.org/finstr.git/initer"
"git.gutmet.org/goutil.git" "git.gutmet.org/goutil.git"
) )
func New(name string) error { func New(fl finstr.IniterFlags) error {
fl := finstr.IniterFlags{} fl.Dir = "photos" + fl.Dir
fl.Dir = "photos" + name
fl.Markdown = true fl.Markdown = true
return finstr.Init(fl) return finstr.Init(fl)
} }
func NewInteractive() error { type galleryFlags struct {
name, err := goutil.AskFor("Name (one word)") artsy bool
if err != nil { name string
return err }
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)
} }

View File

@ -4,6 +4,7 @@ import (
"errors" "errors"
"flag" "flag"
"fmt" "fmt"
finstr "git.gutmet.org/finstr.git/initer"
"git.gutmet.org/goutil.git" "git.gutmet.org/goutil.git"
"git.gutmet.org/wombat.git/gallery" "git.gutmet.org/wombat.git/gallery"
"os" "os"
@ -48,7 +49,7 @@ func dumpInitFiles(style Style) error {
if err != nil { if err != nil {
return err return err
} }
return gallery.New("") return gallery.New(finstr.IniterFlags{})
} }
func isInitialized() bool { func isInitialized() bool {

View File

@ -23,7 +23,7 @@ func main() {
goutil.NewCommandWithFlags("post", post.Command, "create a new blogpost"), goutil.NewCommandWithFlags("post", post.Command, "create a new blogpost"),
goutil.NewCommand("serve", serve, "just execute web server"), goutil.NewCommand("serve", serve, "just execute web server"),
goutil.NewCommandWithFlags("genpics", gallery.Command, "generate galleries"), 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) err := goutil.Execute(commands)
if err != nil { if err != nil {