From 5a304cf18f02c20a61e4790bdf112896705df857 Mon Sep 17 00:00:00 2001 From: Aly Raffauf Date: Fri, 19 Jun 2026 03:49:05 -0400 Subject: [PATCH] move ToSource from config -> source --- internal/appherder/config.go | 25 ------------------------- internal/appherder/source.go | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/internal/appherder/config.go b/internal/appherder/config.go index 3f67971..c1083c5 100644 --- a/internal/appherder/config.go +++ b/internal/appherder/config.go @@ -27,31 +27,6 @@ type SourceConfig struct { URL string `toml:"url"` } -func (sc SourceConfig) ToSource() (Source, error) { - switch sc.Type { - case "github": - return githubReleaseSource{ - owner: sc.Owner, - repo: sc.Repo, - tag: sc.Tag, - pattern: sc.Pattern, - }, nil - case "gitlab": - return gitlabReleaseSource{ - host: sc.Host, - project: sc.Project, - tag: sc.Tag, - pattern: sc.Pattern, - }, nil - case "zsync": - return zsyncURLSource{url: sc.URL}, nil - case "static": - return staticURLSource{url: sc.URL}, nil - default: - return nil, fmt.Errorf("unknown source type %q (expected github, gitlab, zsync, or static)", sc.Type) - } -} - func configPath() string { return filepath.Join(xdg.ConfigHome, "appherder", "config.toml") } diff --git a/internal/appherder/source.go b/internal/appherder/source.go index 4304f7e..332eafc 100644 --- a/internal/appherder/source.go +++ b/internal/appherder/source.go @@ -82,6 +82,32 @@ type Source interface { Kind() string } +// ToSource constructs a Source from a config entry. +func (sc SourceConfig) ToSource() (Source, error) { + switch sc.Type { + case "github": + return githubReleaseSource{ + owner: sc.Owner, + repo: sc.Repo, + tag: sc.Tag, + pattern: sc.Pattern, + }, nil + case "gitlab": + return gitlabReleaseSource{ + host: sc.Host, + project: sc.Project, + tag: sc.Tag, + pattern: sc.Pattern, + }, nil + case "zsync": + return zsyncURLSource{url: sc.URL}, nil + case "static": + return staticURLSource{url: sc.URL}, nil + default: + return nil, fmt.Errorf("unknown source type %q (expected github, gitlab, zsync, or static)", sc.Type) + } +} + // ReadUpdateInfo returns the AppImage's embedded update-information string from // its .upd_info ELF section, or "" when absent or empty. func ReadUpdateInfo(path string) (string, error) { -- 2.51.2