Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DataSmith
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
apps
DataSmith
Commits
688a1f12
Commit
688a1f12
authored
11 months ago
by
Sigmund, Dominik
Browse files
Options
Downloads
Patches
Plain Diff
Started creating init
parent
090834e5
No related branches found
No related tags found
No related merge requests found
Pipeline
#82040
canceled
11 months ago
Stage: build
Stage: scan
Stage: release
Changes
2
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
commands/init.go
+31
-0
31 additions, 0 deletions
commands/init.go
templates/datasmith.yaml.tmpl
+6
-0
6 additions, 0 deletions
templates/datasmith.yaml.tmpl
with
37 additions
and
0 deletions
commands/init.go
+
31
−
0
View file @
688a1f12
...
@@ -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."
...
...
This diff is collapsed.
Click to expand it.
templates/datasmith.yaml.tmpl
0 → 100644
+
6
−
0
View file @
688a1f12
# datasmith.yaml
name: {{ .Name }}
version: 0.0.0
created_at: {{ .CreatedAt }}
database_type: {{ .DbType }}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment