github.com/AlpineAIO/wails/v2@v2.0.0-beta.32.0.20240505041856-1047a8fa5fef/internal/system/packagemanager/pm.go (about)

     1  package packagemanager
     2  
     3  // Package contains information about a system package
     4  type Package struct {
     5  	Name           string
     6  	Version        string
     7  	InstallCommand map[string]string
     8  	SystemPackage  bool
     9  	Library        bool
    10  	Optional       bool
    11  }
    12  
    13  type packagemap = map[string][]*Package
    14  
    15  // PackageManager is a common interface across all package managers
    16  type PackageManager interface {
    17  	Name() string
    18  	Packages() packagemap
    19  	PackageInstalled(pkg *Package) (bool, error)
    20  	PackageAvailable(pkg *Package) (bool, error)
    21  	InstallCommand(pkg *Package) string
    22  }
    23  
    24  // Dependency represents a system package that we require
    25  type Dependency struct {
    26  	Name           string
    27  	PackageName    string
    28  	Installed      bool
    29  	InstallCommand string
    30  	Version        string
    31  	Optional       bool
    32  	External       bool
    33  }
    34  
    35  // DependencyList is a list of Dependency instances
    36  type DependencyList []*Dependency
    37  
    38  // InstallAllRequiredCommand returns the command you need to use to install all required dependencies
    39  func (d DependencyList) InstallAllRequiredCommand() string {
    40  	result := ""
    41  	for _, dependency := range d {
    42  		if !dependency.Installed && !dependency.Optional {
    43  			result += "  - " + dependency.Name + ": " + dependency.InstallCommand + "\n"
    44  		}
    45  	}
    46  
    47  	return result
    48  }
    49  
    50  // InstallAllOptionalCommand returns the command you need to use to install all optional dependencies
    51  func (d DependencyList) InstallAllOptionalCommand() string {
    52  	result := ""
    53  	for _, dependency := range d {
    54  		if !dependency.Installed && dependency.Optional {
    55  			result += "  - " + dependency.Name + ": " + dependency.InstallCommand + "\n"
    56  		}
    57  	}
    58  
    59  	return result
    60  }