Skip to content

Commit

Permalink
moveonly: create standlone function for Create
Browse files Browse the repository at this point in the history
Signed-off-by: William Casarin <jb55@jb55.com>
  • Loading branch information
jb55 committed Oct 11, 2019
1 parent efec50f commit 5f87969
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions cmd/create.go
Expand Up @@ -13,6 +13,34 @@ func init() {
rootCmd.AddCommand(createCmd)
}

func Create(projectName string) {
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)
}

var createCmd = &cobra.Command{
Use: "create",
Short: "Create new project with provided name.",
Expand All @@ -23,30 +51,6 @@ var createCmd = &cobra.Command{

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)
Create(projectName)
},
}

0 comments on commit 5f87969

Please sign in to comment.