Skip to content

Commit

Permalink
Merge branch 'master' into ignore-parse-errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wagoodman committed Mar 8, 2020
2 parents a9c2e48 + f9e29dc commit adc3e19
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ nfpms:
- license: MIT
maintainer: Alex Goodman
homepage: https://github.com/wagoodman/dive/
description: "A tool for exploring each layer in a docker image"
formats:
- rpm
- deb
Expand Down
9 changes: 5 additions & 4 deletions cmd/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"

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

Expand Down Expand Up @@ -47,13 +48,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
10 changes: 9 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ func initCli() {

// initConfig reads in config file and ENV variables if set.
func initConfig() {
var err error

viper.SetDefault("log.level", log.InfoLevel.String())
viper.SetDefault("log.path", "./dive.log")
viper.SetDefault("log.enabled", false)
Expand Down Expand Up @@ -102,6 +104,12 @@ func initConfig() {
viper.SetDefault("container-engine", "docker")
viper.SetDefault("ignore-errors", false)

err = viper.BindPFlag("source", rootCmd.PersistentFlags().Lookup("source"))
if err != nil {
fmt.Println(err)
os.Exit(1)
}

viper.SetEnvPrefix("DIVE")
// replace all - with _ when looking for matching environment variables
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
Expand All @@ -115,7 +123,7 @@ func initConfig() {
} else {
viper.SetConfigFile(cfgFile)
}
err := viper.ReadInConfig()
err = viper.ReadInConfig()
if err == nil {
fmt.Println("Using config file:", viper.ConfigFileUsed())
} else if cfgFile != "" {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ require (
github.com/wagoodman/keybinding v0.0.0-20181213133715-6a824da6df05
golang.org/x/crypto v0.0.0-20190907121410-71b5226ff739
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297
golang.org/x/sys v0.0.0-20190907184412-d223b2b6db03 // indirect
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 // indirect
golang.org/x/text v0.3.2 // indirect
google.golang.org/genproto v0.0.0-20190620144150-6af8c5fc6601 // indirect
google.golang.org/grpc v1.21.1 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190907184412-d223b2b6db03 h1:b3JiLYVaG9kHjTcOQIoUh978YMCO7oVTQQBLudU47zY=
golang.org/x/sys v0.0.0-20190907184412-d223b2b6db03/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4 h1:sfkvUWPNGwSV+8/fNqctR5lS2AqCSqYwXdrjCxp/dXo=
golang.org/x/sys v0.0.0-20200212091648-12a6c2dcc1e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
Expand Down

0 comments on commit adc3e19

Please sign in to comment.