cmd-zet/cmd/edit.go

43 lines
606 B
Go
Raw Normal View History

package cmd
import (
"fmt"
"os"
"strconv"
"github.com/spf13/cobra"
"code.oliverdavies.uk/opdavies/cmd-zet/internal/lib"
)
var editCmd = &cobra.Command{
Use: "edit",
Aliases: []string{"e"},
Short: "Edit a specific zettel",
Long: `zet edit|e ID
zet edit|e latest
`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
fmt.Println("Error: No id provided")
os.Exit(1)
}
var id int
if args[0] == "latest" {
id = lib.GetLatestZet()
} else {
i, err := strconv.Atoi(args[0])
if err != nil {
os.Exit(1)
}
id = i
}
lib.EditZet(id)
},
}