switch to yaml fork so that we can view omitEmpty yaml fields when printing the config

pull/10/head
Jesse Duffield 5 years ago
parent f3491cf13f
commit 2ef5edcf89

18
Gopkg.lock generated

@ -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

@ -44,3 +44,7 @@
[[constraint]]
branch = "master"
name = "github.com/jesseduffield/asciigraph"
[[constraint]]
branch = "v2"
name = "github.com/jesseduffield/yaml"

@ -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 (

@ -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.

@ -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")

@ -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))

@ -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) {

@ -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,
}
}
Loading…
Cancel
Save