Skip to content

Commit 6dea476

Browse files
authored
Scaffold in current directory if name flag empty, p.s #11 (#14)
1 parent 4398faa commit 6dea476

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

helper/getYamlPath.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func GetYamlPath(configPath string, yaml string) string {
1010
var defaultPath string = filepath.Join(AppsDataPath(), "scaffolder", yaml+".yaml")
1111
var savedPath string = GetConfigDir()
1212
var customPath string = fmt.Sprintf("%s/%s.yaml", configPath, yaml)
13-
var routePath string = fmt.Sprintf("./%s", yaml)
13+
var routePath string = fmt.Sprintf("./%s.yaml", yaml)
1414

1515
// 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
1616
if configPath == "" {

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func main() {
3232
flag.Parse()
3333

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

utils/scaffold.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77
"regexp"
8+
89
"github.com/dl-tg/scaffolder/helper"
910

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

74-
// Create project folder
75-
err = os.Mkdir(name, 0755)
76-
helper.Fatal(fmt.Sprintf("Error creating project folder: %s", err), true, err)
77-
78-
// Navigate to the project folder
79-
err = os.Chdir(name)
80-
helper.Fatal(fmt.Sprintf("Failed to navigate to project folder: %s", err), true, err)
75+
// Create project folder if name was specified, else scaffold in current directoy
76+
if name != "" {
77+
err := os.Mkdir(name, 0755)
78+
helper.Fatal(fmt.Sprintf("Error creating project folder: %s", err), true, err)
79+
// Navigate to the project folder
80+
err = os.Chdir(name)
81+
helper.Fatal(fmt.Sprintf("Failed to navigate to project folder: %s", err), true, err)
82+
}
8183

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

0 commit comments

Comments
 (0)