mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-24 19:10:40 +00:00
format should write zero value of bool
This commit is contained in:
parent
ad8ad9816f
commit
be6b37e0b4
@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
## Unreleased
|
||||
### Added
|
||||
- format should write zero value of boolean in settings, by [@bradrydzewski](https://github.com/bradrydzewski).
|
||||
- Support for windows server 1903, by [@bradrydzewski](https://github.com/bradrydzewski).
|
||||
|
||||
## [1.2.2] - 2019-07-29
|
||||
|
@ -159,7 +159,7 @@ func printPorts(w writer, v []*yaml.Port) {
|
||||
}
|
||||
}
|
||||
|
||||
// helper function pretty prints the resoure mapping.
|
||||
// helper function pretty prints the resource mapping.
|
||||
func printResources(w writer, v *yaml.Resources) {
|
||||
w.WriteTag("resources")
|
||||
w.IndentIncrease()
|
||||
@ -194,7 +194,9 @@ func printSettings(w writer, v map[string]*yaml.Parameter) {
|
||||
for _, k := range keys {
|
||||
v := v[k]
|
||||
if v.Secret == "" {
|
||||
w.IncludeZero()
|
||||
w.WriteTagValue(k, v.Value)
|
||||
w.ExcludeZero()
|
||||
} else {
|
||||
w.WriteTag(k)
|
||||
w.IndentIncrease()
|
||||
|
1
yaml/pretty/testdata/pipeline_settings.yml
vendored
1
yaml/pretty/testdata/pipeline_settings.yml
vendored
@ -8,6 +8,7 @@ steps:
|
||||
token:
|
||||
from_secret: token
|
||||
root: general
|
||||
dry_run: false
|
||||
labels:
|
||||
- foo
|
||||
- bar
|
||||
|
@ -10,6 +10,7 @@ steps:
|
||||
- name: notify
|
||||
image: plugins/slack
|
||||
settings:
|
||||
dry_run: false
|
||||
labels:
|
||||
- foo
|
||||
- bar
|
||||
|
@ -42,12 +42,18 @@ type writer interface {
|
||||
// Indent appends padding to the buffer.
|
||||
Indent()
|
||||
|
||||
// IndentIncrease inreases indentation.
|
||||
// IndentIncrease increases indentation.
|
||||
IndentIncrease()
|
||||
|
||||
// IndentDecrese decreases indentation.
|
||||
// IndentDecrease decreases indentation.
|
||||
IndentDecrease()
|
||||
|
||||
// IncludeZero includes zero value values
|
||||
IncludeZero()
|
||||
|
||||
// ExcludeZero excludes zero value values.
|
||||
ExcludeZero()
|
||||
|
||||
// Write appends the contents of p to the buffer.
|
||||
Write(p []byte) (n int, err error)
|
||||
|
||||
@ -71,6 +77,7 @@ type writer interface {
|
||||
type baseWriter struct {
|
||||
bytes.Buffer
|
||||
depth int
|
||||
zero bool
|
||||
}
|
||||
|
||||
func (w *baseWriter) Indent() {
|
||||
@ -87,6 +94,14 @@ func (w *baseWriter) IndentDecrease() {
|
||||
w.depth--
|
||||
}
|
||||
|
||||
func (w *baseWriter) IncludeZero() {
|
||||
w.zero = true
|
||||
}
|
||||
|
||||
func (w *baseWriter) ExcludeZero() {
|
||||
w.zero = false
|
||||
}
|
||||
|
||||
func (w *baseWriter) WriteTag(v interface{}) {
|
||||
w.WriteByte('\n')
|
||||
w.Indent()
|
||||
@ -95,7 +110,7 @@ func (w *baseWriter) WriteTag(v interface{}) {
|
||||
}
|
||||
|
||||
func (w *baseWriter) WriteTagValue(k, v interface{}) {
|
||||
if isZero(v) {
|
||||
if isZero(v) && w.zero == false {
|
||||
return
|
||||
}
|
||||
w.WriteTag(k)
|
||||
@ -122,6 +137,15 @@ func (w *baseWriter) WriteTagValue(k, v interface{}) {
|
||||
type indexWriter struct {
|
||||
writer
|
||||
index int
|
||||
zero bool
|
||||
}
|
||||
|
||||
func (w *indexWriter) IncludeZero() {
|
||||
w.zero = true
|
||||
}
|
||||
|
||||
func (w *indexWriter) ExcludeZero() {
|
||||
w.zero = false
|
||||
}
|
||||
|
||||
func (w *indexWriter) WriteTag(v interface{}) {
|
||||
@ -141,7 +165,7 @@ func (w *indexWriter) WriteTag(v interface{}) {
|
||||
}
|
||||
|
||||
func (w *indexWriter) WriteTagValue(k, v interface{}) {
|
||||
if isZero(v) {
|
||||
if isZero(v) && w.zero == false {
|
||||
return
|
||||
}
|
||||
w.WriteTag(k)
|
||||
|
Loading…
Reference in New Issue
Block a user