Skip to content

Commit

Permalink
check git configuration before exec world create
Browse files Browse the repository at this point in the history
  • Loading branch information
zulkhair committed Aug 27, 2024
1 parent ef6982b commit d518417
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cmd/world/root/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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

Check warning on line 211 in cmd/world/root/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/root/create.go#L211

Added line #L211 was not covered by tests
}

p := tea.NewProgram(NewWorldCreateModel(args), tea.WithOutput(writer))
if _, err := p.Run(); err != nil {
return err
Expand All @@ -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 warning on line 230 in cmd/world/root/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/root/create.go#L230

Added line #L230 was not covered by tests
}

// 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'`")

Check warning on line 237 in cmd/world/root/create.go

View check run for this annotation

Codecov / codecov/patch

cmd/world/root/create.go#L237

Added line #L237 was not covered by tests
}

return nil
}

0 comments on commit d518417

Please sign in to comment.