Skip to content

Commit 5f87969

Browse files
committed
moveonly: create standlone function for Create
Signed-off-by: William Casarin <jb55@jb55.com>
1 parent efec50f commit 5f87969

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

cmd/create.go

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,34 @@ func init() {
1313
rootCmd.AddCommand(createCmd)
1414
}
1515

16+
func Create(projectName string) {
17+
rootDir := fmt.Sprintf("./%v", projectName)
18+
19+
log.Printf("Creating project %s.", projectName)
20+
21+
err := os.Mkdir(rootDir, os.ModePerm)
22+
if os.IsExist(err) {
23+
log.Fatalf("Directory %v already exists! Error: %v", projectName, err)
24+
} else if err != nil {
25+
log.Fatalf("Error creating root: %v ", err)
26+
}
27+
28+
commit0ConfigPath := fmt.Sprintf("%v/commit0.yml", rootDir)
29+
30+
f, err := os.Create(commit0ConfigPath)
31+
if err != nil {
32+
log.Printf("Error creating commit0 config: %v", err)
33+
}
34+
Templator.Commit0.Execute(f, projectName)
35+
36+
gitIgnorePath := fmt.Sprintf("%v/.gitignore", rootDir)
37+
f, err = os.Create(gitIgnorePath)
38+
if err != nil {
39+
log.Printf("Error creating commit0 config: %v", err)
40+
}
41+
Templator.GitIgnore.Execute(f, projectName)
42+
}
43+
1644
var createCmd = &cobra.Command{
1745
Use: "create",
1846
Short: "Create new project with provided name.",
@@ -23,30 +51,6 @@ var createCmd = &cobra.Command{
2351

2452
projectName := args[0]
2553

26-
rootDir := fmt.Sprintf("./%v", projectName)
27-
28-
log.Printf("Creating project %s.", projectName)
29-
30-
err := os.Mkdir(rootDir, os.ModePerm)
31-
if os.IsExist(err) {
32-
log.Fatalf("Directory %v already exists! Error: %v", projectName, err)
33-
} else if err != nil {
34-
log.Fatalf("Error creating root: %v ", err)
35-
}
36-
37-
commit0ConfigPath := fmt.Sprintf("%v/commit0.yml", rootDir)
38-
39-
f, err := os.Create(commit0ConfigPath)
40-
if err != nil {
41-
log.Printf("Error creating commit0 config: %v", err)
42-
}
43-
Templator.Commit0.Execute(f, projectName)
44-
45-
gitIgnorePath := fmt.Sprintf("%v/.gitignore", rootDir)
46-
f, err = os.Create(gitIgnorePath)
47-
if err != nil {
48-
log.Printf("Error creating commit0 config: %v", err)
49-
}
50-
Templator.GitIgnore.Execute(f, projectName)
54+
Create(projectName)
5155
},
5256
}

0 commit comments

Comments
 (0)