From 1c8611173718672a505c88a8279f42ff86cbaa97 Mon Sep 17 00:00:00 2001 From: Kevin Offet Date: Sun, 9 Apr 2023 16:00:07 -0400 Subject: [PATCH] first working verion --- .gitignore | 5 ++++ Makefile | 2 +- main.go | 67 +++++++++++++++++++++--------------------------------- 3 files changed, 32 insertions(+), 42 deletions(-) diff --git a/.gitignore b/.gitignore index bd99f4b..794cd4b 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,11 @@ scaffold .env.toml env.toml +cfg/.env +cfg/.env* +cfg/*.env +cfg/*.toml + build/ buildTime.txt buildVersion.txt diff --git a/Makefile b/Makefile index 4e97b9a..52ca03f 100644 --- a/Makefile +++ b/Makefile @@ -71,7 +71,7 @@ install: prep > @go install . && echo "Build and Install success" || echo "[FAILED] go install" install-production: prep -> @go install -ldflags=${linkerflags} . && echo "production build and install success" || echo "[FAILED] production install" +> @go install -ldflags=${linkerflags} . && echo "Production build and install success" || echo "[FAILED] Production install" ## Commands that don't relate to a specific file .PHONY: help confirm clean prep build build-production \ No newline at end of file diff --git a/main.go b/main.go index f1f5f60..4d02024 100644 --- a/main.go +++ b/main.go @@ -21,53 +21,38 @@ var buildTime string //go:embed buildVersion.txt var buildVersion string -type Setup struct { - Projects_basedir string - Module_basepath string - //Sub_Dirs []string - //Def_project_name string - Project_dir_permissions string - //File_permissions string - //Copy_Examples bool - //Copy_Command string - Setup_git bool - Create_Remote_Repo bool - Remote_User string - Remote_Location string - Remote_Shortname string - //Create_gitignore bool - //Git_ignore_content string - //Include_license bool - //License_name string - //Use_license_file bool - //License_filename string - //License_text string - //Use_external_license bool - //External_license_location string - //Use_remote_license bool - //Remote_license_location string - //Main_content string - //Create_readme bool - //Readme_text string - TestKey string -} +type ( + Setup struct { + Projects_basedir string + Module_basepath string + Project_dir_permissions string + Setup_git bool + Create_Remote_Repo bool + Remote_User string + Remote_Location string + Remote_Shortname string + } + ScaffoldSetup struct { + TestKey string + } +) var ( infoFlag = flag.Bool("Info", false, "Displays the program build information and exits.") + infoFlag2 = flag.Bool("i", false, "Displays the program build information and exits.") sep = "/" cfg_dir = ".config/devel/scaffold" cfg_filename = "scaffold-cfg.toml" - setup Setup + setup ScaffoldSetup npsetup Setup - //projCfg Setup ) func main() { flag.Parse() - if *infoFlag { - fmt.Printf("Newgo version: %s", buildVersion) + if *infoFlag || *infoFlag2 { + fmt.Printf("Scaffold version: %s", buildVersion) fmt.Printf("Built: %s\n", buildTime) os.Exit(0) } @@ -94,11 +79,8 @@ func main() { _, err = toml.DecodeFile(cfg_file, &setup) ifFerr("[Failed] to parse config file", err) - fmt.Printf("Read config TestKey: %s\n", setup.TestKey) - pts, err := availableProjectTypes(scaffold_cfg_dir) ifFerr("Unable to read scaffold config directory contents", err) - //fmt.Printf("Project Types: %+v\n", pts) // Handle request pc := len(os.Args) @@ -124,8 +106,6 @@ func main() { _, err = toml.DecodeFile(projectCfgFile, &npsetup) ifFerr("Unable to read configuration for requested project type", err) - //fmt.Printf("Read %s project config: %+v\n", projType, npsetup) - //Setup and Ready to begin // Permissions are octal (ugo - user, group, other) @@ -149,7 +129,6 @@ func main() { // copy contents from projectType/sample - //fmt.Println("Sample") err = filepath.Walk(projectTypeDir+sep+"sample", func(path string, info os.FileInfo, err error) error { if err != nil { return err @@ -172,7 +151,6 @@ func main() { _, err = io.Copy(dest, src) ifFerr("Unable to copy file: "+info.Name(), err) } - //fmt.Printf("dir: %v,path: %s, name: %s\n", info.IsDir(), path, info.Name()) return nil }) if err != nil { @@ -187,6 +165,11 @@ func main() { _, 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") + // setup git if npsetup.Setup_git { // init repo @@ -216,6 +199,8 @@ func main() { fmt.Println("Added remote repo to git as origin") // push initial commit + // be sure you have set + // git config --global init.defaultBranch main _, err = exec.Command("git", "push", "origin", "main").Output() ifFerr("Unable to push initial commit to origin", err) fmt.Println("Pushed initial commit to remote")