first working verion
This commit is contained in:
5
.gitignore
vendored
5
.gitignore
vendored
@@ -3,6 +3,11 @@ scaffold
|
|||||||
.env.toml
|
.env.toml
|
||||||
env.toml
|
env.toml
|
||||||
|
|
||||||
|
cfg/.env
|
||||||
|
cfg/.env*
|
||||||
|
cfg/*.env
|
||||||
|
cfg/*.toml
|
||||||
|
|
||||||
build/
|
build/
|
||||||
buildTime.txt
|
buildTime.txt
|
||||||
buildVersion.txt
|
buildVersion.txt
|
||||||
|
|||||||
2
Makefile
2
Makefile
@@ -71,7 +71,7 @@ install: prep
|
|||||||
> @go install . && echo "Build and Install success" || echo "[FAILED] go install"
|
> @go install . && echo "Build and Install success" || echo "[FAILED] go install"
|
||||||
|
|
||||||
install-production: prep
|
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
|
## Commands that don't relate to a specific file
|
||||||
.PHONY: help confirm clean prep build build-production
|
.PHONY: help confirm clean prep build build-production
|
||||||
49
main.go
49
main.go
@@ -21,53 +21,38 @@ var buildTime string
|
|||||||
//go:embed buildVersion.txt
|
//go:embed buildVersion.txt
|
||||||
var buildVersion string
|
var buildVersion string
|
||||||
|
|
||||||
type Setup struct {
|
type (
|
||||||
|
Setup struct {
|
||||||
Projects_basedir string
|
Projects_basedir string
|
||||||
Module_basepath string
|
Module_basepath string
|
||||||
//Sub_Dirs []string
|
|
||||||
//Def_project_name string
|
|
||||||
Project_dir_permissions string
|
Project_dir_permissions string
|
||||||
//File_permissions string
|
|
||||||
//Copy_Examples bool
|
|
||||||
//Copy_Command string
|
|
||||||
Setup_git bool
|
Setup_git bool
|
||||||
Create_Remote_Repo bool
|
Create_Remote_Repo bool
|
||||||
Remote_User string
|
Remote_User string
|
||||||
Remote_Location string
|
Remote_Location string
|
||||||
Remote_Shortname string
|
Remote_Shortname string
|
||||||
//Create_gitignore bool
|
}
|
||||||
//Git_ignore_content string
|
ScaffoldSetup struct {
|
||||||
//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
|
TestKey string
|
||||||
}
|
}
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
infoFlag = flag.Bool("Info", false, "Displays the program build information and exits.")
|
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 = "/"
|
sep = "/"
|
||||||
cfg_dir = ".config/devel/scaffold"
|
cfg_dir = ".config/devel/scaffold"
|
||||||
cfg_filename = "scaffold-cfg.toml"
|
cfg_filename = "scaffold-cfg.toml"
|
||||||
setup Setup
|
setup ScaffoldSetup
|
||||||
npsetup Setup
|
npsetup Setup
|
||||||
//projCfg Setup
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *infoFlag {
|
if *infoFlag || *infoFlag2 {
|
||||||
fmt.Printf("Newgo version: %s", buildVersion)
|
fmt.Printf("Scaffold version: %s", buildVersion)
|
||||||
fmt.Printf("Built: %s\n", buildTime)
|
fmt.Printf("Built: %s\n", buildTime)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
@@ -94,11 +79,8 @@ func main() {
|
|||||||
_, err = toml.DecodeFile(cfg_file, &setup)
|
_, err = toml.DecodeFile(cfg_file, &setup)
|
||||||
ifFerr("[Failed] to parse config file", err)
|
ifFerr("[Failed] to parse config file", err)
|
||||||
|
|
||||||
fmt.Printf("Read config TestKey: %s\n", setup.TestKey)
|
|
||||||
|
|
||||||
pts, err := availableProjectTypes(scaffold_cfg_dir)
|
pts, err := availableProjectTypes(scaffold_cfg_dir)
|
||||||
ifFerr("Unable to read scaffold config directory contents", err)
|
ifFerr("Unable to read scaffold config directory contents", err)
|
||||||
//fmt.Printf("Project Types: %+v\n", pts)
|
|
||||||
|
|
||||||
// Handle request
|
// Handle request
|
||||||
pc := len(os.Args)
|
pc := len(os.Args)
|
||||||
@@ -124,8 +106,6 @@ func main() {
|
|||||||
_, err = toml.DecodeFile(projectCfgFile, &npsetup)
|
_, err = toml.DecodeFile(projectCfgFile, &npsetup)
|
||||||
ifFerr("Unable to read configuration for requested project type", err)
|
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
|
//Setup and Ready to begin
|
||||||
|
|
||||||
// Permissions are octal (ugo - user, group, other)
|
// Permissions are octal (ugo - user, group, other)
|
||||||
@@ -149,7 +129,6 @@ func main() {
|
|||||||
|
|
||||||
// copy contents from projectType/sample
|
// copy contents from projectType/sample
|
||||||
|
|
||||||
//fmt.Println("Sample")
|
|
||||||
err = filepath.Walk(projectTypeDir+sep+"sample", func(path string, info os.FileInfo, err error) error {
|
err = filepath.Walk(projectTypeDir+sep+"sample", func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -172,7 +151,6 @@ func main() {
|
|||||||
_, err = io.Copy(dest, src)
|
_, err = io.Copy(dest, src)
|
||||||
ifFerr("Unable to copy file: "+info.Name(), err)
|
ifFerr("Unable to copy file: "+info.Name(), err)
|
||||||
}
|
}
|
||||||
//fmt.Printf("dir: %v,path: %s, name: %s\n", info.IsDir(), path, info.Name())
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -187,6 +165,11 @@ func main() {
|
|||||||
_, err = exec.Command("go", "mod", "init", modpath).Output()
|
_, err = exec.Command("go", "mod", "init", modpath).Output()
|
||||||
ifFerr("go mod init failed", err)
|
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
|
// setup git
|
||||||
if npsetup.Setup_git {
|
if npsetup.Setup_git {
|
||||||
// init repo
|
// init repo
|
||||||
@@ -216,6 +199,8 @@ func main() {
|
|||||||
fmt.Println("Added remote repo to git as origin")
|
fmt.Println("Added remote repo to git as origin")
|
||||||
|
|
||||||
// push initial commit
|
// push initial commit
|
||||||
|
// be sure you have set
|
||||||
|
// git config --global init.defaultBranch main
|
||||||
_, err = exec.Command("git", "push", "origin", "main").Output()
|
_, err = exec.Command("git", "push", "origin", "main").Output()
|
||||||
ifFerr("Unable to push initial commit to origin", err)
|
ifFerr("Unable to push initial commit to origin", err)
|
||||||
fmt.Println("Pushed initial commit to remote")
|
fmt.Println("Pushed initial commit to remote")
|
||||||
|
|||||||
Reference in New Issue
Block a user