-
Notifications
You must be signed in to change notification settings - Fork 52
/
create.go
52 lines (40 loc) · 1.1 KB
/
create.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package cmd
import (
"fmt"
"log"
"os"
"github.com/spf13/cobra"
)
func init() {
rootCmd.AddCommand(createCmd)
}
var createCmd = &cobra.Command{
Use: "create",
Short: "Create new project with provided name.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) < 1 {
log.Fatalf("Project name cannot be empty!")
}
projectName := args[0]
rootDir := fmt.Sprintf("./%v", projectName)
log.Printf("Creating project %s.", projectName)
err := os.Mkdir(rootDir, os.ModePerm)
if os.IsExist(err) {
log.Fatalf("Directory %v already exists! Error: %v", projectName, err)
} else if err != nil {
log.Fatalf("Error creating root: %v ", err)
}
commit0ConfigPath := fmt.Sprintf("%v/commit0.yml", rootDir)
f, err := os.Create(commit0ConfigPath)
if err != nil {
log.Printf("Error creating commit0 config: %v", err)
}
Templator.Commit0.Execute(f, projectName)
gitIgnorePath := fmt.Sprintf("%v/.gitignore", rootDir)
f, err = os.Create(gitIgnorePath)
if err != nil {
log.Printf("Error creating commit0 config: %v", err)
}
Templator.GitIgnore.Execute(f, projectName)
},
}