diff --git a/cmd/world/root/create.go b/cmd/world/root/create.go index 0e01512..17529fc 100644 --- a/cmd/world/root/create.go +++ b/cmd/world/root/create.go @@ -2,10 +2,12 @@ package root import ( "io" + "os/exec" "strings" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" + "github.com/rotisserie/eris" "github.com/spf13/cobra" "pkg.world.dev/world-cli/common/teacmd" @@ -204,6 +206,11 @@ Otherwise, it will prompt you to enter a directory name.`, GroupID: "starter", Args: cobra.MaximumNArgs(1), RunE: func(_ *cobra.Command, args []string) error { + err := checkGitConfig() + if err != nil { + return err + } + p := tea.NewProgram(NewWorldCreateModel(args), tea.WithOutput(writer)) if _, err := p.Run(); err != nil { return err @@ -214,3 +221,21 @@ Otherwise, it will prompt you to enter a directory name.`, return createCmd } + +func checkGitConfig() error { + // Check Git user name + cmdUserName := exec.Command("git", "config", "--get", "user.name") + userName, err := cmdUserName.Output() + if err != nil || userName == nil { + return eris.New("retrieving Git user name, please set it using `git config --global user.name 'Your Name'`") + } + + // Check Git user email + cmdUserEmail := exec.Command("git", "config", "--get", "user.email") + userEmail, err := cmdUserEmail.Output() + if err != nil || userEmail == nil { + return eris.New("retrieving Git user email, please set it using `git config --global user.email 'Your Email'`") + } + + return nil +}