func readTmpFile(filename string) (*pb.Card, error) {
	var c pb.Card
	f, err := os.Open(filename)
	if err != nil {
		return nil, errors.Wrap(err, "reading file")
	}
	defer f.Close()
	if err := json.NewDecoder(f).Decode(&c); err != nil {
		return nil, errors.Wrap(err, "decoding file")
	}
	return &c, nil
}
readTmpFile reads the modified file and formats the card.
package edit
import (
	"bufio"
	"encoding/json"
	"fmt"
	"io"
	"os"
	"os/exec"
	"strings"
	"github.com/GGP1/kure/auth"
	cmdutil "github.com/GGP1/kure/commands"
	"github.com/GGP1/kure/db/card"
	"github.com/GGP1/kure/pb"
	"github.com/GGP1/kure/sig"
	"github.com/pkg/errors"
	"github.com/spf13/cobra"
	bolt "go.etcd.io/bbolt"
)
var example = `
* Edit using the standard input
kure card edit Sample
* Edit using the text editor
kure card edit Sample -i`
type editOptions struct {
	interactive bool
}
func NewCmd(db *bolt.DB) *cobra.Command {
	opts := editOptions{}
	cmd := &cobra.Command{
		Use:   "edit <name>",
		Short: "Edit a card",
		Long: `Edit a card.
If the name is edited, Kure will remove the old card and create one with the new name.`,
		Example: example,
		Args:    cmdutil.MustExist(db, cmdutil.Card),
		PreRunE: auth.Login(db),
		RunE:    runEdit(db, &opts),
		PostRun: func(cmd *cobra.Command, args []string) {
			opts = editOptions{}
		},
	}
	cmd.Flags().BoolVarP(&opts.interactive, "it", "i", false, "use the text editor")
	return cmd
}
func runEdit(db *bolt.DB, opts *editOptions) cmdutil.RunEFunc {
	return func(cmd *cobra.Command, args []string) error {
		name := strings.Join(args, " ")
		name = cmdutil.NormalizeName(name)
		oldCard, err := card.Get(db, name)
		if err != nil {
			return err
		}
		if opts.interactive {
			return useTextEditor(db, oldCard)
		}
		return useStdin(db, os.Stdin, oldCard)
	}
}
func createTempFile(c *pb.Card) (string, error) {
	f, err := os.CreateTemp("", "*.json")
	if err != nil {
		return "", errors.Wrap(err, "creating temporary file")
	}
	content, err := json.MarshalIndent(c, "", "  ")
	if err != nil {
		return "", errors.Wrap(err, "encoding card")
	}
	if _, err := f.Write(content); err != nil {
		return "", errors.Wrap(err, "writing temporary file")
	}
	if err := f.Close(); err != nil {
		return "", errors.Wrap(err, "closing temporary file")
	}
	return f.Name(), nil
}