first working verion

This commit is contained in:
2023-04-09 16:00:07 -04:00
parent e7e1365938
commit cdba5552a4
3 changed files with 32 additions and 42 deletions

5
.gitignore vendored
View File

@@ -3,6 +3,11 @@ scaffold
.env.toml
env.toml
cfg/.env
cfg/.env*
cfg/*.env
cfg/*.toml
build/
buildTime.txt
buildVersion.txt

View File

@@ -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

67
main.go
View File

@@ -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")