diff --git a/Gopkg.lock b/Gopkg.lock index 1a95b06e..1aa0f2ac 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -153,6 +153,14 @@ pruneopts = "NUT" revision = "1e272ff78dcb4c448870f464fda1cdcf2bf0b3dd" +[[projects]] + branch = "v2" + digest = "1:39964c6cc97fae9e81e3f87ffdcacac8e8a8dfb44be532bb9909ff558e8914e5" + name = "github.com/jesseduffield/yaml" + packages = ["."] + pruneopts = "NUT" + revision = "9e6ca978307a1aeaf98218b1880a441af4a57294" + [[projects]] digest = "1:08c231ec84231a7e23d67e4b58f975e1423695a32467a362ee55a803f9de8061" name = "github.com/mattn/go-colorable" @@ -307,14 +315,6 @@ pruneopts = "NUT" revision = "3ee3066db522c6628d440a3a91c4abdd7f5ef22f" -[[projects]] - digest = "1:7c95b35057a0ff2e19f707173cc1a947fa43a6eb5c4d300d196ece0334046082" - name = "gopkg.in/yaml.v2" - packages = ["."] - pruneopts = "NUT" - revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" - version = "v2.2.1" - [solve-meta] analyzer-name = "dep" analyzer-version = 1 @@ -331,6 +331,7 @@ "github.com/jesseduffield/asciigraph", "github.com/jesseduffield/gocui", "github.com/jesseduffield/pty", + "github.com/jesseduffield/yaml", "github.com/mcuadros/go-lookup", "github.com/mgutz/str", "github.com/shibukawa/configdir", @@ -339,7 +340,6 @@ "github.com/stretchr/testify/assert", "github.com/tcnksm/go-gitconfig", "golang.org/x/xerrors", - "gopkg.in/yaml.v2", ] solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 15b214d7..683fce3d 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -44,3 +44,7 @@ [[constraint]] branch = "master" name = "github.com/jesseduffield/asciigraph" + +[[constraint]] + branch = "v2" + name = "github.com/jesseduffield/yaml" diff --git a/main.go b/main.go index afd3bb28..ad02e85f 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,7 @@ import ( "github.com/go-errors/errors" "github.com/jesseduffield/lazydocker/pkg/app" "github.com/jesseduffield/lazydocker/pkg/config" - "gopkg.in/yaml.v2" + "github.com/jesseduffield/yaml" ) var ( diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index da5e0765..530aaab5 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -6,8 +6,8 @@ import ( "path/filepath" "time" + yaml "github.com/jesseduffield/yaml" "github.com/shibukawa/configdir" - yaml "gopkg.in/yaml.v2" ) // AppConfig contains the base configuration fields required for lazygit. diff --git a/pkg/gui/status_panel.go b/pkg/gui/status_panel.go index b0ebceaa..a959c90d 100644 --- a/pkg/gui/status_panel.go +++ b/pkg/gui/status_panel.go @@ -10,7 +10,7 @@ import ( "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazydocker/pkg/commands" "github.com/jesseduffield/lazydocker/pkg/utils" - "gopkg.in/yaml.v2" + "github.com/jesseduffield/yaml" ) func (gui *Gui) getStatusContexts() []string { @@ -86,7 +86,7 @@ func (gui *Gui) renderCredits() error { mainView.Wrap = true var configBuf bytes.Buffer - yaml.NewEncoder(&configBuf).Encode(gui.Config.UserConfig) + yaml.NewEncoder(&configBuf, yaml.IncludeOmitted).Encode(gui.Config.UserConfig) dashboardString := strings.Join( []string{ @@ -96,7 +96,7 @@ func (gui *Gui) renderCredits() error { "Config Options: https://github.com/jesseduffield/lazydocker/blob/master/docs/Config.md", "Raise an Issue: https://github.com/jesseduffield/lazydocker/issues", utils.ColoredString("Buy Jesse a coffee: https://donorbox.org/lazydocker", color.FgMagenta), // caffeine ain't free - "Here's what you lazydocker config is when merged with the defaults (you can open your config by pressing 'o'):", + "Here's your lazydocker config when merged in with the defaults (you can open your config by pressing 'o'):", configBuf.String(), }, "\n\n") diff --git a/vendor/gopkg.in/yaml.v2/LICENSE b/vendor/github.com/jesseduffield/yaml/LICENSE similarity index 100% rename from vendor/gopkg.in/yaml.v2/LICENSE rename to vendor/github.com/jesseduffield/yaml/LICENSE diff --git a/vendor/gopkg.in/yaml.v2/LICENSE.libyaml b/vendor/github.com/jesseduffield/yaml/LICENSE.libyaml similarity index 100% rename from vendor/gopkg.in/yaml.v2/LICENSE.libyaml rename to vendor/github.com/jesseduffield/yaml/LICENSE.libyaml diff --git a/vendor/gopkg.in/yaml.v2/NOTICE b/vendor/github.com/jesseduffield/yaml/NOTICE similarity index 100% rename from vendor/gopkg.in/yaml.v2/NOTICE rename to vendor/github.com/jesseduffield/yaml/NOTICE diff --git a/vendor/gopkg.in/yaml.v2/apic.go b/vendor/github.com/jesseduffield/yaml/apic.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/apic.go rename to vendor/github.com/jesseduffield/yaml/apic.go diff --git a/vendor/gopkg.in/yaml.v2/decode.go b/vendor/github.com/jesseduffield/yaml/decode.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/decode.go rename to vendor/github.com/jesseduffield/yaml/decode.go diff --git a/vendor/gopkg.in/yaml.v2/emitterc.go b/vendor/github.com/jesseduffield/yaml/emitterc.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/emitterc.go rename to vendor/github.com/jesseduffield/yaml/emitterc.go diff --git a/vendor/gopkg.in/yaml.v2/encode.go b/vendor/github.com/jesseduffield/yaml/encode.go similarity index 88% rename from vendor/gopkg.in/yaml.v2/encode.go rename to vendor/github.com/jesseduffield/yaml/encode.go index a14435e8..94158b33 100644 --- a/vendor/gopkg.in/yaml.v2/encode.go +++ b/vendor/github.com/jesseduffield/yaml/encode.go @@ -13,6 +13,19 @@ import ( "unicode/utf8" ) +// jsonNumber is the interface of the encoding/json.Number datatype. +// Repeating the interface here avoids a dependency on encoding/json, and also +// supports other libraries like jsoniter, which use a similar datatype with +// the same interface. Detecting this interface is useful when dealing with +// structures containing json.Number, which is a string under the hood. The +// encoder should prefer the use of Int64(), Float64() and string(), in that +// order, when encoding this type. +type jsonNumber interface { + Float64() (float64, error) + Int64() (int64, error) + String() string +} + type encoder struct { emitter yaml_emitter_t event yaml_event_t @@ -21,6 +34,9 @@ type encoder struct { // doneInit holds whether the initial stream_start_event has been // emitted. doneInit bool + + // includOmitted tells us whether we want to include fields that were marked as 'omitEmpty' + includeOmitted bool } func newEncoder() *encoder { @@ -89,6 +105,21 @@ func (e *encoder) marshal(tag string, in reflect.Value) { } iface := in.Interface() switch m := iface.(type) { + case jsonNumber: + integer, err := m.Int64() + if err == nil { + // In this case the json.Number is a valid int64 + in = reflect.ValueOf(integer) + break + } + float, err := m.Float64() + if err == nil { + // In this case the json.Number is a valid float64 + in = reflect.ValueOf(float) + break + } + // fallback case - no number could be obtained + in = reflect.ValueOf(m.String()) case time.Time, *time.Time: // Although time.Time implements TextMarshaler, // we don't want to treat it as a string for YAML @@ -190,7 +221,7 @@ func (e *encoder) structv(tag string, in reflect.Value) { } else { value = in.FieldByIndex(info.Inline) } - if info.OmitEmpty && isZero(value) { + if info.OmitEmpty && isZero(value) && !e.includeOmitted { continue } e.marshal("", reflect.ValueOf(info.Key)) diff --git a/vendor/gopkg.in/yaml.v2/parserc.go b/vendor/github.com/jesseduffield/yaml/parserc.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/parserc.go rename to vendor/github.com/jesseduffield/yaml/parserc.go diff --git a/vendor/gopkg.in/yaml.v2/readerc.go b/vendor/github.com/jesseduffield/yaml/readerc.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/readerc.go rename to vendor/github.com/jesseduffield/yaml/readerc.go diff --git a/vendor/gopkg.in/yaml.v2/resolve.go b/vendor/github.com/jesseduffield/yaml/resolve.go similarity index 98% rename from vendor/gopkg.in/yaml.v2/resolve.go rename to vendor/github.com/jesseduffield/yaml/resolve.go index 6c151db6..4120e0c9 100644 --- a/vendor/gopkg.in/yaml.v2/resolve.go +++ b/vendor/github.com/jesseduffield/yaml/resolve.go @@ -81,7 +81,7 @@ func resolvableTag(tag string) bool { return false } -var yamlStyleFloat = regexp.MustCompile(`^[-+]?[0-9]*\.?[0-9]+([eE][-+][0-9]+)?$`) +var yamlStyleFloat = regexp.MustCompile(`^[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?$`) func resolve(tag string, in string) (rtag string, out interface{}) { if !resolvableTag(tag) { diff --git a/vendor/gopkg.in/yaml.v2/scannerc.go b/vendor/github.com/jesseduffield/yaml/scannerc.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/scannerc.go rename to vendor/github.com/jesseduffield/yaml/scannerc.go diff --git a/vendor/gopkg.in/yaml.v2/sorter.go b/vendor/github.com/jesseduffield/yaml/sorter.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/sorter.go rename to vendor/github.com/jesseduffield/yaml/sorter.go diff --git a/vendor/gopkg.in/yaml.v2/writerc.go b/vendor/github.com/jesseduffield/yaml/writerc.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/writerc.go rename to vendor/github.com/jesseduffield/yaml/writerc.go diff --git a/vendor/gopkg.in/yaml.v2/yaml.go b/vendor/github.com/jesseduffield/yaml/yaml.go similarity index 96% rename from vendor/gopkg.in/yaml.v2/yaml.go rename to vendor/github.com/jesseduffield/yaml/yaml.go index de85aa4c..5635f0f2 100644 --- a/vendor/gopkg.in/yaml.v2/yaml.go +++ b/vendor/github.com/jesseduffield/yaml/yaml.go @@ -211,12 +211,26 @@ type Encoder struct { encoder *encoder } +// EncoderOption is an option for construcing an encoder +type EncoderOption func(*encoder) + +// IncludeOmitted is for when we want to encode a struct but including fields that were marked to be omitted +func IncludeOmitted(e *encoder) { + e.includeOmitted = true +} + // NewEncoder returns a new encoder that writes to w. // The Encoder should be closed after use to flush all data // to w. -func NewEncoder(w io.Writer) *Encoder { +func NewEncoder(w io.Writer, opts ...EncoderOption) *Encoder { + encoder := newEncoderWithWriter(w) + + for _, opt := range opts { + opt(encoder) + } + return &Encoder{ - encoder: newEncoderWithWriter(w), + encoder: encoder, } } diff --git a/vendor/gopkg.in/yaml.v2/yamlh.go b/vendor/github.com/jesseduffield/yaml/yamlh.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/yamlh.go rename to vendor/github.com/jesseduffield/yaml/yamlh.go diff --git a/vendor/gopkg.in/yaml.v2/yamlprivateh.go b/vendor/github.com/jesseduffield/yaml/yamlprivateh.go similarity index 100% rename from vendor/gopkg.in/yaml.v2/yamlprivateh.go rename to vendor/github.com/jesseduffield/yaml/yamlprivateh.go