Documentation
¶
Overview ¶
Package syspkg provides a unified interface for interacting with multiple package management systems. It allows you to query, install, and remove packages, and supports package managers like Apt, Snap, and Flatpak.
To get started, create a new SysPkg instance by calling the New() function with the desired IncludeOptions. After obtaining a SysPkg instance, you can use the FindPackageManagers() function to find available package managers on the system, and GetPackageManager() to get a specific package manager.
Example:
includeOptions := syspkg.IncludeOptions{
AllAvailable: true,
}
sysPkg, err := syspkg.New(includeOptions)
if err != nil {
log.Fatal(err)
}
aptManager := sysPkg.GetPackageManager("apt")
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IncludeOptions ¶
type IncludeOptions struct {
AllAvailable bool
Apk bool
Apt bool
Dnf bool
Flatpak bool
Snap bool
Zypper bool
}
IncludeOptions specifies which package managers to include when creating a SysPkg instance.
type PackageInfo ¶
type PackageInfo = manager.PackageInfo
PackageInfo represents a package's information.
type PackageManager ¶
type PackageManager interface {
// IsAvailable checks if the package manager is available on the current system.
IsAvailable() bool
// GetPackageManager returns the name of the package manager.
GetPackageManager() string
// Install installs the specified packages using the package manager.
Install(pkgs []string, opts *manager.Options) ([]manager.PackageInfo, error)
// Delete removes the specified packages using the package manager.
Delete(pkgs []string, opts *manager.Options) ([]manager.PackageInfo, error)
// Find searches for packages using the specified keywords.
Find(keywords []string, opts *manager.Options) ([]manager.PackageInfo, error)
// ListInstalled lists all installed packages.
ListInstalled(opts *manager.Options) ([]manager.PackageInfo, error)
// ListUpgradable lists all upgradable packages.
ListUpgradable(opts *manager.Options) ([]manager.PackageInfo, error)
// Upgrade upgrades all packages or only the specified ones.
UpgradeAll(opts *manager.Options) ([]manager.PackageInfo, error)
// Refresh refreshes the package index.
Refresh(opts *manager.Options) error
// GetPackageInfo returns information about the specified package.
GetPackageInfo(pkg string, opts *manager.Options) (manager.PackageInfo, error)
}
PackageManager is the interface that defines the methods for interacting with various package managers.
type SysPkg ¶
type SysPkg interface {
// FindPackageManagers returns a map of available package managers based on the specified IncludeOptions.
// If the AllAvailable option is set to true, all available package managers will be returned.
// Otherwise, only the specified package managers will be returned.
// If no suitable package managers are found, an error is returned.
FindPackageManagers(include IncludeOptions) (map[string]PackageManager, error)
// RefreshPackageManagers refreshes the internal package manager list based on the specified IncludeOptions, and returns the new list.
// If the AllAvailable option is set to true, all available package managers will be included.
// Otherwise, only the specified package managers will be included.
// If no suitable package managers are found, an error is returned.
RefreshPackageManagers(include IncludeOptions) (map[string]PackageManager, error)
// GetPackageManager returns a PackageManager instance based on the specified name, from the list of available package managers specified in the IncludeOptions.
// If the name is empty, the first available package manager will be returned.
// If no suitable package manager is found, an error is returned.
// Note: only package managers that are specified in the IncludeOptions when creating the SysPkg instance (with New() method) will be returned. If you want to use package managers that are not specified in the IncludeOptions, you should use the FindPackageManagers() method to get a list of all available package managers, or use RefreshPackageManagers() with the IncludeOptions parameter to refresh the package manager list.
GetPackageManager(name string) PackageManager
}
SysPkg is the interface that defines the methods for interacting with the SysPkg library.
func New ¶
func New(include IncludeOptions) (SysPkg, error)
New creates a new SysPkg instance with the specified IncludeOptions.
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
syspkg
command
Package main contains the syspkg CLI tool, a universal system package manager.
|
Package main contains the syspkg CLI tool, a universal system package manager. |
|
Package manager provides utilities for managing the application.
|
Package manager provides utilities for managing the application. |
|
apt
Package apt provides an implementation of the syspkg manager interface for the apt package manager.
|
Package apt provides an implementation of the syspkg manager interface for the apt package manager. |
|
flatpak
Package flatpak provides an implementation of the syspkg manager interface for the Flatpak package manager.
|
Package flatpak provides an implementation of the syspkg manager interface for the Flatpak package manager. |
|
snap
Package snap provides an implementation of the syspkg manager interface for the snap package manager.
|
Package snap provides an implementation of the syspkg manager interface for the snap package manager. |