mirror of
https://github.com/dnote/dnote
synced 2026-03-15 15:05:51 +01:00
* Updated the code to suit maintainer's proposal * Bug fixes and minor changes * Minor changes * Add files via upload * Add files via upload * Updated README.md * Implement a simpler delete interface
54 lines
953 B
Go
54 lines
953 B
Go
package edit
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
|
|
"github.com/dnote-io/cli/utils"
|
|
)
|
|
|
|
func Edit() error {
|
|
dnote, err := utils.GetDnote()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var target_book string
|
|
var index int
|
|
var content string
|
|
|
|
if len(os.Args) == 4 {
|
|
target_book, err = utils.GetCurrentBook()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
index, err = strconv.Atoi(os.Args[2])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
content = os.Args[3]
|
|
}else if len(os.Args) == 5 {
|
|
target_book = os.Args[2]
|
|
index, err = strconv.Atoi(os.Args[3])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
content = os.Args[4]
|
|
}
|
|
|
|
for i, note := range dnote[target_book] {
|
|
if i == index {
|
|
note.Content = content
|
|
dnote[target_book][i] = note
|
|
|
|
err := utils.WriteDnote(dnote)
|
|
fmt.Printf("[+] Edited Note : %d \n", index)
|
|
return err
|
|
}
|
|
}
|
|
|
|
// If loop finishes without returning, note did not exist
|
|
fmt.Println("Error : The note with that index is not found.")
|
|
return nil
|
|
}
|