about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
Diffstat (limited to 'internal')
-rw-r--r--internal/fetcher/channel.go20
-rw-r--r--internal/fetcher/download.go18
-rw-r--r--internal/fetcher/main.go42
-rw-r--r--internal/fetcher/nixpkgs-channel.go18
4 files changed, 57 insertions, 41 deletions
diff --git a/internal/fetcher/channel.go b/internal/fetcher/channel.go
index 5dc84b4..fd7427c 100644
--- a/internal/fetcher/channel.go
+++ b/internal/fetcher/channel.go
@@ -22,6 +22,23 @@ type ChannelFetcher struct {
 	Logger     *slog.Logger
 }
 
+func NewChannelFetcher(
+	source *config.Source,
+	dataPath string,
+	logger *slog.Logger,
+) (*ChannelFetcher, error) {
+	switch source.Importer {
+	case config.Options:
+		return &ChannelFetcher{
+			DataPath: dataPath,
+			Source:   source,
+			Logger:   logger,
+		}, nil
+	default:
+		return nil, fmt.Errorf("unsupported importer type %s", source.Importer)
+	}
+}
+
 func (i *ChannelFetcher) FetchIfNeeded(
 	parent context.Context,
 ) (f FetchedFiles, updated bool, err error) {
@@ -91,8 +108,7 @@ func (i *ChannelFetcher) FetchIfNeeded(
 	updated = before != after
 
 	f = FetchedFiles{
-		Options:  path.Join(dest, i.Source.OutputPath, "options.json"),
-		Packages: path.Join(dest, i.Source.OutputPath, "packages.json"),
+		Options: path.Join(dest, i.Source.OutputPath, "options.json"),
 	}
 
 	return
diff --git a/internal/fetcher/download.go b/internal/fetcher/download.go
index 4165886..2c7b8fd 100644
--- a/internal/fetcher/download.go
+++ b/internal/fetcher/download.go
@@ -2,6 +2,7 @@ package fetcher
 
 import (
 	"context"
+	"fmt"
 	"log/slog"
 	"net/url"
 	"path"
@@ -18,6 +19,23 @@ type DownloadFetcher struct {
 	Logger     *slog.Logger
 }
 
+func NewDownloadFetcher(
+	source *config.Source,
+	dataPath string,
+	logger *slog.Logger,
+) (*DownloadFetcher, error) {
+	switch source.Importer {
+	case config.Options:
+		return &DownloadFetcher{
+			DataPath: dataPath,
+			Source:   source,
+			Logger:   logger,
+		}, nil
+	default:
+		return nil, fmt.Errorf("unsupported importer type %s", source.Importer)
+	}
+}
+
 var files = map[string]string{
 	"revision": "revision",
 	"options":  "options.json",
diff --git a/internal/fetcher/main.go b/internal/fetcher/main.go
index d8bc25e..65f62db 100644
--- a/internal/fetcher/main.go
+++ b/internal/fetcher/main.go
@@ -18,42 +18,6 @@ type Fetcher interface {
 	FetchIfNeeded(context.Context) (FetchedFiles, bool, error)
 }
 
-func NewNixpkgsChannelFetcher(
-	source *config.Source,
-	dataPath string,
-	logger *slog.Logger,
-) *NixpkgsChannelFetcher {
-	return &NixpkgsChannelFetcher{
-		DataPath: dataPath,
-		Source:   source,
-		Logger:   logger,
-	}
-}
-
-func NewChannelFetcher(
-	source *config.Source,
-	dataPath string,
-	logger *slog.Logger,
-) *ChannelFetcher {
-	return &ChannelFetcher{
-		DataPath: dataPath,
-		Source:   source,
-		Logger:   logger,
-	}
-}
-
-func NewDownloadFetcher(
-	source *config.Source,
-	dataPath string,
-	logger *slog.Logger,
-) *DownloadFetcher {
-	return &DownloadFetcher{
-		DataPath: dataPath,
-		Source:   source,
-		Logger:   logger,
-	}
-}
-
 func New(
 	source *config.Source,
 	fetcherDataPath string,
@@ -61,11 +25,11 @@ func New(
 ) (fetcher Fetcher, err error) {
 	switch source.Fetcher {
 	case config.ChannelNixpkgs:
-		fetcher = NewNixpkgsChannelFetcher(source, fetcherDataPath, logger)
+		fetcher, err = NewNixpkgsChannelFetcher(source, fetcherDataPath, logger)
 	case config.Channel:
-		fetcher = NewChannelFetcher(source, fetcherDataPath, logger)
+		fetcher, err = NewChannelFetcher(source, fetcherDataPath, logger)
 	case config.Download:
-		fetcher = NewDownloadFetcher(source, fetcherDataPath, logger)
+		fetcher, err = NewDownloadFetcher(source, fetcherDataPath, logger)
 	default:
 		err = errors.Errorf("unsupported fetcher type %s", source.Fetcher.String())
 	}
diff --git a/internal/fetcher/nixpkgs-channel.go b/internal/fetcher/nixpkgs-channel.go
index 32aaac3..033b577 100644
--- a/internal/fetcher/nixpkgs-channel.go
+++ b/internal/fetcher/nixpkgs-channel.go
@@ -2,6 +2,7 @@ package fetcher
 
 import (
 	"context"
+	"fmt"
 	"log/slog"
 	"net/url"
 	"path"
@@ -23,6 +24,23 @@ func makeChannelURL(channel string, subPath string) (string, error) {
 	return url, errors.WithMessagef(err, "error creating URL")
 }
 
+func NewNixpkgsChannelFetcher(
+	source *config.Source,
+	dataPath string,
+	logger *slog.Logger,
+) (*NixpkgsChannelFetcher, error) {
+	switch source.Importer {
+	case config.Options, config.Packages:
+		return &NixpkgsChannelFetcher{
+			DataPath: dataPath,
+			Source:   source,
+			Logger:   logger,
+		}, nil
+	default:
+		return nil, fmt.Errorf("unsupported importer type %s", source.Importer)
+	}
+}
+
 const (
 	revisionFilename = "git-revision"
 	optionsFilename  = "options.json.br"