Skip to content

Commit

Permalink
feat: create includes empty go file
Browse files Browse the repository at this point in the history
  • Loading branch information
YashishDua committed May 17, 2019
1 parent 8a1da1a commit 883f944
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"bufio"
"fmt"
"io/ioutil"
"os/exec"
"strconv"

Expand All @@ -23,6 +24,14 @@ func SetupProject() {
}
}

if goFileExist, _ := internal.CheckFileExist("main.go"); !goFileExist {
internal.PrintStep("Adding empty main.go")
if err := addEmptyGoFile(); err != nil {
internal.PrintError(err)
return
}
}

internal.PrintStep("Create successful")
}

Expand Down Expand Up @@ -69,3 +78,13 @@ func getScripts(dir string) []string {
keepScript := fmt.Sprintf(`cd %s && touch .keep`, dir)
return []string{script, countScript, keepScript}
}

func addEmptyGoFile() error {
data := []byte("package main\n\nfunc main() {}")

if err := ioutil.WriteFile("main.go", data, 0777); err != nil {
return err
}

return nil
}

0 comments on commit 883f944

Please sign in to comment.