diff options
author | Alan Pearce | 2024-05-16 23:41:57 +0200 |
---|---|---|
committer | Alan Pearce | 2024-05-16 23:41:57 +0200 |
commit | a5e758d41c151c17ed03b39454470ba8dd0c3b99 (patch) | |
tree | 386333b5020477eabcf490773113b029e47a21ef /internal/config/importer-type.go | |
parent | d558039919b6198a246a6a3fd007276191cb4b2f (diff) | |
download | searchix-a5e758d41c151c17ed03b39454470ba8dd0c3b99.tar.lz searchix-a5e758d41c151c17ed03b39454470ba8dd0c3b99.tar.zst searchix-a5e758d41c151c17ed03b39454470ba8dd0c3b99.zip |
refactor: separate fetch and import logic
Diffstat (limited to 'internal/config/importer-type.go')
-rw-r--r-- | internal/config/importer-type.go | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/internal/config/importer-type.go b/internal/config/importer-type.go new file mode 100644 index 0000000..b3b3e88 --- /dev/null +++ b/internal/config/importer-type.go @@ -0,0 +1,44 @@ +package config + +import ( + "fmt" + + "github.com/stoewer/go-strcase" +) + +type ImporterType int + +const ( + UnknownType = iota + Packages + Options +) + +func (i ImporterType) String() string { + switch i { + case Packages: + return "packages" + case Options: + return "options" + } + + return fmt.Sprintf("Type(%d)", i) +} + +func parseType(name string) (ImporterType, error) { + switch strcase.KebabCase(name) { + case "packages": + return Packages, nil + case "options": + return Options, nil + default: + return UnknownType, fmt.Errorf("unsupported importer %s", name) + } +} + +func (i *ImporterType) UnmarshalText(text []byte) error { + var err error + *i, err = parseType(string(text)) + + return err +} |