Documentation
¶
Overview ¶
Package packages is the package behavior: the packages installed on the host.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Behavior = behavior.Register(behavior.Define( "package", "The packages installed on the host", behavior.Node, behavior.API, behavior.Area(area.Software), behavior.CLI, behavior.Platform(behavior.PlatformDebian, newDebian), behavior.Platform(behavior.PlatformLinux, newReader), behavior.Platform(behavior.PlatformDarwin, newReader), behavior.RunsOnPlatform(behavior.PlatformDebian, "dpkg-query"), behavior.RunsOnPlatform(behavior.PlatformDarwin, "brew"), behavior.RunsIfPresent("rpm"), behavior.Read("list", List). Describe("List the packages installed on the host"). Explain("Lists each installed package with its version: dpkg on the Debian "+ "family, rpm on the other Linux families, and Homebrew on macOS."). Example("A Debian host", ListInput{}, []Installed{curl}, behavior.OnPlatform(behavior.PlatformDebian), behavior.Prints(dpkg, installed+"tree\t2.1.1-2\tamd64\tdeinstall\tdisplays an indented directory tree\t100\n"), ). Example("A Fedora host", ListInput{}, []Installed{{ Name: "curl", Version: "8.6.0-7.fc40", Architecture: "x86_64", Manager: "rpm", Description: "A utility for getting files from remote servers", Size: 790000, }}, behavior.OnPlatform(behavior.PlatformLinux), behavior.Prints(rpm, "curl\t8.6.0-7.fc40\tx86_64\tA utility for getting files from remote servers\t790000\n"), ). Example("A Mac", ListInput{}, []Installed{{Name: "jq", Version: "1.7.1", Manager: "brew"}}, behavior.OnPlatform(behavior.PlatformDarwin), behavior.Prints(brew, "jq 1.7 1.7.1\n"), ), behavior.Read("get", Get).Key("name"). Describe("Get one installed package"). Explain("Reads one package from the same list. A package that is not "+ "installed is not found."). Example("An installed package", GetInput{Name: "curl"}, curl, behavior.OnPlatform(behavior.PlatformDebian), behavior.Prints(dpkg, installed), ). Example("An installed formula", GetInput{Name: "jq"}, Installed{Name: "jq", Version: "1.7.1", Manager: "brew"}, behavior.OnPlatform(behavior.PlatformDarwin), behavior.Prints(brew, "jq 1.7.1\n"), ). Example("An installed RPM", GetInput{Name: "curl"}, Installed{ Name: "curl", Version: "8.6.0-7.fc40", Architecture: "x86_64", Manager: "rpm", }, behavior.OnPlatform(behavior.PlatformLinux), behavior.Prints(rpm, "curl\t8.6.0-7.fc40\tx86_64\n"), ). Fails("A package that is not installed", GetInput{Name: "tree"}, "not found", behavior.NotLive("the suite installs tree on a live host, for the package examples")). Fails("A name that is an option", GetInput{Name: "-oAPT::Get=x"}, "not a valid package name"). Fails("A name longer than 255 characters", GetInput{Name: strings.Repeat("a", 256)}, "not a valid package name"), behavior.Write("create", Create). On(behavior.PlatformDebian). Sudo("apt-get"). Describe("Install a package"). Explain("Installs the package with apt-get install, at the version when one is "+ "given. A package that is installed, at that version when one is given, "+ "does not change and reports changed: false. It runs on the Debian family "+ "only, and elsewhere reports skipped."). Example("Install a package", CreateInput{Name: "tree"}, Result{Name: "tree", Changed: true}, behavior.PrintsAfter("apt-get install -y -- tree", dpkg, tree), behavior.Ran("apt-get", "install", "-y", "--", "tree"), behavior.Reads(GetInput{Name: "tree"}, Installed{Name: "tree"}), ). Fails("A name that is an option", CreateInput{Name: "-oAPT::Get=x"}, "not a valid package name"). Fails("A name longer than 255 characters", CreateInput{Name: strings.Repeat("a", 256)}, "not a valid package name"). Fails("A version that is an option", CreateInput{Name: "tree", Version: "-x"}, "not a valid package version"). Fails("A version longer than 255 characters", CreateInput{ Name: "tree", Version: strings.Repeat("1", 256), }, "not a valid package version"), behavior.Write("delete", Delete).Key("name"). On(behavior.PlatformDebian). Sudo("apt-get"). Describe("Remove a package"). Explain("Removes the package with apt-get remove. A package that is not "+ "installed does not change and reports changed: false. It runs on the "+ "Debian family only, and elsewhere reports skipped."). Example("Remove a package", DeleteInput{Name: "tree"}, Result{Name: "tree", Changed: true}, behavior.After(CreateInput{Name: "tree"}), behavior.PrintsAfter("apt-get install -y -- tree", dpkg, tree), behavior.PrintsAfter("apt-get remove -y -- tree", dpkg, ""), behavior.Ran("apt-get", "remove", "-y", "--", "tree"), behavior.ReadsNone(GetInput{Name: "tree"}, Installed{Name: "tree"}, "name"), ). Example("A package that is not installed", DeleteInput{Name: "tree"}, Result{Name: "tree"}, behavior.ReadsNone(GetInput{Name: "tree"}, Installed{Name: "tree"}, "name"), ). Fails("A name that is an option", DeleteInput{Name: "-oAPT::Get=x"}, "not a valid package name"). Fails("A name longer than 255 characters", DeleteInput{Name: strings.Repeat("a", 256)}, "not a valid package name"), ))
Behavior is the packages installed on the host. gohai reads them on every platform; apt-get installs and removes them on the Debian family.
Functions ¶
This section is empty.
Types ¶
type CreateInput ¶
type CreateInput struct {
Name string `` /* 163-byte string literal not displayed */
Version string `` /* 146-byte string literal not displayed */
}
CreateInput is the package to install.
type DeleteInput ¶
type DeleteInput struct {
Name string `json:"name" validate:"required,max=255,package_name" doc:"The package to remove, such as curl"`
}
DeleteInput is the package to remove.
type GetInput ¶
type GetInput struct {
Name string `json:"name" validate:"required,max=255,package_name" doc:"The package, such as curl"`
}
GetInput names one installed package.
type Installed ¶
type Installed struct {
Name string `json:"name" doc:"The package"`
Version string `json:"version" doc:"The installed version"`
Architecture string `json:"architecture,omitempty" doc:"The architecture it is built for, such as amd64"`
Manager string `json:"manager" doc:"The package database that has it: dpkg, rpm or brew"`
Description string `json:"description,omitempty" doc:"Its one-line summary"`
Size int64 `json:"size,omitempty" doc:"Its installed size in bytes" render:"bytes"`
}
Installed is one installed package.
type Provider ¶
type Provider interface {
// List is every installed package.
List(ctx context.Context) ([]Installed, error)
// Get is one installed package, or behavior.ErrNotFound.
Get(ctx context.Context, name string) (Installed, error)
// Install installs a package, at version when it is not empty, and
// reports whether it changed the host.
Install(ctx context.Context, name string, version string) (bool, error)
// Remove removes a package, and reports whether it changed the host.
Remove(ctx context.Context, name string) (bool, error)
}
Provider reads the installed packages and installs and removes them.