mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-22 01:50: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
|
## Unreleased
|
||||||
### Added
|
### 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).
|
- Support for windows server 1903, by [@bradrydzewski](https://github.com/bradrydzewski).
|
||||||
|
|
||||||
## [1.2.2] - 2019-07-29
|
## [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) {
|
func printResources(w writer, v *yaml.Resources) {
|
||||||
w.WriteTag("resources")
|
w.WriteTag("resources")
|
||||||
w.IndentIncrease()
|
w.IndentIncrease()
|
||||||
@ -194,7 +194,9 @@ func printSettings(w writer, v map[string]*yaml.Parameter) {
|
|||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
v := v[k]
|
v := v[k]
|
||||||
if v.Secret == "" {
|
if v.Secret == "" {
|
||||||
|
w.IncludeZero()
|
||||||
w.WriteTagValue(k, v.Value)
|
w.WriteTagValue(k, v.Value)
|
||||||
|
w.ExcludeZero()
|
||||||
} else {
|
} else {
|
||||||
w.WriteTag(k)
|
w.WriteTag(k)
|
||||||
w.IndentIncrease()
|
w.IndentIncrease()
|
||||||
|
1
yaml/pretty/testdata/pipeline_settings.yml
vendored
1
yaml/pretty/testdata/pipeline_settings.yml
vendored
@ -8,6 +8,7 @@ steps:
|
|||||||
token:
|
token:
|
||||||
from_secret: token
|
from_secret: token
|
||||||
root: general
|
root: general
|
||||||
|
dry_run: false
|
||||||
labels:
|
labels:
|
||||||
- foo
|
- foo
|
||||||
- bar
|
- bar
|
||||||
|
@ -10,6 +10,7 @@ steps:
|
|||||||
- name: notify
|
- name: notify
|
||||||
image: plugins/slack
|
image: plugins/slack
|
||||||
settings:
|
settings:
|
||||||
|
dry_run: false
|
||||||
labels:
|
labels:
|
||||||
- foo
|
- foo
|
||||||
- bar
|
- bar
|
||||||
|
@ -42,12 +42,18 @@ type writer interface {
|
|||||||
// Indent appends padding to the buffer.
|
// Indent appends padding to the buffer.
|
||||||
Indent()
|
Indent()
|
||||||
|
|
||||||
// IndentIncrease inreases indentation.
|
// IndentIncrease increases indentation.
|
||||||
IndentIncrease()
|
IndentIncrease()
|
||||||
|
|
||||||
// IndentDecrese decreases indentation.
|
// IndentDecrease decreases indentation.
|
||||||
IndentDecrease()
|
IndentDecrease()
|
||||||
|
|
||||||
|
// IncludeZero includes zero value values
|
||||||
|
IncludeZero()
|
||||||
|
|
||||||
|
// ExcludeZero excludes zero value values.
|
||||||
|
ExcludeZero()
|
||||||
|
|
||||||
// Write appends the contents of p to the buffer.
|
// Write appends the contents of p to the buffer.
|
||||||
Write(p []byte) (n int, err error)
|
Write(p []byte) (n int, err error)
|
||||||
|
|
||||||
@ -71,6 +77,7 @@ type writer interface {
|
|||||||
type baseWriter struct {
|
type baseWriter struct {
|
||||||
bytes.Buffer
|
bytes.Buffer
|
||||||
depth int
|
depth int
|
||||||
|
zero bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *baseWriter) Indent() {
|
func (w *baseWriter) Indent() {
|
||||||
@ -87,6 +94,14 @@ func (w *baseWriter) IndentDecrease() {
|
|||||||
w.depth--
|
w.depth--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *baseWriter) IncludeZero() {
|
||||||
|
w.zero = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *baseWriter) ExcludeZero() {
|
||||||
|
w.zero = false
|
||||||
|
}
|
||||||
|
|
||||||
func (w *baseWriter) WriteTag(v interface{}) {
|
func (w *baseWriter) WriteTag(v interface{}) {
|
||||||
w.WriteByte('\n')
|
w.WriteByte('\n')
|
||||||
w.Indent()
|
w.Indent()
|
||||||
@ -95,7 +110,7 @@ func (w *baseWriter) WriteTag(v interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *baseWriter) WriteTagValue(k, v interface{}) {
|
func (w *baseWriter) WriteTagValue(k, v interface{}) {
|
||||||
if isZero(v) {
|
if isZero(v) && w.zero == false {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteTag(k)
|
w.WriteTag(k)
|
||||||
@ -122,6 +137,15 @@ func (w *baseWriter) WriteTagValue(k, v interface{}) {
|
|||||||
type indexWriter struct {
|
type indexWriter struct {
|
||||||
writer
|
writer
|
||||||
index int
|
index int
|
||||||
|
zero bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *indexWriter) IncludeZero() {
|
||||||
|
w.zero = true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *indexWriter) ExcludeZero() {
|
||||||
|
w.zero = false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *indexWriter) WriteTag(v interface{}) {
|
func (w *indexWriter) WriteTag(v interface{}) {
|
||||||
@ -141,7 +165,7 @@ func (w *indexWriter) WriteTag(v interface{}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *indexWriter) WriteTagValue(k, v interface{}) {
|
func (w *indexWriter) WriteTagValue(k, v interface{}) {
|
||||||
if isZero(v) {
|
if isZero(v) && w.zero == false {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.WriteTag(k)
|
w.WriteTag(k)
|
||||||
|
Loading…
Reference in New Issue
Block a user