|
|
@ -24,6 +24,17 @@ type CreateOpts struct {
|
|
|
|
Content opt.String
|
|
|
|
Content opt.String
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ErrNoteExists is an error returned when a note already exists with the
|
|
|
|
|
|
|
|
// filename generated by Create().
|
|
|
|
|
|
|
|
type ErrNoteExists struct {
|
|
|
|
|
|
|
|
Name string
|
|
|
|
|
|
|
|
Path string
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (e ErrNoteExists) Error() string {
|
|
|
|
|
|
|
|
return fmt.Sprintf("%s: note already exists", e.Path)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Create generates a new note from the given options.
|
|
|
|
// Create generates a new note from the given options.
|
|
|
|
// Returns the path of the newly created note.
|
|
|
|
// Returns the path of the newly created note.
|
|
|
|
func Create(
|
|
|
|
func Create(
|
|
|
@ -125,11 +136,13 @@ func genPath(
|
|
|
|
dir zk.Dir,
|
|
|
|
dir zk.Dir,
|
|
|
|
deps createDeps,
|
|
|
|
deps createDeps,
|
|
|
|
) (string, renderContext, error) {
|
|
|
|
) (string, renderContext, error) {
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
var filename string
|
|
|
|
var path string
|
|
|
|
var path string
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
for i := 0; i < 50; i++ {
|
|
|
|
context.ID = deps.genId()
|
|
|
|
context.ID = deps.genId()
|
|
|
|
|
|
|
|
|
|
|
|
filename, err := deps.filenameTemplate.Render(context)
|
|
|
|
filename, err = deps.filenameTemplate.Render(context)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return "", context, err
|
|
|
|
return "", context, err
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -146,5 +159,8 @@ func genPath(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return "", context, fmt.Errorf("%v: note already exists", path)
|
|
|
|
return "", context, ErrNoteExists{
|
|
|
|
|
|
|
|
Name: filepath.Join(dir.Name, filename),
|
|
|
|
|
|
|
|
Path: path,
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|