pkg

package
v0.0.0-...-02c76fb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetExitCode

func GetExitCode(err error) (uint32, error)

GetExitCode returns the exit code of an error

Types

type ExecCaller

type ExecCaller struct{}

ExecCaller is a dummy struct to handle wrapping exec.Command in the SysCaller interface.

func (ExecCaller) Run

func (e ExecCaller) Run(cmd string) ([]byte, error)

Run executes `cmd` as a /bin/sh script and returns the output and error

type Package

type Package struct {
	// name of the package
	Name string `export:"name"`

	// package state; one of "present" or "absent"
	State  State `export:"state"`
	PkgMgr PackageManager
}

Package is an API for package state

func (*Package) Apply

Apply desired package state

func (*Package) Check

Check if the package has to be 'present', or 'absent'

func (*Package) PackageState

func (p *Package) PackageState() State

PackageState returns a State ("present","absent") based on whether a package is installed or not.

type PackageManager

type PackageManager interface {
	// If the package is installed, returns the version and true, otherwise
	// returns an empty string and false.
	InstalledVersion(string) (PackageVersion, bool)

	// Installs a package, returning an error if something went wrong
	InstallPackage(string) (string, error)

	// Removes a package, returning an error if something went wrong
	RemovePackage(string) (string, error)
}

PackageManager describes an interface for managing packages and helps make `Check` and `Apply` testable.

type PackageVersion

type PackageVersion string

PackageVersion is a type alias for a string, since various packages may use different naming conventions

type State

type State string

State type for Package

const (
	// StatePresent indicates the package should be present
	StatePresent State = "present"

	// StateAbsent indicates the package should be absent
	StateAbsent State = "absent"
)

type SysCaller

type SysCaller interface {
	Run(string) ([]byte, error)
}

SysCaller allows us to mock exec.Command

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL