about summary refs log tree commit diff stats
path: root/internal/config/fetcher.go
blob: 5018b82ade74f057e05e5f592327e02547b8207e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package config

import (
	"fmt"

	"github.com/stoewer/go-strcase"
)

type Fetcher int

const (
	UnknownFetcher = iota
	Channel
	ChannelNixpkgs
	Download
)

func (f Fetcher) String() string {
	switch f {
	case Channel:
		return "channel"
	case ChannelNixpkgs:
		return "channel-nixpkgs"
	case Download:
		return "download"
	}

	return fmt.Sprintf("Fetcher(%d)", f)
}

func parseFetcher(name string) (Fetcher, error) {
	switch strcase.KebabCase(name) {
	case "channel":
		return Channel, nil
	case "channel-nixpkgs":
		return ChannelNixpkgs, nil
	case "download":
		return Download, nil
	default:
		return UnknownFetcher, fmt.Errorf("unsupported fetcher %s", name)
	}
}

func (f *Fetcher) UnmarshalText(text []byte) error {
	var err error
	*f, err = parseFetcher(string(text))

	return err
}