Allow setting source
in config file (fixes #267)
This commit is contained in:
parent
4026276660
commit
aea85a1f40
@ -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
|
||||
}
|
||||
|
||||
|
@ -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("-", "_"))
|
||||
|
Loading…
x
Reference in New Issue
Block a user