aboutsummaryrefslogtreecommitdiff
path: root/cmd/eno
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
parent388971e7a86be97f6a7412cd1d526016bc4e14ce (diff)
better
Diffstat (limited to 'cmd/eno')
-rw-r--r--cmd/eno/cobra.go70
-rw-r--r--cmd/eno/cobra_new.go76
2 files changed, 82 insertions, 64 deletions
diff --git a/cmd/eno/cobra.go b/cmd/eno/cobra.go
index b988dab..9e4d4d2 100644
--- a/cmd/eno/cobra.go
+++ b/cmd/eno/cobra.go
@@ -45,7 +45,7 @@ var encryptCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to read input file: %v", err)
}
- utils.TryMlock(fileBytes)
+ crypt.TryMlock(fileBytes)
defer clear(fileBytes)
fmt.Printf("Enter a passphrase: ")
@@ -53,10 +53,10 @@ var encryptCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to read passphrase: %v", err)
}
- utils.TryMlock(password)
+ crypt.TryMlock(password)
defer clear(password)
- encrypted, err := crypt.EncryptRawBytes(fileBytes, password)
+ encrypted, err := crypt.EncryptRawBytes(fileBytes, password, crypt.Pass)
if err != nil {
cmd.PrintErrln("Error:", err)
os.Exit(1)
@@ -104,7 +104,7 @@ var decryptCmd = &cobra.Command{
if err != nil {
return fmt.Errorf("failed to read passphrase: %v", err)
}
- utils.TryMlock(password)
+ crypt.TryMlock(password)
defer clear(password)
plaintext, err := crypt.DecryptRawBytes(fileBytes, password)
@@ -112,7 +112,7 @@ var decryptCmd = &cobra.Command{
cmd.PrintErrln("Error:", err)
os.Exit(1)
}
- utils.TryMlock(plaintext)
+ crypt.TryMlock(plaintext)
defer clear(plaintext)
if err := os.WriteFile(output, plaintext, 0644); err != nil {
@@ -138,65 +138,6 @@ var initCmd = &cobra.Command{
},
}
-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)
- }
-
- 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)
- }
- }
-
- err = crud.NewNote(output)
- if err != nil {
- cmd.PrintErrln("Error:", err)
- os.Exit(1)
- }
-
- if editFlag {
- target := filepath.Clean(output)
- target = strings.TrimSuffix(target, ".eno")
- target += ".eno"
-
- err = crud.EditNote(target, Conf.EditorString)
- if err != nil {
- cmd.PrintErrln("Error:", err)
- os.Exit(1)
- }
- }
- },
-}
-
var editCmd = &cobra.Command{
Use: "edit <note>",
Short: "edit an existing encrypted note",
@@ -235,6 +176,7 @@ func init() {
newCmd.Flags().StringP("output", "o", "", "output file")
newCmd.Flags().BoolP("edit", "e", false, "edit after creation")
+ newCmd.Flags().BoolP("ssh", "ssh", false, "use your ssh for auth")
cobraCmd.AddCommand(encryptCmd, decryptCmd, initCmd, newCmd, editCmd)
}
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)
+ }
+ },
+}