Skip to content

Commit

Permalink
Allow setting source in config file (fixes #267)
Browse files Browse the repository at this point in the history
  • Loading branch information
abitrolly committed Feb 22, 2020
1 parent 4026276 commit aea85a1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/wagoodman/dive/runtime"
)

Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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("-", "_"))
Expand Down

0 comments on commit aea85a1

Please sign in to comment.