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"
|
|
|
|
)
|
|
|
|
|
2021-02-15 21:44:31 +00:00
|
|
|
// Init creates a notebook in the given directory
|
2020-12-24 15:02:19 +00:00
|
|
|
type Init struct {
|
2021-02-15 21:44:31 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-02-15 21:44:31 +00:00
|
|
|
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
|
|
|
}
|