t

commit ae418aa2387201cd2b4e85c3562800d4fb9eea0b

Author: Pedro Lucas Porcellis <pedrolucasporcellis@gmail.com>

Create a new Note

 commands/create.go | 26 ++++++++++++++++++++++++++


diff --git a/commands/create.go b/commands/create.go
new file mode 100644
index 0000000000000000000000000000000000000000..1da0dedf1cdceb1219eefc6a125303eac9bbe4a8
--- /dev/null
+++ b/commands/create.go
@@ -0,0 +1,26 @@
+package commands
+
+import (
+	"fmt"
+	"git.sr.ht/~porcellis/t/config"
+	"git.sr.ht/~porcellis/t/models"
+	"os"
+	"path"
+	"time"
+)
+
+func Create(config config.TConfig) (models.Note, error) {
+	var (
+		err  error
+		note models.Note
+	)
+
+	currentTime := time.Now()
+	noteName := currentTime.Format("2006-01-02T15:04:05Z07:00")
+	file, err := os.Create(path.Join(config.BasePath, fmt.Sprintf("%s.md", noteName)))
+
+	stat, _ := file.Stat()
+	note = models.Note{Name: stat.Name(), Path: path.Join(config.BasePath, stat.Name()), ModTime: stat.ModTime()}
+
+	return note, err
+}