Skip to content
Snippets Groups Projects
Commit 688a1f12 authored by Sigmund, Dominik's avatar Sigmund, Dominik
Browse files

Started creating init

parent 090834e5
No related branches found
No related tags found
No related merge requests found
Pipeline #82040 canceled
...@@ -4,14 +4,27 @@ import ( ...@@ -4,14 +4,27 @@ import (
"fmt" "fmt"
"os/exec" "os/exec"
"os" "os"
"time"
"path/filepath" "path/filepath"
"datasmith/utils" "datasmith/utils"
"datasmith/templates"
) )
func InitProject(name string, dbType string) { func InitProject(name string, dbType string) {
utils.PromptIfEmpty(&name, "Enter the name of the project: ") utils.PromptIfEmpty(&name, "Enter the name of the project: ")
slug := utils.Slugify(name) slug := utils.Slugify(name)
// Check if datasmith.yaml already exists in the directory
configFilePath := filepath.Join(slug, "datasmith.yaml")
if _, err := os.Stat(configFilePath); err == nil {
fmt.Printf("Error: A datasmith.yaml file already exists in the directory '%s'. Initialization aborted.\n", slug)
return
} else if !os.IsNotExist(err) {
fmt.Printf("Error checking datasmith.yaml file: %v\n", err)
return
}
if dbType == "" { if dbType == "" {
dbType = promptForDbType() dbType = promptForDbType()
} }
...@@ -21,6 +34,8 @@ func InitProject(name string, dbType string) { ...@@ -21,6 +34,8 @@ func InitProject(name string, dbType string) {
// Create project directories // Create project directories
createProjectDirs(slug) createProjectDirs(slug)
// Create datasmith.yaml file from template
createConfigFile(slug, name, dbType)
// TODO: copy base files // TODO: copy base files
...@@ -61,6 +76,22 @@ func createProjectDirs(projectName string) { ...@@ -61,6 +76,22 @@ func createProjectDirs(projectName string) {
} }
} }
// createConfigFile creates the datasmith.yaml file from template
func createConfigFile(projectDir, projectName, dbType string) {
data := map[string]interface{}{
"Name": projectName,
"CreatedAt": time.Now().Format(time.RFC3339),
"DbType": dbType,
}
err := templates.CreateFileFromTemplate(projectDir, "", "datasmith.yaml", "datasmith.yaml", data)
if err != nil {
fmt.Printf("Error creating datasmith.yaml file: %v\n", err)
} else {
fmt.Printf("Created file: %s/datasmith.yaml\n", projectDir)
}
}
// Help returns the help information for the init command // Help returns the help information for the init command
func InitHelp() string { func InitHelp() string {
return "init [name] [--type mysql|postgres] : Create a new project with the specified name and database type." return "init [name] [--type mysql|postgres] : Create a new project with the specified name and database type."
......
# datasmith.yaml
name: {{ .Name }}
version: 0.0.0
created_at: {{ .CreatedAt }}
database_type: {{ .DbType }}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment