This commit adds a new `describe-image` comamnd that contains
the details about the given image type. The output is yaml as
it is both nicely human readable and also machine readable.
Note that this version carries an invalid yaml header on
purpose to avoid people replying on the feature for scripts
before it is stable.
The output looks like this:
```yaml
$ ./image-builder describe-image rhel-9.1 tar
@WARNING - the output format is not stable yet and may change
distro: rhel-9.1
type: tar
arch: x86_64
os_vesion: "9.1"
bootmode: none
partition_type: ""
default_filename: root.tar.xz
packages:
include:
- policycoreutils
- selinux-policy-targeted
- selinux-policy-targeted
exclude:
- rng-tools
```
Thanks to Ondrej Budai for the idea and the example.
61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/osbuild/images/pkg/reporegistry"
|
|
)
|
|
|
|
var (
|
|
GetOneImage = getOneImage
|
|
Run = run
|
|
FindDistro = findDistro
|
|
DescribeImage = describeImage
|
|
)
|
|
|
|
func MockOsArgs(new []string) (restore func()) {
|
|
saved := os.Args
|
|
os.Args = append([]string{"argv0"}, new...)
|
|
return func() {
|
|
os.Args = saved
|
|
}
|
|
}
|
|
|
|
func MockOsStdout(new io.Writer) (restore func()) {
|
|
saved := osStdout
|
|
osStdout = new
|
|
return func() {
|
|
osStdout = saved
|
|
}
|
|
}
|
|
|
|
func MockOsStderr(new io.Writer) (restore func()) {
|
|
saved := osStderr
|
|
osStderr = new
|
|
return func() {
|
|
osStderr = saved
|
|
}
|
|
}
|
|
|
|
func MockNewRepoRegistry(f func() (*reporegistry.RepoRegistry, error)) (restore func()) {
|
|
saved := newRepoRegistry
|
|
newRepoRegistry = func(dataDir string) (*reporegistry.RepoRegistry, error) {
|
|
if dataDir != "" {
|
|
panic(fmt.Sprintf("cannot use custom dataDir %v in mock", dataDir))
|
|
}
|
|
return f()
|
|
}
|
|
return func() {
|
|
newRepoRegistry = saved
|
|
}
|
|
}
|
|
|
|
func MockDistroGetHostDistroName(f func() (string, error)) (restore func()) {
|
|
saved := distroGetHostDistroName
|
|
distroGetHostDistroName = f
|
|
return func() {
|
|
distroGetHostDistroName = saved
|
|
}
|
|
}
|