+user init commands in scaffold-<ProjType>.toml
This commit is contained in:
44
main.go
44
main.go
@@ -31,6 +31,7 @@ type (
|
||||
Remote_User string
|
||||
Remote_Location string
|
||||
Remote_Shortname string
|
||||
Commands [][]string
|
||||
}
|
||||
ScaffoldSetup struct {
|
||||
TestKey string
|
||||
@@ -71,14 +72,21 @@ func main() {
|
||||
|
||||
if _, err := os.Stat(cfg_file); err != nil {
|
||||
fmt.Println("No scaffold program configuration file found - creating a default file")
|
||||
// ok now do it
|
||||
cfgfd, err := os.Create(cfg_file)
|
||||
ifFerr("Unable to create scaffold configuration file", err)
|
||||
defer cfgfd.Close()
|
||||
|
||||
_, err = cfgfd.WriteString(cfg_content)
|
||||
ifFerr("Unable to write scaffold configuration file content", err)
|
||||
fmt.Println("Wrote new scaffold configuration file")
|
||||
_, err = toml.Decode(cfg_content, &setup)
|
||||
ifFerr("[Failed] to parse config file", err)
|
||||
} else {
|
||||
fmt.Println("found config file")
|
||||
_, err = toml.DecodeFile(cfg_file, &setup)
|
||||
ifFerr("[Failed] to parse config file", err)
|
||||
}
|
||||
|
||||
_, err = toml.DecodeFile(cfg_file, &setup)
|
||||
ifFerr("[Failed] to parse config file", err)
|
||||
|
||||
pts, err := availableProjectTypes(scaffold_cfg_dir)
|
||||
ifFerr("Unable to read scaffold config directory contents", err)
|
||||
|
||||
@@ -106,6 +114,8 @@ func main() {
|
||||
_, err = toml.DecodeFile(projectCfgFile, &npsetup)
|
||||
ifFerr("Unable to read configuration for requested project type", err)
|
||||
|
||||
//fmt.Printf("Found commands: %+v\n", npsetup.Commands)
|
||||
|
||||
//Setup and Ready to begin
|
||||
|
||||
// Permissions are octal (ugo - user, group, other)
|
||||
@@ -158,20 +168,20 @@ func main() {
|
||||
}
|
||||
fmt.Println("Project sample skeleton copied")
|
||||
|
||||
// run init commands
|
||||
// run your init commands from the projectType/scaffold-<PROJECTTYPE>.toml file
|
||||
|
||||
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")
|
||||
case "py":
|
||||
for _, comm := range npsetup.Commands {
|
||||
args := comm[1:]
|
||||
if comm[0] == "go" && comm[1] == "mod" && comm[2] == "init" {
|
||||
args[2] = args[2] + sep + newProjectName
|
||||
//fmt.Printf("executing: %+v -- %+v\n", comm, args)
|
||||
}
|
||||
_, err = exec.Command(comm[0], args...).Output()
|
||||
if err != nil {
|
||||
commstring := fmt.Sprintf("Unable to execute command: %+v", comm)
|
||||
log.Fatalf("%s -- %s\n", commstring, err)
|
||||
}
|
||||
fmt.Printf("executing: %+v %+v\n", comm[0], args)
|
||||
}
|
||||
|
||||
// setup git
|
||||
|
||||
Reference in New Issue
Block a user