Skip to content

Commit a1e2551

Browse files
committed
chore: move toml function to config package and improve comments
1 parent cd0bc0b commit a1e2551

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

internal/config/patrol.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"errors"
55
"fmt"
66
"net/url"
7-
"sheriff/internal/toml"
87

98
zerolog "github.com/rs/zerolog/log"
109
)
@@ -49,14 +48,14 @@ type PatrolCommonOpts struct {
4948
Report PatrolReportOpts `toml:"report"`
5049
}
5150

52-
// Options only available from CLI configuration
51+
// PatrolCLIOpts are the options only available from CLI configuration
5352
type PatrolCLIOpts struct {
5453
Config string
5554
Verbose bool
5655
PatrolCommonOpts
5756
}
5857

59-
// Options only available from File configuration
58+
// PatrolFileOpts are the options only available from File configuration
6059
type PatrolFileOpts struct {
6160
PatrolCommonOpts
6261
}
@@ -65,7 +64,7 @@ func GetPatrolConfiguration(cliOpts PatrolCLIOpts) (config PatrolConfig, err err
6564
zerolog.Debug().Interface("cli options", cliOpts).Msg("Running with cli options")
6665
var tomlOpts PatrolFileOpts
6766
if cliOpts.Config != "" {
68-
found, err := toml.GetFile(cliOpts.Config, &tomlOpts)
67+
found, err := getTOMLFile(cliOpts.Config, &tomlOpts)
6968
if !found {
7069
return config, fmt.Errorf("failed to find configuration file %v", cliOpts.Config)
7170
} else if err != nil {
@@ -105,7 +104,7 @@ func mergeConfigs(cliOpts PatrolCLIOpts, fileOpts PatrolFileOpts) (config Patrol
105104
return
106105
}
107106

108-
// Returns valueA if != nil, otherwise valueB if != nil, otherwise the provided default value
107+
// getCliOrFileOption returns valueA if != nil, otherwise valueB if != nil, otherwise the provided default value
109108
func getCliOrFileOption[T interface{}](valueA *T, valueB *T, def T) (r T) {
110109
if valueA != nil {
111110
return *valueA

internal/config/project.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package config
22

33
import (
4-
"sheriff/internal/toml"
5-
64
"path"
75

86
"github.com/rs/zerolog/log"
@@ -22,7 +20,7 @@ type ProjectConfig struct {
2220
}
2321

2422
func GetProjectConfiguration(projectName string, dir string) (config ProjectConfig) {
25-
found, err := toml.GetFile(path.Join(dir, projectConfigFileName), &config)
23+
found, err := getTOMLFile(path.Join(dir, projectConfigFileName), &config)
2624
if err != nil {
2725
log.Error().Err(err).Str("project", projectName).Msg("Failed to read project configuration. Running with empty configuration.")
2826
} else if found {
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package toml
1+
package config
22

33
import (
44
"errors"
@@ -9,8 +9,8 @@ import (
99
"github.com/rs/zerolog/log"
1010
)
1111

12-
// Parses and sets passed config pointer by value
13-
func GetFile[T interface{}](filename string, config *T) (found bool, err error) {
12+
// getTOMLFile parses and sets passed config pointer by value
13+
func getTOMLFile[T interface{}](filename string, config *T) (found bool, err error) {
1414
if _, err := os.Stat(filename); os.IsNotExist(err) {
1515
return false, nil
1616
} else if err != nil {

0 commit comments

Comments
 (0)