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:
Michael Vogt 2025-02-05 09:42:27 +01:00 committed by Ondřej Budai
parent 8b09755cab
commit 7c6db68c98
3 changed files with 52 additions and 10 deletions

View file

@ -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)