Clarify diff display of MutatingCommand

Tools inheriting from MutatingCommand print out the change they are going to
make and then ask the user to confirm that this is indeed what they wanted to
do.

The change is outputted as a list of updated values in the form

key -> [oldValue, newValue]

e.g.

dnsPaused -> [true, false]

This CL will change the output to be clearer:

key: oldValue -> newValue

e.g.

dnsPaused: true -> false

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=170853745
This commit is contained in:
guyben 2017-10-03 07:41:02 -07:00 committed by Ben McIlwain
parent fd62f4a74e
commit 01591ff88e
8 changed files with 30 additions and 31 deletions

View file

@ -63,7 +63,7 @@ Cursors can be updated as follows:
$ nomulus -e {ENVIRONMENT} update_cursors exampletld --type RDE_STAGING \ $ nomulus -e {ENVIRONMENT} update_cursors exampletld --type RDE_STAGING \
--timestamp 2016-09-01T00:00:00Z --timestamp 2016-09-01T00:00:00Z
Update Cursor@ahFzfmRvbWFpbi1yZWdpc3RyeXIzCxIPRW50aXR5R3JvdXBSb290Igljcm9zcy10bGQMCxIIUmVnaXN0cnkiB3lvdXR1YmUM_RDE_STAGING Update Cursor@ahFzfmRvbWFpbi1yZWdpc3RyeXIzCxIPRW50aXR5R3JvdXBSb290Igljcm9zcy10bGQMCxIIUmVnaXN0cnkiB3lvdXR1YmUM_RDE_STAGING
cursorTime -> [2016-09-23T00:00:00.000Z, 2016-09-01T00:00:00.000Z] cursorTime: 2016-09-23T00:00:00.000Z -> 2016-09-01T00:00:00.000Z
Perform this command? (y/N): Y Perform this command? (y/N): Y
Updated 1 entities. Updated 1 entities.

View file

@ -76,7 +76,7 @@ parameter:
```shell ```shell
$ nomulus -e {ENVIRONMENT} update_tld exampletld --premium_list exampletld $ nomulus -e {ENVIRONMENT} update_tld exampletld --premium_list exampletld
Update Registry@exampletld Update Registry@exampletld
premiumList -> [null, Key<?>(EntityGroupRoot("cross-tld")/PremiumList("exampletld"))] premiumList: null -> Key<?>(EntityGroupRoot("cross-tld")/PremiumList("exampletld"))
Perform this command? (y/N): y Perform this command? (y/N): y
Updated 1 entities. Updated 1 entities.

View file

@ -124,7 +124,7 @@ parameter:
$ nomulus -e {ENVIRONMENT} update_tld exampletld \ $ nomulus -e {ENVIRONMENT} update_tld exampletld \
--add_reserved_lists common_bad-words --add_reserved_lists common_bad-words
Update Registry@exampletld Update Registry@exampletld
reservedLists -> [null, [Key<?>(EntityGroupRoot("cross-tld")/ReservedList("common_bad-words"))]] reservedLists: null -> [Key<?>(EntityGroupRoot("cross-tld")/ReservedList("common_bad-words"))]
Perform this command? (y/N): y Perform this command? (y/N): y
Updated 1 entities. Updated 1 entities.
``` ```

View file

@ -57,16 +57,16 @@ import javax.annotation.Nullable;
* <p>For example, if you had an {@code ImmutableSortedMap<String, String>} on a field named * <p>For example, if you had an {@code ImmutableSortedMap<String, String>} on a field named
* {@code field}, then this would look like:<pre> {@code * {@code field}, then this would look like:<pre> {@code
* *
* field.key -> [key1, key2] * field.key: key1 -> key2
* field.value -> [value1, value2]}</pre> * field.value: value1 -> value2}</pre>
* *
* <p>If you had an {@code ImmutableSortedMap<String, EmbeddedClass>} on a field named * <p>If you had an {@code ImmutableSortedMap<String, EmbeddedClass>} on a field named
* {@code field}, where {@code EmbeddedClass} defines two {@code foo} and {@code bar} fields, then * {@code field}, where {@code EmbeddedClass} defines two {@code foo} and {@code bar} fields, then
* the embedded properties might look like:<pre> {@code * the embedded properties might look like:<pre> {@code
* *
* field.key -> [key1, key2] * field.key: key1 -> key2
* field.value.foo -> [foo1, foo2] * field.value.foo: foo1 -> foo2
* field.value.bar -> [bar1, bar2]}</pre> * field.value.bar: bar1 -> bar2}</pre>
* *
* @param <K> key type for sorted map which must be {@link Comparable} * @param <K> key type for sorted map which must be {@link Comparable}
* @param <V> value type for sorted map * @param <V> value type for sorted map

View file

@ -15,7 +15,6 @@
package google.registry.util; package google.registry.util;
import static com.google.common.base.Predicates.notNull; import static com.google.common.base.Predicates.notNull;
import static com.google.common.collect.Lists.newArrayList;
import com.google.common.annotations.VisibleForTesting; import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
@ -54,7 +53,7 @@ public final class DiffUtils {
@Override @Override
public String toString() { public String toString() {
// Note that we use newArrayList here instead of ImmutableList because a and b can be null. // Note that we use newArrayList here instead of ImmutableList because a and b can be null.
return newArrayList(a, b).toString(); return String.format("%s -> %s", a, b);
} }
} }
@ -141,9 +140,9 @@ public final class DiffUtils {
&& ((DiffPair) value).b instanceof Set) { && ((DiffPair) value).b instanceof Set) {
DiffPair pair = ((DiffPair) value); DiffPair pair = ((DiffPair) value);
String prettyLineDiff = prettyPrintSetDiff((Set<?>) pair.a, (Set<?>) pair.b) + "\n"; String prettyLineDiff = prettyPrintSetDiff((Set<?>) pair.a, (Set<?>) pair.b) + "\n";
output = newPath + ((prettyLineDiff.startsWith("\n")) ? " ->" : " -> ") + prettyLineDiff; output = newPath + ((prettyLineDiff.startsWith("\n")) ? ":" : ": ") + prettyLineDiff;
} else { } else {
output = newPath + " -> " + value + "\n"; output = newPath + ": " + value + "\n";
} }
builder.append(output); builder.append(output);
} }

View file

@ -99,16 +99,16 @@ public class MutatingCommandTest {
String changes = command.prompt(); String changes = command.prompt();
assertThat(changes).isEqualTo( assertThat(changes).isEqualTo(
"Update HostResource@2-ROID\n" "Update HostResource@2-ROID\n"
+ "lastEppUpdateTime -> [null, 2014-09-09T09:09:09.000Z]\n" + "lastEppUpdateTime: null -> 2014-09-09T09:09:09.000Z\n"
+ "\n" + "\n"
+ "Update HostResource@3-ROID\n" + "Update HostResource@3-ROID\n"
+ "currentSponsorClientId -> [TheRegistrar, Registrar2]\n" + "currentSponsorClientId: TheRegistrar -> Registrar2\n"
+ "\n" + "\n"
+ "Update Registrar@Registrar1\n" + "Update Registrar@Registrar1\n"
+ "billingIdentifier -> [null, 42]\n" + "billingIdentifier: null -> 42\n"
+ "\n" + "\n"
+ "Update Registrar@Registrar2\n" + "Update Registrar@Registrar2\n"
+ "blockPremiumNames -> [false, true]\n"); + "blockPremiumNames: false -> true\n");
String results = command.execute(); String results = command.execute();
assertThat(results).isEqualTo("Updated 4 entities.\n"); assertThat(results).isEqualTo("Updated 4 entities.\n");
assertThat(ofy().load().entity(host1).now()).isEqualTo(newHost1); assertThat(ofy().load().entity(host1).now()).isEqualTo(newHost1);
@ -229,13 +229,13 @@ public class MutatingCommandTest {
+ host1 + "\n" + host1 + "\n"
+ "\n" + "\n"
+ "Update HostResource@3-ROID\n" + "Update HostResource@3-ROID\n"
+ "currentSponsorClientId -> [TheRegistrar, Registrar2]\n" + "currentSponsorClientId: TheRegistrar -> Registrar2\n"
+ "\n" + "\n"
+ "Delete Registrar@Registrar1\n" + "Delete Registrar@Registrar1\n"
+ registrar1 + "\n" + registrar1 + "\n"
+ "\n" + "\n"
+ "Update Registrar@Registrar2\n" + "Update Registrar@Registrar2\n"
+ "blockPremiumNames -> [false, true]\n"); + "blockPremiumNames: false -> true\n");
String results = command.execute(); String results = command.execute();
assertThat(results).isEqualTo("Updated 4 entities.\n"); assertThat(results).isEqualTo("Updated 4 entities.\n");
assertThat(ofy().load().entity(host1).now()).isNull(); assertThat(ofy().load().entity(host1).now()).isNull();
@ -269,13 +269,13 @@ public class MutatingCommandTest {
+ host1 + "\n" + host1 + "\n"
+ "\n" + "\n"
+ "Update HostResource@3-ROID\n" + "Update HostResource@3-ROID\n"
+ "currentSponsorClientId -> [TheRegistrar, Registrar2]\n" + "currentSponsorClientId: TheRegistrar -> Registrar2\n"
+ "\n" + "\n"
+ "Delete Registrar@Registrar1\n" + "Delete Registrar@Registrar1\n"
+ registrar1 + "\n" + registrar1 + "\n"
+ "\n" + "\n"
+ "Update Registrar@Registrar2\n" + "Update Registrar@Registrar2\n"
+ "blockPremiumNames -> [false, true]\n"); + "blockPremiumNames: false -> true\n");
try { try {
command.execute(); command.execute();
assertWithMessage("Expected transaction to fail with IllegalStateException").fail(); assertWithMessage("Expected transaction to fail with IllegalStateException").fail();

View file

@ -1,13 +1,13 @@
The following changes were made to the registrar: The following changes were made to the registrar:
whoisServer -> [null, foo.bar.baz] whoisServer: null -> foo.bar.baz
ipAddressWhitelist -> [null, [1.1.1.1/32, 2.2.2.2/32, 4.4.4.4/32]] ipAddressWhitelist: null -> [1.1.1.1/32, 2.2.2.2/32, 4.4.4.4/32]
localizedAddress.street.0 -> [123 Example Bőulevard, 123 Street Rd] localizedAddress.street.0: 123 Example Bőulevard -> 123 Street Rd
localizedAddress.street.1 -> [null, Ste 156] localizedAddress.street.1: null -> Ste 156
localizedAddress.city -> [Williamsburg, New York] localizedAddress.city: Williamsburg -> New York
localizedAddress.zip -> [11211, 10011] localizedAddress.zip: 11211 -> 10011
phoneNumber -> [+1.2223334444, +1.2223335555] phoneNumber: +1.2223334444 -> +1.2223335555
emailAddress -> [new.registrar@example.com, thase@the.registrar] emailAddress: new.registrar@example.com -> thase@the.registrar
contacts -> contacts:
ADDED: ADDED:
{parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=Extra Terrestrial, emailAddress=etphonehome@example.com, phoneNumber=null, faxNumber=null, types=[ADMIN, BILLING, TECH, WHOIS], gaeUserId=null, visibleInWhoisAsAdmin=true, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false} {parent=Key<?>(EntityGroupRoot("cross-tld")/Registrar("TheRegistrar")), name=Extra Terrestrial, emailAddress=etphonehome@example.com, phoneNumber=null, faxNumber=null, types=[ADMIN, BILLING, TECH, WHOIS], gaeUserId=null, visibleInWhoisAsAdmin=true, visibleInWhoisAsTech=false, visibleInDomainWhoisAsAbuse=false}
REMOVED: REMOVED:

View file

@ -68,8 +68,8 @@ public class DiffUtilsTest {
Map<String, Object> mapB = new HashMap<String, Object>(); Map<String, Object> mapB = new HashMap<String, Object>();
mapB.put("a", "tim"); mapB.put("a", "tim");
mapB.put("b", ImmutableSet.of()); mapB.put("b", ImmutableSet.of());
// This ensures that it is not outputting a diff of [b -> [null, []]. // This ensures that it is not outputting a diff of b: null -> [].
assertThat(prettyPrintEntityDeepDiff(mapA, mapB)).isEqualTo("a -> [jim, tim]\n"); assertThat(prettyPrintEntityDeepDiff(mapA, mapB)).isEqualTo("a: jim -> tim\n");
} }
@Test @Test