Skip to content

Commit e2b675e

Browse files
feat(.github): ConfigParser adds Type() string for informing the user which parser is being used. (#4)
1 parent 6a2e775 commit e2b675e

File tree

8 files changed

+14
-10
lines changed

8 files changed

+14
-10
lines changed

config_file_type.go

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ type ConfigFileType struct {
5050
ConfigType
5151
}
5252

53+
// Type returns which parser is in use.
54+
func (f *ConfigFileType) Type() string {
55+
return "Not Implemented"
56+
}
57+
5358
// Stat checks if the file exists and computes the platform specific Path and
5459
// directly writes to the provided diagnostics.
5560
func (f *ConfigFileType) Stat(diags *diag.Diagnostics, component diag.Component, cfg *Config, dirPath string) bool {

config_typeable.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
package configurator
22

33
import (
4-
"fmt"
5-
64
"github.com/matthewhartstonge/configurator/diag"
75
)
86

97
type ConfigTypeable interface {
10-
fmt.Stringer
11-
128
ConfigParser
139
ConfigImplementer
1410
}
1511

1612
type ConfigFileParser interface {
13+
// Stat returns false if a file can't be found by the parser.
1714
Stat(diags *diag.Diagnostics, component diag.Component, cfg *Config, dirPath string) bool
1815
}
1916

2017
type ConfigParser interface {
18+
// Type informs the user as to which parser is being used.
19+
Type() string
2120
// Parse returns the direct file path of the file that was parsed and any
2221
// associated errors returned from parsing the file.
2322
Parse(cfg *Config) (string, error)

configurator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ func processConfig(diags diag.Diagnostics, component diag.Component, cfg *Config
192192
path, err := configurer.Parse(cfg)
193193
if err != nil {
194194
// Low-level parsing issue
195-
diags.FromComponent(component, configurer.String()).
195+
diags.FromComponent(component, configurer.Type()).
196196
Error(fmt.Sprintf("Error parsing %s configuration", component),
197197
err.Error())
198198
return cfg, diags

env/envconfig/envconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type EnvConfig struct {
2222
configurator.ConfigType
2323
}
2424

25-
func (e EnvConfig) String() string {
25+
func (e EnvConfig) Type() string {
2626
return "EnvConfig configurator"
2727
}
2828

file/hcl/hcl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type HCL struct {
2727
configurator.ConfigFileType
2828
}
2929

30-
func (h HCL) String() string {
30+
func (h HCL) Type() string {
3131
return "HCL Configurator"
3232
}
3333

file/json/json.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ type JSON struct {
2222
configurator.ConfigFileType
2323
}
2424

25-
func (j JSON) String() string {
25+
func (j JSON) Type() string {
2626
return "JSON configurator"
2727
}

file/toml/toml.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ type TOML struct {
2222
configurator.ConfigFileType
2323
}
2424

25-
func (t TOML) String() string {
25+
func (t TOML) Type() string {
2626
return "TOML configurator"
2727
}

file/yaml/yaml.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ type YAML struct {
2222
configurator.ConfigFileType
2323
}
2424

25-
func (y YAML) String() string {
25+
func (y YAML) Type() string {
2626
return "YAML configurator"
2727
}

0 commit comments

Comments
 (0)