79 lines
2.5 KiB
Markdown
Raw Permalink Normal View History

2025-01-03 23:30:07 -06:00
---
title: "Packages"
weight: 2
description: This is dedicated to package commands.
2025-01-03 23:30:07 -06:00
---
This is dedicated to `package` commands. The command `type` field must be `package`. Package is a type that allows one to perform package operations. There are several additional options available when `type` is `package`:
| name | notes | type | required |
| --- | --- | --- | --- |
| `packageName` | The name of a package to be modified. | `string` | yes |
| `packageManager` | The name of the package manger to be used. | `string` | yes |
2025-02-08 15:17:34 -06:00
| `packageOperation` | The type of operation to perform. | `string` | yes |
| `packageVersion` | The version of a package. | `string` | no |
2025-01-03 23:30:07 -06:00
#### example
The following is an example of a package command:
```yaml
update-docker:
type: package
shell: zsh
packageName: docker-ce
packageManager: apt
packageOperation: install
host: debian-based-host
```
#### packageOperation
The following package operations are supported:
- `install`
- `remove`
- `upgrade`
2025-02-08 15:17:34 -06:00
- `checkVersion`
2025-01-03 23:30:07 -06:00
#### packageManager
The following package managers are recognized:
- `apt`
- `yum`
- `dnf`
#### package command args
2025-02-08 15:17:34 -06:00
You can add additional arguments using the standard `Args` key. This is useful for adding more packages, yet it does not work with `checkVersion`.
2025-01-03 23:30:07 -06:00
### Development
2025-02-08 15:17:34 -06:00
The PackageManager interface provides an easy way to enforce functions and options. There are two interfaces, `PackageManager` and `ConfigurablePackageManager` in the directory `pkg/pkgman`. Go's import-cycle "feature" caused me to implement functional options using a third interface. `PackageManagerOption`is a function that takes an interface.
2025-01-03 23:30:07 -06:00
#### PackageManager
```go
// PackageManager is an interface used to define common package commands. This shall be implemented by every package.
type PackageManager interface {
Install(pkg, version string, args []string) (string, []string)
Remove(pkg string, args []string) (string, []string)
Upgrade(pkg, version string) (string, []string) // Upgrade a specific package
UpgradeAll() (string, []string)
// Configure applies functional options to customize the package manager.
Configure(options ...pkgcommon.PackageManagerOption)
}
```
There are a few functional options that should be implemented using the `ConfigurablePackageManager` interface:
```go
// ConfigurablePackageManager defines methods for setting configuration options.
type ConfigurablePackageManager interface {
SetUseAuth(useAuth bool)
SetAuthCommand(authCommand string)
}
```