change newgallery command to be non-interactive
This commit is contained in:
parent
888fe75a34
commit
2c9adcc403
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue
Block a user