This commit tweaks the argument handling based on the suggestion by Achilleas and Ondrej (thanks!). Now it takes ```console $ image-builder manifest qcow2 ./path/to/blueprint ... $ image-builder manifest --arch s390x --distro centos-9 qcow2 ... ``` If no arch is specified the hostname arch is used. If no distro is specified in either the blueprint or the commandline it is auto-detected based on the host. Note that if the distro from the comandline and the blueprint diverge an error is raised. We can relax this rule and just add precedence, e.g. commandline always overrides the blueprint but ideally we would have a clear use-case here so we start conservative and can always relax this rule later (the inverse is much harder). This means it is no longer copy/paste friendly from `list-images` by default but instead we can provide a new `list-images --output=shell` option that outputs in exactly the format that `image-builder [manifest|build]` need.
30 lines
1 KiB
Go
30 lines
1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/osbuild/images/pkg/distro"
|
|
)
|
|
|
|
var distroGetHostDistroName = distro.GetHostDistroName
|
|
|
|
// findDistro will ensure that the given distro argument do not
|
|
// diverge. If no distro is set via the blueprint or the argument
|
|
// the host is used to derive the distro.
|
|
func findDistro(argDistroName, bpDistroName string) (string, error) {
|
|
switch {
|
|
case argDistroName != "" && bpDistroName != "" && argDistroName != bpDistroName:
|
|
return "", fmt.Errorf("error selecting distro name, cmdline argument %q is different from blueprint %q", argDistroName, bpDistroName)
|
|
case argDistroName != "":
|
|
return argDistroName, nil
|
|
case bpDistroName != "":
|
|
return bpDistroName, nil
|
|
}
|
|
// nothing selected by the user, derive from host
|
|
distroStr, err := distroGetHostDistroName()
|
|
if err != nil {
|
|
return "", fmt.Errorf("error deriving host distro %w", err)
|
|
}
|
|
fmt.Fprintf(osStderr, "No distro name specified, selecting %q based on host, use --distro to override", distroStr)
|
|
return distroStr, nil
|
|
}
|