Print output properties in the CLI
This change skips printing output<T> properties as we perform a deployment, instead showing the real values inline after the resource has been created. (output<T> is still shown during planning, of course.)
This commit is contained in:
parent
87ad371107
commit
ae8cefcb20
|
@ -206,6 +206,13 @@ func (prog *deployProgress) After(step resource.Step, state resource.State, err
|
||||||
// Increment the counters.
|
// Increment the counters.
|
||||||
prog.Steps++
|
prog.Steps++
|
||||||
prog.Ops[step.Op()]++
|
prog.Ops[step.Op()]++
|
||||||
|
|
||||||
|
// Print out any output properties that got created as a result of this operation.
|
||||||
|
if step.Op() == resource.OpCreate {
|
||||||
|
var b bytes.Buffer
|
||||||
|
printResourceOutputProperties(&b, step, "")
|
||||||
|
fmt.Printf(colors.Colorize(&b))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Issue a true, bonafide error.
|
// Issue a true, bonafide error.
|
||||||
prog.Ctx.Diag.Errorf(errors.ErrorPlanApplyFailed, err)
|
prog.Ctx.Diag.Errorf(errors.ErrorPlanApplyFailed, err)
|
||||||
|
|
|
@ -411,6 +411,7 @@ func printStep(b *bytes.Buffer, step resource.Step, summary bool, indent string)
|
||||||
// Next print the resource URN, properties, etc.
|
// Next print the resource URN, properties, etc.
|
||||||
printResourceHeader(b, step.Old(), step.New(), indent)
|
printResourceHeader(b, step.Old(), step.New(), indent)
|
||||||
b.WriteString(step.Op().Suffix())
|
b.WriteString(step.Op().Suffix())
|
||||||
|
|
||||||
var replaces []resource.PropertyKey
|
var replaces []resource.PropertyKey
|
||||||
if step.Old() != nil {
|
if step.Old() != nil {
|
||||||
m := step.Old().URN()
|
m := step.Old().URN()
|
||||||
|
@ -467,27 +468,59 @@ func printResourceProperties(b *bytes.Buffer, old resource.Resource, new resourc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func printObject(b *bytes.Buffer, props resource.PropertyMap, indent string) {
|
func maxKey(keys []resource.PropertyKey) int {
|
||||||
// Compute the maximum with of property keys so we can justify everything.
|
|
||||||
keys := resource.StablePropertyKeys(props)
|
|
||||||
maxkey := 0
|
maxkey := 0
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
if len(k) > maxkey {
|
if len(k) > maxkey {
|
||||||
maxkey = len(k)
|
maxkey = len(k)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return maxkey
|
||||||
|
}
|
||||||
|
|
||||||
|
func printObject(b *bytes.Buffer, props resource.PropertyMap, indent string) {
|
||||||
|
// Compute the maximum with of property keys so we can justify everything.
|
||||||
|
keys := resource.StablePropertyKeys(props)
|
||||||
|
maxkey := maxKey(keys)
|
||||||
|
|
||||||
// Now print out the values intelligently based on the type.
|
// Now print out the values intelligently based on the type.
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
if v := props[k]; shouldPrintPropertyValue(v) {
|
if v := props[k]; shouldPrintPropertyValue(v, false) {
|
||||||
printPropertyTitle(b, k, maxkey, indent)
|
printPropertyTitle(b, k, maxkey, indent)
|
||||||
printPropertyValue(b, v, indent)
|
printPropertyValue(b, v, indent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func shouldPrintPropertyValue(v resource.PropertyValue) bool {
|
func printResourceOutputProperties(b *bytes.Buffer, step resource.Step, indent string) {
|
||||||
return !v.IsNull() // by default, don't print nulls (they just clutter up the output)
|
indent += detailsIndent
|
||||||
|
b.WriteString(step.Op().Color())
|
||||||
|
b.WriteString(step.Op().Suffix())
|
||||||
|
|
||||||
|
olds := step.Old().Properties()
|
||||||
|
news := step.New().Properties()
|
||||||
|
keys := resource.StablePropertyKeys(olds)
|
||||||
|
maxkey := maxKey(keys)
|
||||||
|
for _, k := range keys {
|
||||||
|
if v := olds[k]; v.IsOutput() && shouldPrintPropertyValue(v, true) {
|
||||||
|
printPropertyTitle(b, k, maxkey, indent)
|
||||||
|
printPropertyValue(b, news[k], indent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
b.WriteString(colors.Reset)
|
||||||
|
}
|
||||||
|
|
||||||
|
func shouldPrintPropertyValue(v resource.PropertyValue, outs bool) bool {
|
||||||
|
if v.IsNull() {
|
||||||
|
// by default, don't print nulls (they just clutter up the output)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if v.IsOutput() && !outs {
|
||||||
|
// also don't show output properties until the outs parameter tells us to.
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func printPropertyTitle(b *bytes.Buffer, k resource.PropertyKey, align int, indent string) {
|
func printPropertyTitle(b *bytes.Buffer, k resource.PropertyKey, align int, indent string) {
|
||||||
|
@ -550,12 +583,7 @@ func printObjectDiff(b *bytes.Buffer, diff resource.ObjectDiff,
|
||||||
|
|
||||||
// Compute the maximum with of property keys so we can justify everything.
|
// Compute the maximum with of property keys so we can justify everything.
|
||||||
keys := diff.Keys()
|
keys := diff.Keys()
|
||||||
maxkey := 0
|
maxkey := maxKey(keys)
|
||||||
for _, k := range keys {
|
|
||||||
if len(k) > maxkey {
|
|
||||||
maxkey = len(k)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If a list of what causes a resource to get replaced exist, create a handy map.
|
// If a list of what causes a resource to get replaced exist, create a handy map.
|
||||||
var replaceMap map[resource.PropertyKey]bool
|
var replaceMap map[resource.PropertyKey]bool
|
||||||
|
@ -570,14 +598,14 @@ func printObjectDiff(b *bytes.Buffer, diff resource.ObjectDiff,
|
||||||
for _, k := range keys {
|
for _, k := range keys {
|
||||||
title := func(id string) { printPropertyTitle(b, k, maxkey, id) }
|
title := func(id string) { printPropertyTitle(b, k, maxkey, id) }
|
||||||
if add, isadd := diff.Adds[k]; isadd {
|
if add, isadd := diff.Adds[k]; isadd {
|
||||||
if shouldPrintPropertyValue(add) {
|
if shouldPrintPropertyValue(add, false) {
|
||||||
b.WriteString(colors.SpecAdded)
|
b.WriteString(colors.SpecAdded)
|
||||||
title(addIndent(indent))
|
title(addIndent(indent))
|
||||||
printPropertyValue(b, add, addIndent(indent))
|
printPropertyValue(b, add, addIndent(indent))
|
||||||
b.WriteString(colors.Reset)
|
b.WriteString(colors.Reset)
|
||||||
}
|
}
|
||||||
} else if delete, isdelete := diff.Deletes[k]; isdelete {
|
} else if delete, isdelete := diff.Deletes[k]; isdelete {
|
||||||
if shouldPrintPropertyValue(delete) {
|
if shouldPrintPropertyValue(delete, false) {
|
||||||
b.WriteString(colors.SpecDeleted)
|
b.WriteString(colors.SpecDeleted)
|
||||||
title(deleteIndent(indent))
|
title(deleteIndent(indent))
|
||||||
printPropertyValue(b, delete, deleteIndent(indent))
|
printPropertyValue(b, delete, deleteIndent(indent))
|
||||||
|
@ -588,7 +616,7 @@ func printObjectDiff(b *bytes.Buffer, diff resource.ObjectDiff,
|
||||||
causedReplace = replaceMap[k]
|
causedReplace = replaceMap[k]
|
||||||
}
|
}
|
||||||
printPropertyValueDiff(b, title, update, causedReplace, indent)
|
printPropertyValueDiff(b, title, update, causedReplace, indent)
|
||||||
} else if same := diff.Sames[k]; shouldPrintPropertyValue(same) {
|
} else if same := diff.Sames[k]; shouldPrintPropertyValue(same, false) {
|
||||||
title(indent)
|
title(indent)
|
||||||
printPropertyValue(b, diff.Sames[k], indent)
|
printPropertyValue(b, diff.Sames[k], indent)
|
||||||
}
|
}
|
||||||
|
@ -640,7 +668,7 @@ func printPropertyValueDiff(b *bytes.Buffer, title func(string), diff resource.V
|
||||||
} else {
|
} else {
|
||||||
// If we ended up here, the two values either differ by type, or they have different primitive values. We will
|
// If we ended up here, the two values either differ by type, or they have different primitive values. We will
|
||||||
// simply emit a deletion line followed by an addition line.
|
// simply emit a deletion line followed by an addition line.
|
||||||
if shouldPrintPropertyValue(diff.Old) {
|
if shouldPrintPropertyValue(diff.Old, false) {
|
||||||
var color string
|
var color string
|
||||||
if causedReplace {
|
if causedReplace {
|
||||||
color = resource.OpDelete.Color() // this property triggered replacement; color as a delete
|
color = resource.OpDelete.Color() // this property triggered replacement; color as a delete
|
||||||
|
@ -652,7 +680,7 @@ func printPropertyValueDiff(b *bytes.Buffer, title func(string), diff resource.V
|
||||||
printPropertyValue(b, diff.Old, deleteIndent(indent))
|
printPropertyValue(b, diff.Old, deleteIndent(indent))
|
||||||
b.WriteString(colors.Reset)
|
b.WriteString(colors.Reset)
|
||||||
}
|
}
|
||||||
if shouldPrintPropertyValue(diff.New) {
|
if shouldPrintPropertyValue(diff.New, false) {
|
||||||
var color string
|
var color string
|
||||||
if causedReplace {
|
if causedReplace {
|
||||||
color = resource.OpCreate.Color() // this property triggered replacement; color as a create
|
color = resource.OpCreate.Color() // this property triggered replacement; color as a create
|
||||||
|
|
|
@ -47,7 +47,7 @@ func NewIDLCCmd() *cobra.Command {
|
||||||
"and pkg-base-idl and --pkg-base-rpc may be used to override the default inferred Go\n" +
|
"and pkg-base-idl and --pkg-base-rpc may be used to override the default inferred Go\n" +
|
||||||
"package names (which, by default, are based on your GOPATH).",
|
"package names (which, by default, are based on your GOPATH).",
|
||||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
cmdutil.InitLogging(logToStderr, verbose)
|
cmdutil.InitLogging(logToStderr, verbose, true)
|
||||||
},
|
},
|
||||||
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
|
|
|
@ -27,8 +27,7 @@ import (
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Initialize loggers before going any further.
|
// Initialize loggers before going any further.
|
||||||
// TODO: consider parsing flags and letting the Lumi harness propagate them.
|
cmdutil.InitLogging(false, 0, false)
|
||||||
cmdutil.InitLogging(false, 0)
|
|
||||||
|
|
||||||
// Fire up a gRPC server, letting the kernel choose a free port for us.
|
// Fire up a gRPC server, letting the kernel choose a free port for us.
|
||||||
port, done, err := rpcutil.Serve(0, []func(*grpc.Server) error{
|
port, done, err := rpcutil.Serve(0, []func(*grpc.Server) error{
|
||||||
|
|
Loading…
Reference in a new issue