diff --git a/manifests.go b/manifests.go index fefad40..fbe5b1b 100644 --- a/manifests.go +++ b/manifests.go @@ -43,7 +43,7 @@ func ingestManifestsWorker(autoInternalize bool, autoInternalizePath string, aut if basemanifest.PackageIdentifier != "" && basemanifest.PackageVersion != "" && basemanifest.ManifestType != "" && basemanifest.ManifestVersion != "" { if basemanifest.ManifestType == "singleton" { - var manifest = parseFileAsSingletonManifest(filepath.Join(path, file.Name())) + var manifest = parseFileAsSingletonManifest(basemanifest.ManifestVersion, filepath.Join(path, file.Name())) logging.Logger.Debug().Str("package", basemanifest.PackageIdentifier).Str("packageversion", basemanifest.PackageVersion).Msgf("found singleton manifest") // Singleton manifests can only contain version of a package each @@ -537,43 +537,47 @@ func parseFileAsBaseManifest (path string) (*models.BaseManifest, error) { return manifest, err } -func parseFileAsSingletonManifest (path string) models.API_ManifestInterface { +func parseFileAsSingletonManifest (manifestVersion string, path string) models.API_ManifestInterface { yamlFile, err := os.ReadFile(path) if err != nil { logging.Logger.Error().Err(err).Msg("error opening yaml file") } - singleton := &models.Manifest_SingletonManifest_1_1_0{} - err = yaml.Unmarshal(yamlFile, singleton) + var singleton models.Manifest_SingletonManifestInterface + singleton, err = unmarshalSingletonManifest(manifestVersion, yamlFile) if err != nil { logging.Logger.Error().Err(err).Msg("error unmarshalling singleton") } - manifest := singletonToStandardManifest(singleton) + manifest := singleton.ToApiManifest() return manifest } -func singletonToStandardManifest (singleton *models.Manifest_SingletonManifest_1_1_0) *models.API_Manifest_1_1_0 { - manifest := &models.API_Manifest_1_1_0 { - PackageIdentifier: singleton.PackageIdentifier, - Versions: []models.API_ManifestVersionInterface{ models.API_ManifestVersion_1_1_0 { - PackageVersion: singleton.PackageVersion, - DefaultLocale: models.API_DefaultLocale_1_1_0 { - PackageLocale: singleton.PackageLocale, - PackageName: singleton.PackageName, - Publisher: singleton.Publisher, - ShortDescription: singleton.ShortDescription, - License: singleton.License, - }, - Channel: "", - Locales: []models.API_Locale_1_1_0{}, - Installers: []models.API_Installer_1_1_0{singleton.Installers[0].ToApiInstaller()}, - }, - }, - } +func unmarshalSingletonManifest (manifestVersion string, yamlData []byte) (models.Manifest_SingletonManifestInterface, error) { + var smanifest models.Manifest_SingletonManifestInterface - return manifest + switch manifestVersion { + case "1.1.0": + smanifest = &models.Manifest_SingletonManifest_1_1_0{} + case "1.2.0": + smanifest = &models.Manifest_SingletonManifest_1_2_0{} + case "1.4.0": + smanifest = &models.Manifest_SingletonManifest_1_4_0{} + case "1.5.0": + smanifest = &models.Manifest_SingletonManifest_1_5_0{} + case "1.6.0": + smanifest = &models.Manifest_SingletonManifest_1_6_0{} + default: + return nil, errors.New("unsupported SingletonManifest version " + manifestVersion) + } + + err := yaml.Unmarshal(yamlData, smanifest) + if err != nil { + return nil, err + } + + return smanifest, nil } func caseInsensitiveHasSuffix(s, substr string) bool { diff --git a/models/manifests_1_1_0.go b/models/manifests_1_1_0.go index 5c58b03..ff428dd 100644 --- a/models/manifests_1_1_0.go +++ b/models/manifests_1_1_0.go @@ -22,6 +22,27 @@ type Manifest_SingletonManifest_1_1_0 struct { ManifestVersion string `yaml:"ManifestVersion"` } +func (in *Manifest_SingletonManifest_1_1_0) ToApiManifest() API_ManifestInterface { + return &API_Manifest_1_1_0{ + PackageIdentifier: in.PackageIdentifier, + Versions: []API_ManifestVersionInterface{ + &API_ManifestVersion_1_1_0{ + PackageVersion: in.PackageVersion, + DefaultLocale: API_DefaultLocale_1_1_0{ + PackageLocale: in.PackageLocale, + PackageName: in.PackageName, + Publisher: in.Publisher, + ShortDescription: in.ShortDescription, + License: in.License, + }, + Channel: "", + Locales: []API_Locale_1_1_0{}, + Installers: []API_Installer_1_1_0{in.Installers[0].ToApiInstaller()}, + }, + }, + } +} + // The struct for a separate version manifest file // https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.1.0/manifest.version.1.1.0.json type Manifest_VersionManifest_1_1_0 struct { diff --git a/models/manifests_1_2_0.go b/models/manifests_1_2_0.go index e048d23..a086a70 100644 --- a/models/manifests_1_2_0.go +++ b/models/manifests_1_2_0.go @@ -25,6 +25,27 @@ type Manifest_SingletonManifest_1_2_0 struct { ManifestVersion string `yaml:"ManifestVersion"` } +func (in *Manifest_SingletonManifest_1_2_0) ToApiManifest() API_ManifestInterface { + return &API_Manifest_1_4_0{ + PackageIdentifier: in.PackageIdentifier, + Versions: []API_ManifestVersionInterface{ + &API_ManifestVersion_1_4_0{ + PackageVersion: in.PackageVersion, + DefaultLocale: API_DefaultLocale_1_4_0{ + PackageLocale: in.PackageLocale, + PackageName: in.PackageName, + Publisher: in.Publisher, + ShortDescription: in.ShortDescription, + License: in.License, + }, + Channel: "", + Locales: []API_Locale_1_4_0{}, + Installers: []API_Installer_1_4_0{in.Installers[0].ToApiInstaller()}, + }, + }, + } +} + // The struct for a separate version manifest file // https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.1.0/manifest.version.1.1.0.json type Manifest_VersionManifest_1_2_0 struct { diff --git a/models/manifests_1_4_0.go b/models/manifests_1_4_0.go index 5fae638..d2b5a33 100644 --- a/models/manifests_1_4_0.go +++ b/models/manifests_1_4_0.go @@ -28,6 +28,27 @@ type Manifest_SingletonManifest_1_4_0 struct { ManifestVersion string `yaml:"ManifestVersion"` } +func (in *Manifest_SingletonManifest_1_4_0) ToApiManifest() API_ManifestInterface { + return &API_Manifest_1_4_0{ + PackageIdentifier: in.PackageIdentifier, + Versions: []API_ManifestVersionInterface{ + &API_ManifestVersion_1_4_0{ + PackageVersion: in.PackageVersion, + DefaultLocale: API_DefaultLocale_1_4_0{ + PackageLocale: in.PackageLocale, + PackageName: in.PackageName, + Publisher: in.Publisher, + ShortDescription: in.ShortDescription, + License: in.License, + }, + Channel: "", + Locales: []API_Locale_1_4_0{}, + Installers: []API_Installer_1_4_0{in.Installers[0].ToApiInstaller()}, + }, + }, + } +} + // The struct for a separate version manifest file // https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.4.0/manifest.version.1.4.0.json type Manifest_VersionManifest_1_4_0 struct { diff --git a/models/manifests_1_5_0.go b/models/manifests_1_5_0.go index 88a3cfb..ad9a56c 100644 --- a/models/manifests_1_5_0.go +++ b/models/manifests_1_5_0.go @@ -29,6 +29,27 @@ type Manifest_SingletonManifest_1_5_0 struct { ManifestVersion string `yaml:"ManifestVersion"` } +func (in *Manifest_SingletonManifest_1_5_0) ToApiManifest() API_ManifestInterface { + return &API_Manifest_1_5_0{ + PackageIdentifier: in.PackageIdentifier, + Versions: []API_ManifestVersionInterface{ + &API_ManifestVersion_1_5_0{ + PackageVersion: in.PackageVersion, + DefaultLocale: API_DefaultLocale_1_5_0{ + PackageLocale: in.PackageLocale, + PackageName: in.PackageName, + Publisher: in.Publisher, + ShortDescription: in.ShortDescription, + License: in.License, + }, + Channel: "", + Locales: []API_Locale_1_5_0{}, + Installers: []API_Installer_1_5_0{in.Installers[0].ToApiInstaller()}, + }, + }, + } +} + // The struct for a separate version manifest file // https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.5.0/manifest.version.1.5.0.json type Manifest_VersionManifest_1_5_0 struct { diff --git a/models/manifests_1_6_0.go b/models/manifests_1_6_0.go index cdec628..ebeecad 100755 --- a/models/manifests_1_6_0.go +++ b/models/manifests_1_6_0.go @@ -29,6 +29,27 @@ type Manifest_SingletonManifest_1_6_0 struct { ManifestVersion string `yaml:"ManifestVersion"` } +func (in *Manifest_SingletonManifest_1_6_0) ToApiManifest() API_ManifestInterface { + return &API_Manifest_1_6_0{ + PackageIdentifier: in.PackageIdentifier, + Versions: []API_ManifestVersionInterface{ + &API_ManifestVersion_1_6_0{ + PackageVersion: in.PackageVersion, + DefaultLocale: API_DefaultLocale_1_6_0{ + PackageLocale: in.PackageLocale, + PackageName: in.PackageName, + Publisher: in.Publisher, + ShortDescription: in.ShortDescription, + License: in.License, + }, + Channel: "", + Locales: []API_Locale_1_6_0{}, + Installers: []API_Installer_1_6_0{in.Installers[0].ToApiInstaller()}, + }, + }, + } +} + // The struct for a separate version manifest file // https://github.com/microsoft/winget-cli/blob/master/schemas/JSON/manifests/v1.6.0/manifest.version.1.6.0.json type Manifest_VersionManifest_1_6_0 struct { diff --git a/models/manifests_common.go b/models/manifests_common.go index 209b5a3..bc78b59 100644 --- a/models/manifests_common.go +++ b/models/manifests_common.go @@ -38,6 +38,10 @@ func (basemanifest BaseManifest) ToMultiFileManifest() MultiFileManifest { } } +type Manifest_SingletonManifestInterface interface { + ToApiManifest() API_ManifestInterface +} + type Manifest_VersionManifestInterface interface { GetPackageVersion() string } diff --git a/packages/bottom.yml b/packages/bottom.yml index f6a7f9e..c8e1560 100644 --- a/packages/bottom.yml +++ b/packages/bottom.yml @@ -13,5 +13,6 @@ Installers: InstallerUrl: "https://github.com/ClementTsang/bottom/releases/download/0.6.8/bottom_x86_64_installer.msi" InstallerSha256: "43A860A1ECAC287CAF9745D774B0B2CE9C0A2A79D4048893E7649B0D8048EE58" #SignatureSha256: "" + DownloadCommandProhibited: true ManifestType: singleton -ManifestVersion: 1.1.0 +ManifestVersion: 1.6.0