TheMathemagicians/sevenkeys/cmd/printinglist/main.go

42 lines
649 B
Go

package main
import (
"fmt"
"io"
"log"
"os"
"os/exec"
"sevenkeys/database"
"sevenkeys/database/operations"
)
func check(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
db := database.GetDatabaseFromConfig("config.json")
cardSearchOptions, err := operations.GetCardSearchOptions(db)
check(err)
cmd := exec.Command("fzf")
cmd.Stderr = os.Stderr
fzfStdin, err := cmd.StdinPipe()
check(err)
go func() {
defer fzfStdin.Close()
for _, option := range cardSearchOptions {
io.WriteString(fzfStdin, option+"\n")
}
}()
fzfOutput, err := cmd.Output()
check(err)
fmt.Println("Output:", string(fzfOutput))
}