changed .gitignore file handling/creation
This commit is contained in:
47
main.go
47
main.go
@@ -160,15 +160,19 @@ func main() {
|
||||
|
||||
// run init commands
|
||||
|
||||
// make mod file
|
||||
modpath := npsetup.Module_basepath + sep + newProjectName
|
||||
_, err = exec.Command("go", "mod", "init", modpath).Output()
|
||||
ifFerr("go mod init failed", err)
|
||||
switch projType {
|
||||
case "go":
|
||||
// make mod file
|
||||
modpath := npsetup.Module_basepath + sep + newProjectName
|
||||
_, err = exec.Command("go", "mod", "init", modpath).Output()
|
||||
ifFerr("go mod init failed", err)
|
||||
|
||||
// do a mod tidy to update the mod file
|
||||
_, err = exec.Command("go", "mod", "tidy").Output()
|
||||
ifFerr("Unable to update the mod file with a tidy", err)
|
||||
fmt.Println("Updated go.mod")
|
||||
// do a mod tidy to update the mod file
|
||||
_, err = exec.Command("go", "mod", "tidy").Output()
|
||||
ifFerr("Unable to update the mod file with a tidy", err)
|
||||
fmt.Println("Updated go.mod")
|
||||
case "py":
|
||||
}
|
||||
|
||||
// setup git
|
||||
if npsetup.Setup_git {
|
||||
@@ -179,10 +183,29 @@ func main() {
|
||||
nifd, err := os.Create(".gitignore")
|
||||
ifFerr("Unable to create .gitignore file", err)
|
||||
defer nifd.Close()
|
||||
gi_content := fmt.Sprintf(gi_template, newProjectName)
|
||||
_, err = nifd.WriteString(gi_content)
|
||||
ifFerr("Unable to write .gitignore content", err)
|
||||
fmt.Println("Wrote .gitignore content")
|
||||
|
||||
var gi_content string
|
||||
var gi_in []byte = []byte("bin/")
|
||||
|
||||
gisrc, err := os.Open("GITIGNORE")
|
||||
if err == nil { // assume error means there is no source file
|
||||
gi_in, err = io.ReadAll(gisrc)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to read GITIGNORE, using default content")
|
||||
}
|
||||
gi_content = fmt.Sprintf("%s\n\n%s", newProjectName, string(gi_in))
|
||||
|
||||
_, err = nifd.WriteString(gi_content)
|
||||
ifFerr("Unable to write .gitignore content", err)
|
||||
fmt.Println("Wrote .gitignore content")
|
||||
|
||||
// remove GITIGNORE
|
||||
err = os.Remove("GITIGNORE")
|
||||
if err != nil {
|
||||
fmt.Println("Unable to remove GITIGNORE file")
|
||||
}
|
||||
}
|
||||
defer gisrc.Close()
|
||||
|
||||
// stage files
|
||||
_, err = exec.Command("git", "add", ".").Output()
|
||||
|
||||
Reference in New Issue
Block a user