You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zk/cmd/new.go

46 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"github.com/mickael-menu/zk/core/note"
"github.com/mickael-menu/zk/core/zk"
"github.com/mickael-menu/zk/util/opt"
)
// New adds a new note to the slip box.
type New struct {
Directory string `arg optional type:"path" default:"." help:"Directory in which to create the note"`
ShowPath bool `help:"Shows the path of the created note instead of editing it"`
Title string `short:"t" help:"Title of the new note" placeholder:"TITLE"`
Template string `type:"path" help:"Custom template to use to render the note" placeholder:"PATH"`
Extra map[string]string `help:"Extra variables passed to the templates"`
}
func (cmd *New) Run(container *Container) error {
zk, err := zk.Open(".")
if err != nil {
return err
}
dir, err := zk.DirAt(cmd.Directory)
if err != nil {
return err
}
opts := note.CreateOpts{
Dir: *dir,
Title: opt.NewNotEmptyString(cmd.Title),
Content: opt.NullString,
Template: opt.NewNotEmptyString(cmd.Template),
Extra: cmd.Extra,
}
file, err := note.Create(zk, opts, container.TemplateLoader())
if err != nil {
return err
}
fmt.Printf("%+v\n", file)
return nil
}