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
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)
}

View File

@ -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 {

View File

@ -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 {