diff --git a/cmd/analyze.go b/cmd/analyze.go index 0a594422..e6d7e8cc 100644 --- a/cmd/analyze.go +++ b/cmd/analyze.go @@ -6,6 +6,7 @@ import ( "os" "github.com/spf13/cobra" + "github.com/spf13/viper" "github.com/wagoodman/dive/runtime" ) @@ -45,13 +46,13 @@ func doAnalyzeCmd(cmd *cobra.Command, args []string) { sourceType, imageStr = dive.DeriveImageSource(userImage) if sourceType == dive.SourceUnknown { - sourceStr, err := cmd.PersistentFlags().GetString("source") - if err != nil { - fmt.Printf("unable to determine image source: %v\n", err) + sourceStr := viper.GetString("source") + sourceType = dive.ParseImageSource(sourceStr) + if sourceType == dive.SourceUnknown { + fmt.Printf("unable to determine image source: %v\n", sourceStr) os.Exit(1) } - sourceType = dive.ParseImageSource(sourceStr) imageStr = userImage } diff --git a/cmd/root.go b/cmd/root.go index cdbc60fe..3ce286a9 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -97,6 +97,8 @@ func initConfig() { viper.SetDefault("container-engine", "docker") + viper.BindPFlag("source", rootCmd.PersistentFlags().Lookup("source")) + viper.SetEnvPrefix("DIVE") // replace all - with _ when looking for matching environment variables viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))