Skip to content

Commit

Permalink
feat: add play command
Browse files Browse the repository at this point in the history
  • Loading branch information
kbrgl committed Jul 24, 2022
1 parent f88dac5 commit ae9faa0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions cmd/play.go
@@ -0,0 +1,42 @@
package cmd

import (
"fmt"
"os"
"os/exec"

"github.com/spf13/cobra"
)

var (
playCmd = &cobra.Command{
Use: "play [game]",
Short: "Play a game",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
games, err := FetchGames()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = Play(FindGame(args[0], games))
if err != nil {
fmt.Println(err)
os.Exit(1)
}
},
}
)

func init() {
rootCmd.AddCommand(playCmd)
}

func Play(g *Game) error {
bin := binariesDir(g.Name)
cmd := exec.Command(bin)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}

0 comments on commit ae9faa0

Please sign in to comment.