main: add -v,--verbose switch that enables verbose build logging
This commit adds a new `-v,--verbose` switch that enables verbose build logging. Closes: https://github.com/osbuild/image-builder-cli/issues/112
This commit is contained in:
parent
8b09755cab
commit
7c6db68c98
3 changed files with 52 additions and 10 deletions
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -157,6 +157,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 {
|
||||
|
|
@ -166,16 +182,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
|
||||
}
|
||||
|
|
@ -256,6 +267,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)
|
||||
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
@ -567,3 +569,30 @@ func TestDescribeImageSmoke(t *testing.T) {
|
|||
type: qcow2
|
||||
arch: x86_64`)
|
||||
}
|
||||
|
||||
func TestProgressFromCmd(t *testing.T) {
|
||||
cmd := &cobra.Command{}
|
||||
cmd.Flags().String("progress", "auto", "")
|
||||
cmd.Flags().Bool("verbose", false, "")
|
||||
|
||||
for _, tc := range []struct {
|
||||
progress string
|
||||
verbose bool
|
||||
// XXX: progress should just export the types, then
|
||||
// this would be a bit nicer
|
||||
expectedProgress string
|
||||
}{
|
||||
// we cannto test the "auto/false" case because it
|
||||
// depends on if there is a terminal attached or not
|
||||
//{"auto", false, "*progress.terminalProgressBar"},
|
||||
{"auto", true, "*progress.verboseProgressBar"},
|
||||
{"term", false, "*progress.terminalProgressBar"},
|
||||
{"term", true, "*progress.terminalProgressBar"},
|
||||
} {
|
||||
cmd.Flags().Set("progress", tc.progress)
|
||||
cmd.Flags().Set("verbose", fmt.Sprintf("%v", tc.verbose))
|
||||
pbar, err := main.ProgressFromCmd(cmd)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, tc.expectedProgress, fmt.Sprintf("%T", pbar))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue