Skip to content

Commit

Permalink
Scaffold in current directory if name flag empty, p.s #11 (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
dl-tg authored Aug 5, 2023
1 parent 4398faa commit 6dea476
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion helper/getYamlPath.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func GetYamlPath(configPath string, yaml string) string {
var defaultPath string = filepath.Join(AppsDataPath(), "scaffolder", yaml+".yaml")
var savedPath string = GetConfigDir()
var customPath string = fmt.Sprintf("%s/%s.yaml", configPath, yaml)
var routePath string = fmt.Sprintf("./%s", yaml)
var routePath string = fmt.Sprintf("./%s.yaml", yaml)

// Set the path to the YAML file based on whether the user specified a custom config path or not. If not, a saved or a default file will be used
if configPath == "" {
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func main() {
flag.Parse()

// If the project name or path to the YAML file was not provided, print usage and exit with code 1
if name == "" || yaml == "" {
if yaml == "" {
flag.Usage()
}

Expand Down
16 changes: 9 additions & 7 deletions utils/scaffold.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"regexp"

"github.com/dl-tg/scaffolder/helper"

"gopkg.in/yaml.v3"
Expand Down Expand Up @@ -71,13 +72,14 @@ func Scaffold(name string, yamlpath string, setVariables map[string]string) {
err = yaml.Unmarshal(yamlData, &dirs)
helper.Fatal(fmt.Sprintf("Error unmarshalling YAML: %s", err), true, err)

// Create project folder
err = os.Mkdir(name, 0755)
helper.Fatal(fmt.Sprintf("Error creating project folder: %s", err), true, err)

// Navigate to the project folder
err = os.Chdir(name)
helper.Fatal(fmt.Sprintf("Failed to navigate to project folder: %s", err), true, err)
// Create project folder if name was specified, else scaffold in current directoy
if name != "" {
err := os.Mkdir(name, 0755)
helper.Fatal(fmt.Sprintf("Error creating project folder: %s", err), true, err)
// Navigate to the project folder
err = os.Chdir(name)
helper.Fatal(fmt.Sprintf("Failed to navigate to project folder: %s", err), true, err)
}

// Scaffold the directory structure :: iterating over the map
for folder, files := range dirs {
Expand Down

0 comments on commit 6dea476

Please sign in to comment.