Diff returns a string describing the pending mutations to the environment.
()
| 109 | |
| 110 | // Diff returns a string describing the pending mutations to the environment. |
| 111 | func (e *Environment) Diff() string { |
| 112 | lines := make([]string, 0, len(e.set)+len(e.unset)) |
| 113 | for k, v := range e.set { |
| 114 | old, ok := e.init[k] |
| 115 | if ok { |
| 116 | lines = append(lines, fmt.Sprintf("%s=%s (was %s)", k, v, old)) |
| 117 | } else { |
| 118 | lines = append(lines, fmt.Sprintf("%s=%s (was <nil>)", k, v)) |
| 119 | } |
| 120 | } |
| 121 | for k := range e.unset { |
| 122 | old, ok := e.init[k] |
| 123 | if ok { |
| 124 | lines = append(lines, fmt.Sprintf("%s=<nil> (was %s)", k, old)) |
| 125 | } else { |
| 126 | lines = append(lines, fmt.Sprintf("%s=<nil> (was <nil>)", k)) |
| 127 | } |
| 128 | } |
| 129 | sort.Strings(lines) |
| 130 | return strings.Join(lines, "\n") |
| 131 | } |