zk/cmd/init.go

27 lines
500 B
Go
Raw Normal View History

2020-12-24 15:02:19 +00:00
package cmd
2020-12-28 12:16:11 +00:00
import (
"fmt"
"path/filepath"
2020-12-24 15:02:19 +00:00
2020-12-28 12:16:11 +00:00
"github.com/mickael-menu/zk/core/zk"
)
// Init creates a notebook in the given directory
2020-12-24 15:02:19 +00:00
type Init struct {
Directory string `arg optional type:"path" default:"." help:"Directory containing the notebook."`
2020-12-24 15:02:19 +00:00
}
func (cmd *Init) Run() error {
2020-12-28 12:16:11 +00:00
err := zk.Create(cmd.Directory)
if err == nil {
path, err := filepath.Abs(cmd.Directory)
if err != nil {
path = cmd.Directory
}
fmt.Printf("Initialized a notebook in %v\n", path)
2020-12-28 12:16:11 +00:00
}
return err
2020-12-24 15:02:19 +00:00
}