Consolidate printing options in update_rust.py

update_rust.py has multiple ways to print the revision, with slightly
different characteristics. We would like to be able to print the
installed revision without validating it, for use on the rust ToT bots.

Rather than adding yet another argument, this CL consolidates the
various printing behavior into a single flag with three options.

Bug: 407563488
Change-Id: Iae078f48387a3feb5fbddab1db1b1478613f866e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6899826
Commit-Queue: Devon Loehr <dloehr@google.com>
Reviewed-by: Hans Wennborg <hans@chromium.org>
Auto-Submit: Devon Loehr <dloehr@google.com>
Commit-Queue: Hans Wennborg <hans@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1509582}
NOKEYCHECK=True
GitOrigin-RevId: 6a3651a5faee7e3eb6450ddb5f1837a2ef27401a
diff --git a/update_rust.py b/update_rust.py
index 103de9d..06cf695 100755
--- a/update_rust.py
+++ b/update_rust.py
@@ -82,26 +82,38 @@
 
 
 def main():
-    parser = argparse.ArgumentParser(description='Update Rust package')
+    parser = argparse.ArgumentParser(
+        description='Update Rust package',
+        formatter_class=argparse.RawTextHelpFormatter)
     parser.add_argument(
-        '--print-rust-revision',
-        action='store_true',
-        help='Print Rust revision (without Clang revision) and '
-        'quit. Can be run outside of a Chromium checkout.')
+        '--print-revision',
+        choices=['rust', 'installed', 'validate'],
+        help='Print the rust revision then quit. Possible formats:\n'
+        '- rust: print only the expected rust revision (without clang).\n'
+        '  Can be run outside of a Chromium checkout.\n'
+        '- installed: print the installed package version (including both\n'
+        '  rust and clang revisions), without checking that it matches the\n'
+        '  expected version in this file.\n'
+        '- validate: print the expected package version, and ensure it\n'
+        '  matches the installed package.')
+    parser.add_argument('--output-dir', help='Where to extract the package.')
+    # TODO(crbug.com/407563488): Remove this argument once all uses are removed
     parser.add_argument('--print-package-version',
                         action='store_true',
-                        help='Print Rust package version (including both the '
-                        'Rust and Clang revisions) and quit.')
-    parser.add_argument('--output-dir', help='Where to extract the package.')
+                        help='Deprecated and will be removed in the future.\n'
+                        'Use `--print-revision validate` instead.')
     args = parser.parse_args()
 
-    if args.print_rust_revision:
+    if args.print_package_version:
+        args.print_revision = 'validate'
+
+    if args.print_revision == 'rust':
         print(f'{RUST_REVISION}-{RUST_SUB_REVISION}')
         return 0
-
-    if args.print_package_version:
+    elif args.print_revision:
         stamp_version = GetStampVersion()
-        if stamp_version != GetRustClangRevision():
+        if (args.print_revision == 'validate'
+                and stamp_version != GetRustClangRevision()):
             print(f'The expected Rust version is {GetRustClangRevision()} '
                   f'but the actual version is {stamp_version}')
             print('Did you run "gclient sync"?')