zk/internal/cli/cmd/index.go
Mickaël Menu 50855154e2
Architecture (#27)
* Move everything under the internal package.
* Better separation between core and adapter packages, for easier unit testing.
* Simplify data models.
* Support multiple opened notebooks during runtime (useful for the LSP server).
* Proper surface API which might be exposed later as a public Go package.
2021-04-14 20:14:01 +02:00

36 lines
706 B
Go

package cmd
import (
"fmt"
"github.com/mickael-menu/zk/internal/cli"
)
// Index indexes the content of all the notes in the notebook.
type Index struct {
Force bool `short:"f" help:"Force indexing all the notes."`
Quiet bool `short:"q" help:"Do not print statistics nor progress."`
}
func (cmd *Index) Help() string {
return "You usually do not need to run `zk index` manually, as notes are indexed automatically when needed."
}
func (cmd *Index) Run(container *cli.Container) error {
notebook, err := container.CurrentNotebook()
if err != nil {
return err
}
stats, err := notebook.Index(cmd.Force)
if err != nil {
return err
}
if !cmd.Quiet {
fmt.Println(stats)
}
return nil
}