Skip to content

Commit

Permalink
refactor: rename package
Browse files Browse the repository at this point in the history
  • Loading branch information
0xDones committed Jun 25, 2023
1 parent 947ff84 commit d8eeb71
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
5 changes: 2 additions & 3 deletions cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"fmt"
"os"
"path/filepath"
"tfgen/config"
"tfgen/tfgen"

"github.com/rs/zerolog/log"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -36,7 +35,7 @@ func clean(targetDir string) error {
if err != nil {
log.Fatal().Err(err).Msg("failed to get absolute path")
}
configHandler := config.NewConfigHandler(absTargetDir)
configHandler := tfgen.NewConfigHandler(absTargetDir)
if err := configHandler.ParseConfigFiles(); err != nil {
return err
}
Expand Down
8 changes: 3 additions & 5 deletions cmd/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import (
"fmt"
"os"
"path/filepath"
"tfgen/config"
"tfgen/utils"
"tfgen/tfgen"

"github.com/rs/zerolog/log"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -37,7 +35,7 @@ func exec(targetDir string) error {
if err != nil {
log.Fatal().Err(err).Msg("failed to get absolute path")
}
configHandler := config.NewConfigHandler(absTargetDir)
configHandler := tfgen.NewConfigHandler(absTargetDir)
if err := configHandler.ParseConfigFiles(); err != nil {
return err
}
Expand All @@ -47,7 +45,7 @@ func exec(targetDir string) error {
hasError := false
for templateName, templateBody := range configHandler.ConfigFile.TemplateFiles {
filePath := filepath.Join(configHandler.TargetDir, templateName)
if err := utils.WriteFile(filePath, templateBody, configHandler.TemplateContext); err != nil {
if err := tfgen.WriteFile(filePath, templateBody, configHandler.TemplateContext); err != nil {
hasError = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion config/config.go → tfgen/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package tfgen

import (
"path"
Expand Down
2 changes: 1 addition & 1 deletion config/finder.go → tfgen/finder.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package config
package tfgen

import (
"fmt"
Expand Down
2 changes: 1 addition & 1 deletion utils/fs.go → tfgen/fs.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package tfgen

import (
"os"
Expand Down
9 changes: 4 additions & 5 deletions config/handler.go → tfgen/handler.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package config
package tfgen

import (
"path"
"path/filepath"
"tfgen/utils"

"github.com/rs/zerolog/log"
)
Expand Down Expand Up @@ -31,7 +30,7 @@ func NewConfigHandler(targetDir string) *ConfigHandler {
}

func (c *ConfigHandler) ParseConfigFiles() error {
configFiles := []ConfigFile{}
var configFiles []ConfigFile
targetDir := c.TargetDir
for {
configFilePath, err := searchInParentDirs(targetDir, CONFIG_FILE_NAME, MAX_ITER)
Expand All @@ -40,7 +39,7 @@ func (c *ConfigHandler) ParseConfigFiles() error {
return err
}

byteContent := utils.ReadFile(configFilePath)
byteContent := ReadFile(configFilePath)
config, err := NewConfigFile(byteContent, configFilePath)
if err != nil {
return err
Expand Down Expand Up @@ -87,7 +86,7 @@ func (c *ConfigHandler) SetupTemplateContext() {
func (c *ConfigHandler) CleanupFiles() error {
for templateName := range c.ConfigFile.TemplateFiles {
filePath := filepath.Join(c.TargetDir, templateName)
err := utils.DeleteFile(filePath)
err := DeleteFile(filePath)
if err != nil {
log.Error().Err(err).Msgf("failed to delete file: %s", templateName)
return err
Expand Down

0 comments on commit d8eeb71

Please sign in to comment.