main: show output directory content after image build

This commit adds the content of the output directory when a
build is finished. This is a convenient feature to make it easier
for the users.

Thanks to Simon for suggesting this!
This commit is contained in:
Michael Vogt 2025-03-20 12:06:54 +01:00 committed by Simon de Vlieger
parent 2895e71064
commit d4c31389a9
2 changed files with 18 additions and 2 deletions

View file

@ -7,6 +7,8 @@ import (
"io"
"os"
"os/signal"
"path/filepath"
"strings"
"syscall"
"github.com/sirupsen/logrus"
@ -211,6 +213,17 @@ func progressFromCmd(cmd *cobra.Command) (progress.ProgressBar, error) {
return progress.New(progressType)
}
// listOutputdir will return a string with the output dir content.
// Any errors will also just appear as part of the string (as it is
// purely informational)
func listOutputdir(path string) string {
ents, err := filepath.Glob(filepath.Join(path, "/*"))
if err != nil {
return fmt.Sprintf("error: %v", err)
}
return strings.Join(ents, ",")
}
func cmdBuild(cmd *cobra.Command, args []string) error {
cacheDir, err := cmd.Flags().GetString("cache")
if err != nil {
@ -286,7 +299,8 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
return err
}
pbar.Stop()
fmt.Fprintf(osStdout, "Image build successful, result in %q\n", outputDir)
fmt.Fprintf(osStdout, "Image build successful, results:\n%s\n", listOutputdir(outputDir))
if uploader != nil {
// XXX: integrate better into the progress, see bib

View file

@ -391,7 +391,9 @@ func TestBuildIntegrationHappy(t *testing.T) {
})
assert.NoError(t, err)
assert.Contains(t, fakeStdout.String(), `Image build successful, result in "centos-9-qcow2-x86_64"`+"\n")
assert.Contains(t, fakeStdout.String(), `Image build successful, results:
centos-9-qcow2-x86_64/centos-9-qcow2-x86_64.qcow2
`)
// ensure osbuild was run exactly one
require.Equal(t, 1, len(fakeOsbuildCmd.Calls()))