Skip to content

Commit

Permalink
main: add -v,--verbose switch that enables verbose build logging
Browse files Browse the repository at this point in the history
This commit adds a new `-v,--verbose` switch that enables verbose
build logging.

Closes: osbuild#112
  • Loading branch information
mvo5 committed Feb 5, 2025
1 parent fdab539 commit ee01739
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
9 changes: 5 additions & 4 deletions cmd/image-builder/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import (
)

var (
GetOneImage = getOneImage
Run = run
FindDistro = findDistro
DescribeImage = describeImage
GetOneImage = getOneImage
Run = run
FindDistro = findDistro
DescribeImage = describeImage
ProgressFromCmd = progressFromCmd
)

func MockOsArgs(new []string) (restore func()) {
Expand Down
24 changes: 18 additions & 6 deletions cmd/image-builder/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,22 @@ func cmdManifest(cmd *cobra.Command, args []string) error {
return err
}

func progressFromCmd(cmd *cobra.Command) (progress.ProgressBar, error) {
progressType, err := cmd.Flags().GetString("progress")
if err != nil {
return nil, err
}
verbose, err := cmd.Flags().GetBool("verbose")
if err != nil {
return nil, err
}
if progressType == "auto" && verbose {
progressType = "verbose"
}

return progress.New(progressType)
}

func cmdBuild(cmd *cobra.Command, args []string) error {
cacheDir, err := cmd.Flags().GetString("cache")
if err != nil {
Expand All @@ -165,16 +181,11 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
progressType, err := cmd.Flags().GetString("progress")
if err != nil {
return err
}
withManifest, err := cmd.Flags().GetBool("with-manifest")
if err != nil {
return err
}

pbar, err := progress.New(progressType)
pbar, err := progressFromCmd(cmd)
if err != nil {
return err
}
Expand Down Expand Up @@ -249,6 +260,7 @@ operating systems like Fedora, CentOS and RHEL with easy customizations support.
}
rootCmd.PersistentFlags().String("datadir", "", `Override the default data directory for e.g. custom repositories/*.json data`)
rootCmd.PersistentFlags().String("output-dir", "", `Put output into the specified directory`)
rootCmd.PersistentFlags().BoolP("verbose", "v", false, `Switch to verbose mode`)
rootCmd.SetOut(osStdout)
rootCmd.SetErr(osStderr)

Expand Down
16 changes: 16 additions & 0 deletions cmd/image-builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ import (
"testing"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"

//"github.com/osbuild/bootc-image-builder/bib/pkg/progress"
testrepos "github.com/osbuild/images/test/data/repositories"

main "github.com/osbuild/image-builder-cli/cmd/image-builder"
Expand Down Expand Up @@ -567,3 +569,17 @@ func TestDescribeImageSmoke(t *testing.T) {
type: qcow2
arch: x86_64`)
}

type testCmd struct{}

func TestProgressFromCmd(t *testing.T) {
cmd := &cobra.Command{}
cmd.Flags().String("progress", "", "")
cmd.Flags().Bool("verbose", false, "")

pbar, err := main.ProgressFromCmd(cmd)
assert.NoError(t, err)
// XXX: progress should just export the types, then this would be
// a bit nicer
assert.Equal(t, "*progress.verboseProgressBar", fmt.Sprintf("%T", pbar))
}

0 comments on commit ee01739

Please sign in to comment.