mirror of
https://github.com/gogrlx/snack.git
synced 2026-04-02 05:08:42 -07:00
Add optional interfaces that providers can implement beyond the base Manager. grlx can type-assert to check support at runtime: - VersionQuerier: LatestVersion, ListUpgrades, UpgradeAvailable, VersionCmp - Holder: Hold, Unhold, ListHeld (version pinning) - Cleaner: Autoremove, Clean (orphan/cache cleanup) - FileOwner: FileList, Owner (file-to-package mapping) - RepoManager: ListRepos, AddRepo, RemoveRepo - KeyManager: AddKey, RemoveKey, ListKeys (GPG signing keys) - Grouper: GroupList, GroupInfo, GroupInstall - NameNormalizer: NormalizeName, ParseArch Also adds GetCapabilities() helper, Repository type, and updated README.
38 lines
896 B
Go
38 lines
896 B
Go
package snack
|
|
|
|
// Capabilities reports which optional interfaces a Manager implements.
|
|
// Useful for grlx to determine what operations are available before
|
|
// attempting them.
|
|
type Capabilities struct {
|
|
VersionQuery bool
|
|
Hold bool
|
|
Clean bool
|
|
FileOwnership bool
|
|
RepoManagement bool
|
|
KeyManagement bool
|
|
Groups bool
|
|
NameNormalize bool
|
|
}
|
|
|
|
// GetCapabilities probes a Manager for all optional interface support.
|
|
func GetCapabilities(m Manager) Capabilities {
|
|
_, vq := m.(VersionQuerier)
|
|
_, h := m.(Holder)
|
|
_, c := m.(Cleaner)
|
|
_, fo := m.(FileOwner)
|
|
_, rm := m.(RepoManager)
|
|
_, km := m.(KeyManager)
|
|
_, g := m.(Grouper)
|
|
_, nn := m.(NameNormalizer)
|
|
return Capabilities{
|
|
VersionQuery: vq,
|
|
Hold: h,
|
|
Clean: c,
|
|
FileOwnership: fo,
|
|
RepoManagement: rm,
|
|
KeyManagement: km,
|
|
Groups: g,
|
|
NameNormalize: nn,
|
|
}
|
|
}
|