aboutsummaryrefslogtreecommitdiff
path: root/cmd/eno/cobra_new.go
diff options
context:
space:
mode:
authorishaan <contact@ishaan.cc>2026-07-13 11:09:34 +0530
committerishaan <contact@ishaan.cc>2026-07-13 11:09:34 +0530
commitd433b1af731ff901b9c14a647678471b27fdfe8a (patch)
treeb101b59e89d826386de8bbada4c405a3cfbf6b3f /cmd/eno/cobra_new.go
parent388971e7a86be97f6a7412cd1d526016bc4e14ce (diff)
better
Diffstat (limited to 'cmd/eno/cobra_new.go')
-rw-r--r--cmd/eno/cobra_new.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/cmd/eno/cobra_new.go b/cmd/eno/cobra_new.go
new file mode 100644
index 0000000..4a7caeb
--- /dev/null
+++ b/cmd/eno/cobra_new.go
@@ -0,0 +1,76 @@
+package main
+
+import (
+ "os"
+ "path/filepath"
+ "strings"
+
+ "github.com/spf13/cobra"
+ "gitlab.com/whiteboardguy/eno/internal/crud"
+ "gitlab.com/whiteboardguy/eno/internal/utils"
+)
+
+var newCmd = &cobra.Command{
+ Use: "new <note>",
+ Short: "create a new encrypted note",
+ Args: cobra.MinimumNArgs(1),
+ Run: func(cmd *cobra.Command, args []string) {
+
+ output, err := cmd.Flags().GetString("output")
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+
+ editFlag, err := cmd.Flags().GetBool("edit")
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+
+ sshFlag, err := cmd.Flags().GetBool("ssh")
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+
+
+
+ noteName := strings.Join(args, " ")
+ if output == "" {
+ if strings.ContainsRune(noteName, filepath.Separator) {
+ output = noteName + ".eno"
+ } else {
+ output = filepath.Join(Conf.DataDir, noteName+".eno")
+ }
+ }
+
+ if _, err := os.Stat(output); err == nil {
+ ok, err := utils.AskUserYesNo("file '"+output+"' already exists. Overwrite?", false)
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+ if !ok {
+ cmd.PrintErrln("Error: write aborted")
+ os.Exit(1)
+ }
+ }
+
+ if editFlag {
+ err = crud.NewNoteEdit(output, Conf.EditorString)
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+ }
+
+ _ = sshFlag
+
+ err = crud.NewNote(output)
+ if err != nil {
+ cmd.PrintErrln("Error:", err)
+ os.Exit(1)
+ }
+ },
+}