Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check dir is exists before create/clone on world cardinal create command #83

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion cmd/world/root/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,17 @@ func TestCreateStartStopRestartPurge(t *testing.T) {
// set tea ouput to variable
teaOut := &bytes.Buffer{}
createCmd := getCreateCmd(teaOut)
createCmd.SetArgs([]string{gameDir})

// checkout the repo
sgtDir := gameDir + "/sgt"
createCmd.SetArgs([]string{sgtDir})
zulkhair marked this conversation as resolved.
Show resolved Hide resolved
err = createCmd.Execute()
assert.NilError(t, err)

// Change dir
err = os.Chdir(sgtDir)
assert.NilError(t, err)

zulkhair marked this conversation as resolved.
Show resolved Hide resolved
// Start cardinal
rootCmd.SetArgs([]string{"cardinal", "start", "--detach", "--editor=false"})
err = rootCmd.Execute()
Expand Down Expand Up @@ -173,6 +179,9 @@ func TestDev(t *testing.T) {
createCmd := getCreateCmd(teaOut)
createCmd.SetArgs([]string{gameDir})

// checkout the repo
sgtDir := gameDir + "/sgt"
createCmd.SetArgs([]string{sgtDir})
zulkhair marked this conversation as resolved.
Show resolved Hide resolved
err = createCmd.Execute()
assert.NilError(t, err)

Expand Down Expand Up @@ -280,6 +289,9 @@ func TestEVMStart(t *testing.T) {
createCmd := getCreateCmd(teaOut)
createCmd.SetArgs([]string{gameDir})

// checkout the repo
sgtDir := gameDir + "/sgt"
createCmd.SetArgs([]string{sgtDir})
err = createCmd.Execute()
assert.NilError(t, err)

Expand Down
6 changes: 4 additions & 2 deletions common/docker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,19 @@ func TestBuild(t *testing.T) {
err = os.Chdir(dir)
assert.NilError(t, err)

sgtDir := dir + "/sgt"

zulkhair marked this conversation as resolved.
Show resolved Hide resolved
// Pull the repository
templateGitURL := "https://github.com/Argus-Labs/starter-game-template.git"
err = teacmd.GitCloneCmd(templateGitURL, dir, "Initial commit from World CLI")
err = teacmd.GitCloneCmd(templateGitURL, sgtDir, "Initial commit from World CLI")
assert.NilError(t, err)

// Preparation
cfg := &config.Config{
DockerEnv: map[string]string{
"CARDINAL_NAMESPACE": cardinalNamespace,
},
RootDir: dir,
RootDir: sgtDir,
}
cardinalService := service.Cardinal(cfg)
ctx := context.Background()
Expand Down
6 changes: 6 additions & 0 deletions common/teacmd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ func git(args ...string) (string, error) {
}

func GitCloneCmd(url string, targetDir string, initMsg string) error {
// check targetDir exists
if _, err := os.Stat(targetDir); err == nil {
return eris.Errorf("Game shard named '%s' already exists in this directory, "+
"please change the directory or use another name", targetDir)
}
zulkhair marked this conversation as resolved.
Show resolved Hide resolved

_, err := git("clone", url, targetDir)
if err != nil {
return err
Expand Down
Loading