about summary refs log tree commit diff stats
path: root/internal/config
diff options
context:
space:
mode:
Diffstat (limited to 'internal/config')
-rw-r--r--internal/config/config.go19
-rw-r--r--internal/config/fetcher.go49
-rw-r--r--internal/config/importer-type.go44
-rw-r--r--internal/config/repository.go5
-rw-r--r--internal/config/source.go48
5 files changed, 110 insertions, 55 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index eb46270..88bc006 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -115,12 +115,13 @@ var defaultConfig = Config{
 				Name:          "NixOS",
 				Key:           "nixos",
 				Enable:        true,
-				Type:          Channel,
+				Importer:      Options,
+				Fetcher:       Channel,
 				Channel:       "nixpkgs",
 				URL:           "https://channels.nixos.org/nixos-unstable/nixexprs.tar.xz",
 				ImportPath:    "nixos/release.nix",
 				Attribute:     "options",
-				OutputPath:    "share/doc/nixos/options.json",
+				OutputPath:    "share/doc/nixos",
 				FetchTimeout:  5 * time.Minute,
 				ImportTimeout: 15 * time.Minute,
 				Repo:          nixpkgs,
@@ -129,12 +130,13 @@ var defaultConfig = Config{
 				Name:          "Darwin",
 				Key:           "darwin",
 				Enable:        false,
-				Type:          Channel,
+				Importer:      Options,
+				Fetcher:       Channel,
 				Channel:       "darwin",
 				URL:           "https://github.com/LnL7/nix-darwin/archive/master.tar.gz",
 				ImportPath:    "release.nix",
 				Attribute:     "options",
-				OutputPath:    "share/doc/darwin/options.json",
+				OutputPath:    "share/doc/darwin",
 				FetchTimeout:  5 * time.Minute,
 				ImportTimeout: 15 * time.Minute,
 				Repo: Repository{
@@ -147,12 +149,13 @@ var defaultConfig = Config{
 				Name:          "Home Manager",
 				Key:           "home-manager",
 				Enable:        false,
+				Importer:      Options,
 				Channel:       "home-manager",
 				URL:           "https://github.com/nix-community/home-manager/archive/master.tar.gz",
-				Type:          Channel,
+				Fetcher:       Channel,
 				ImportPath:    "default.nix",
 				Attribute:     "docs.json",
-				OutputPath:    "share/doc/home-manager/options.json",
+				OutputPath:    "share/doc/home-manager",
 				FetchTimeout:  5 * time.Minute,
 				ImportTimeout: 15 * time.Minute,
 				Repo: Repository{
@@ -165,7 +168,9 @@ var defaultConfig = Config{
 				Name:          "Nix Packages",
 				Key:           "nixpkgs",
 				Enable:        true,
-				Type:          ChannelNixpkgs,
+				Importer:      Packages,
+				Fetcher:       ChannelNixpkgs,
+				Channel:       "nixos-unstable",
 				OutputPath:    "packages.json.br",
 				FetchTimeout:  5 * time.Minute,
 				ImportTimeout: 15 * time.Minute,
diff --git a/internal/config/fetcher.go b/internal/config/fetcher.go
new file mode 100644
index 0000000..5018b82
--- /dev/null
+++ b/internal/config/fetcher.go
@@ -0,0 +1,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
+}
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
+}
diff --git a/internal/config/repository.go b/internal/config/repository.go
index 8c17a4f..957cad4 100644
--- a/internal/config/repository.go
+++ b/internal/config/repository.go
@@ -8,7 +8,8 @@ import (
 type RepoType int
 
 const (
-	GitHub = iota + 1
+	UnknownRepoType = iota
+	GitHub
 )
 
 type Repository struct {
@@ -32,7 +33,7 @@ func parseRepoType(name string) (RepoType, error) {
 	case "github":
 		return GitHub, nil
 	default:
-		return Unknown, fmt.Errorf("unsupported repo type %s", name)
+		return UnknownRepoType, fmt.Errorf("unsupported repo type %s", name)
 	}
 }
 
diff --git a/internal/config/source.go b/internal/config/source.go
index 9797bb1..1fab61d 100644
--- a/internal/config/source.go
+++ b/internal/config/source.go
@@ -1,59 +1,15 @@
 package config
 
 import (
-	"fmt"
 	"time"
-
-	"github.com/stoewer/go-strcase"
-)
-
-type Type int
-
-const (
-	Unknown = iota
-	Channel
-	ChannelNixpkgs
-	DownloadOptions
 )
 
-func (f Type) String() string {
-	switch f {
-	case Channel:
-		return "channel"
-	case ChannelNixpkgs:
-		return "channel-nixpkgs"
-	case DownloadOptions:
-		return "download-options"
-	}
-
-	return fmt.Sprintf("Fetcher(%d)", f)
-}
-
-func parseType(name string) (Type, error) {
-	switch strcase.KebabCase(name) {
-	case "channel":
-		return Channel, nil
-	case "channel-nixpkgs":
-		return ChannelNixpkgs, nil
-	case "download-options":
-		return DownloadOptions, nil
-	default:
-		return Unknown, fmt.Errorf("unsupported fetcher %s", name)
-	}
-}
-
-func (f *Type) UnmarshalText(text []byte) error {
-	var err error
-	*f, err = parseType(string(text))
-
-	return err
-}
-
 type Source struct {
 	Name          string
 	Key           string
 	Enable        bool
-	Type          Type
+	Fetcher       Fetcher
+	Importer      ImporterType
 	Channel       string
 	URL           string
 	Attribute     string