| 1 | package cliscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/ |
| 2 | |
| 3 | import ( |
| 4 | "errorsscip-go gomod github.com/golang/go/src go1.25 errors/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src go1.25 fmt/" |
| 6 | "ioscip-go gomod github.com/golang/go/src go1.25 io/" |
| 7 | "osscip-go gomod github.com/golang/go/src go1.25 os/" |
| 8 | "os/userscip-go gomod github.com/golang/go/src go1.25 `os/user`/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src go1.25 strings/" |
| 10 | |
| 11 | "go.yaml.in/yaml/v4scip-go gomod go.yaml.in/yaml/v4 v4.0.0-rc.3 `go.yaml.in/yaml/v4`/" |
| 12 | ) |
| 13 | |
| 14 | // Config holds the contents of a config file. |
| 15 | type Configscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Config# struct { |
| 16 | DefaultFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Config#DefaultFormat. string `yaml:"default_format"` |
| 17 | } |
| 18 | |
| 19 | var cfgscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfg. = Configscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Config#{ |
| 20 | DefaultFormatscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Config#DefaultFormat.: "json", |
| 21 | } |
| 22 | var cfgLoadedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfgLoaded. = false |
| 23 | |
| 24 | // LoadConfig loads the config from the given path. |
| 25 | // If already loaded, returned previously loaded config. |
| 26 | func LoadConfigscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/LoadConfig().(path string) (Configscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/Config#, error) { |
| 27 | if cfgLoadedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfgLoaded. { |
| 28 | return cfgscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfg., nil |
| 29 | } |
| 30 | |
| 31 | if stringsscip-go gomod github.com/golang/go/src go1.25 strings/.HasPrefixscip-go gomod github.com/golang/go/src go1.25 strings/HasPrefix().(path, "~/") { |
| 32 | usr, err := userscip-go gomod github.com/golang/go/src go1.25 `os/user`/.Currentscip-go gomod github.com/golang/go/src go1.25 `os/user`/Current().() |
| 33 | if err != nil { |
| 34 | return cfgscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfg., fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error getting current user: %v", err) |
| 35 | } |
| 36 | path = usr.HomeDirscip-go gomod github.com/golang/go/src go1.25 `os/user`/User#HomeDir. + path[1:] |
| 37 | } |
| 38 | |
| 39 | f, err := osscip-go gomod github.com/golang/go/src go1.25 os/.Openscip-go gomod github.com/golang/go/src go1.25 os/Open().(path) |
| 40 | if errorsscip-go gomod github.com/golang/go/src go1.25 errors/.Isscip-go gomod github.com/golang/go/src go1.25 errors/Is().(err, osscip-go gomod github.com/golang/go/src go1.25 os/.ErrNotExistscip-go gomod github.com/golang/go/src go1.25 os/ErrNotExist.) { |
| 41 | cfgLoadedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfgLoaded. = true |
| 42 | return cfgscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfg., nil |
| 43 | } |
| 44 | if err != nil { |
| 45 | return cfgscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfg., fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error opening config file at path %q: %w", path, err) |
| 46 | } |
| 47 | defer func() { |
| 48 | _ = f.Closescip-go gomod github.com/golang/go/src go1.25 os/File#Close().() |
| 49 | }() |
| 50 | decoder := yamlscip-go gomod go.yaml.in/yaml/v4 v4.0.0-rc.3 `go.yaml.in/yaml/v4`/.NewDecoderscip-go gomod go.yaml.in/yaml/v4 v4.0.0-rc.3 `go.yaml.in/yaml/v4`/NewDecoder().(f) |
| 51 | err = decoder.Decodescip-go gomod go.yaml.in/yaml/v4 v4.0.0-rc.3 `go.yaml.in/yaml/v4`/Decoder#Decode().(&cfgscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfg.) |
| 52 | if err != nil && !errorsscip-go gomod github.com/golang/go/src go1.25 errors/.Isscip-go gomod github.com/golang/go/src go1.25 errors/Is().(err, ioscip-go gomod github.com/golang/go/src go1.25 io/.EOFscip-go gomod github.com/golang/go/src go1.25 io/EOF.) { |
| 53 | return cfgscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfg., fmtscip-go gomod github.com/golang/go/src go1.25 fmt/.Errorfscip-go gomod github.com/golang/go/src go1.25 fmt/Errorf().("error parsing config file: %w", err) |
| 54 | } |
| 55 | cfgLoadedscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfgLoaded. = true |
| 56 | return cfgscip-go gomod github.com/tomwright/dasel/v3 . `github.com/tomwright/dasel/v3/internal/cli`/cfg., nil |
| 57 | } |