Skip to content

Commit 4d3336a

Browse files
committed
changes:
- Fix output folder not being relative to config - Remove OutputNamespace (Just set it in templates) - Use filepath instead of path everywhere
1 parent 9c1fe77 commit 4d3336a

File tree

7 files changed

+17
-18
lines changed

7 files changed

+17
-18
lines changed

readme.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ Enable verbose logging with `--verbose` flag (can)
1919
- **OutputFolder (string)**:
2020
- Specifies the folder where generated code files will be saved.
2121
- It can be relative to current working directory
22-
- **OutputNamespace (string)**:
23-
- Sets the namespace for the generated code.
2422
- **GenerateModels (boolean)**:
2523
- If **True** Generates models
2624
- **GenerateProcessors (boolean)**:

src/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"flag"
66
"fmt"
77
"os"
8-
"path"
98
"path/filepath"
109
"strings"
1110
)
@@ -32,17 +31,21 @@ func GetConfig() (*Config, error) {
3231
// Cli args should override config loaded from file
3332
config.Command = args.command
3433
config.Verbose = args.verbose
35-
config.PathBase = path.Dir(args.configPath)
34+
config.PathBase = filepath.Dir(args.configPath)
3635

36+
//All paths are relative to config file
3737
config.ProcessorTemplate = filepath.Join(config.PathBase, config.ProcessorTemplate)
3838
config.DbContextTemplate = filepath.Join(config.PathBase, config.DbContextTemplate)
3939
config.ModelTemplate = filepath.Join(config.PathBase, config.ModelTemplate)
40+
config.OutputFolder = filepath.Join(config.PathBase, config.OutputFolder)
4041

4142
if err != nil {
4243
return nil, fmt.Errorf("getting configuration from file: %w", err)
4344
}
4445

4546
CurrentConfig = config
47+
48+
VerboseLog("%+v", config)
4649
return config, nil
4750
}
4851

@@ -67,7 +70,7 @@ func readJsonConfigFile(path string) (*Config, error) {
6770
func parseCLIArgs() (*cliArgs, error) {
6871

6972
verboseFlag := flag.Bool("verbose", false, "If true it will print more stuff")
70-
configPathFlag := flag.String("config", defaultConfigPath, "If true it will print more stuff")
73+
configPathFlag := flag.String("config", defaultConfigPath, "Path to config file, all paths are relative it")
7174
flag.Parse()
7275

7376
args := new(cliArgs)

src/debugginf.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dbGen
33
import (
44
"encoding/json"
55
"os"
6-
"path"
6+
"path/filepath"
77
"time"
88
)
99

@@ -21,7 +21,7 @@ func SaveToTempFile(functions interface{}, fileNamePrefix string) (err error) {
2121
return
2222
}
2323

24-
filename := path.Join(tempFolder, time.Now().Format("2006-01-02-15-04-05")+"-"+fileNamePrefix+".json")
24+
filename := filepath.Join(tempFolder, time.Now().Format("2006-01-02-15-04-05")+"-"+fileNamePrefix+".json")
2525
err = os.WriteFile(filename, saveJson, 777)
2626
if err != nil {
2727
return

src/generator.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"io"
88
"log"
99
"os"
10-
"path"
1110
"path/filepath"
1211
"text/template"
1312
)
@@ -69,7 +68,7 @@ func generateDbContext(routines []Routine, hashMap *map[string]string, config *C
6968
Functions: routines,
7069
}
7170

72-
fp := path.Join(config.OutputFolder, "DbContext"+config.GeneratedFileExtension)
71+
fp := filepath.Join(config.OutputFolder, "DbContext"+config.GeneratedFileExtension)
7372

7473
changed, err := generateFile(data, dbcontextTemplate, fp, hashMap)
7574
if err != nil {
@@ -93,15 +92,15 @@ func generateModels(routines []Routine, hashMap *map[string]string, config *Conf
9392
return fmt.Errorf("loading module template: %s", err)
9493
}
9594

96-
err = os.MkdirAll(path.Join(config.OutputFolder, modelsFolder), 777)
95+
err = os.MkdirAll(filepath.Join(config.OutputFolder, modelsFolder), 777)
9796

9897
for _, routine := range routines {
9998
if !routine.HasReturn {
10099
continue
101100
}
102101

103-
relPath := path.Join(modelsFolder, routine.ModelName+config.GeneratedFileExtension)
104-
filePath := path.Join(config.OutputFolder, relPath)
102+
relPath := filepath.Join(modelsFolder, routine.ModelName+config.GeneratedFileExtension)
103+
filePath := filepath.Join(config.OutputFolder, relPath)
105104

106105
changed, err := generateFile(routine, moduleTemplate, filePath, hashMap)
107106
if err != nil {
@@ -124,7 +123,7 @@ func generateProcessors(routines []Routine, hashMap *map[string]string, config *
124123
return fmt.Errorf("loading processor template: %s", err)
125124
}
126125

127-
err = os.MkdirAll(path.Join(config.OutputFolder, processorsFolder), 777)
126+
err = os.MkdirAll(filepath.Join(config.OutputFolder, processorsFolder), 777)
128127
if err != nil {
129128
return fmt.Errorf("creating processor output folder: %s", err)
130129
}
@@ -133,8 +132,8 @@ func generateProcessors(routines []Routine, hashMap *map[string]string, config *
133132
if !routine.HasReturn {
134133
continue
135134
}
136-
relPath := path.Join(processorsFolder, routine.ProcessorName+config.GeneratedFileExtension)
137-
filePath := path.Join(config.OutputFolder, relPath)
135+
relPath := filepath.Join(processorsFolder, routine.ProcessorName+config.GeneratedFileExtension)
136+
filePath := filepath.Join(config.OutputFolder, relPath)
138137

139138
changed, err := generateFile(routine, processorTemplate, filePath, hashMap)
140139
if err != nil {

src/helpers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ func Exit(template string, args ...any) {
3232
}
3333

3434
func VerboseLog(message string, args ...any) {
35-
if CurrentConfig.Verbose {
35+
// to be safe, use verbose log if current config isn't set
36+
if CurrentConfig == nil || CurrentConfig.Verbose {
3637
if len(args) == 0 {
3738
log.Print(colorBlue + message + colorReset)
3839

src/types.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ type Config struct {
3939
PathBase string //everything should be relative to config file
4040
ConnectionString string `json:"ConnectionString"`
4141
OutputFolder string `json:"OutputFolder,omitempty"`
42-
OutputNamespace string `json:"OutputNamespace,omitempty"`
4342
GenerateModels bool `json:"GenerateModels,omitempty"`
4443
GenerateProcessors bool `json:"GenerateProcessors,omitempty"`
4544
SkipModelGenForVoidReturns bool `json:"SkipModelGenForVoidReturns,omitempty"`

testing/db-gen.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"ConnectionString": "postgresql://postgres:Password3000!!@localhost:5432/db_gen",
33
"OutputFolder": "C:\\Testbench\\CSharp\\AspNetCoreDbGen\\AspNetCoreDbGen\\output",
4-
"OutputNamespace": "Database.Generated",
54
"GenerateModels": true,
65
"GenerateProcessors": true,
76
"SkipModelGenForVoidReturns": false,

0 commit comments

Comments
 (0)