Allow setting source
in config file (fixes #267)
This commit is contained in:
parent
4026276660
commit
aea85a1f40
@ -6,6 +6,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
"github.com/spf13/viper"
|
||||||
"github.com/wagoodman/dive/runtime"
|
"github.com/wagoodman/dive/runtime"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -45,13 +46,13 @@ func doAnalyzeCmd(cmd *cobra.Command, args []string) {
|
|||||||
sourceType, imageStr = dive.DeriveImageSource(userImage)
|
sourceType, imageStr = dive.DeriveImageSource(userImage)
|
||||||
|
|
||||||
if sourceType == dive.SourceUnknown {
|
if sourceType == dive.SourceUnknown {
|
||||||
sourceStr, err := cmd.PersistentFlags().GetString("source")
|
sourceStr := viper.GetString("source")
|
||||||
if err != nil {
|
sourceType = dive.ParseImageSource(sourceStr)
|
||||||
fmt.Printf("unable to determine image source: %v\n", err)
|
if sourceType == dive.SourceUnknown {
|
||||||
|
fmt.Printf("unable to determine image source: %v\n", sourceStr)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceType = dive.ParseImageSource(sourceStr)
|
|
||||||
imageStr = userImage
|
imageStr = userImage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +97,8 @@ func initConfig() {
|
|||||||
|
|
||||||
viper.SetDefault("container-engine", "docker")
|
viper.SetDefault("container-engine", "docker")
|
||||||
|
|
||||||
|
viper.BindPFlag("source", rootCmd.PersistentFlags().Lookup("source"))
|
||||||
|
|
||||||
viper.SetEnvPrefix("DIVE")
|
viper.SetEnvPrefix("DIVE")
|
||||||
// replace all - with _ when looking for matching environment variables
|
// replace all - with _ when looking for matching environment variables
|
||||||
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user