git map: Add -h option

Bug:

Change-Id: Ife7f4049062bc951e58d5c322b1fc7e39338fe79
Reviewed-on: https://chromium-review.googlesource.com/463246
Commit-Queue: anatoly techtonik <techtonik@gmail.com>
Reviewed-by: Robbie Iannucci <iannucci@chromium.org>
diff --git a/git_map.py b/git_map.py
index 22e02e7..c765753 100755
--- a/git_map.py
+++ b/git_map.py
@@ -4,8 +4,9 @@
 # found in the LICENSE file.
 
 """
-Provides an augmented `git log --graph` view. In particular, it also annotates
-commits with branches + tags that point to them. Items are colorized as follows:
+Enhances `git log --graph` view with information on commit branches + tags that
+point to them. Items are colorized as follows:
+
   * Cyan    - Currently checked out branch
   * Green   - Local branch
   * Red     - Remote branches
@@ -37,7 +38,33 @@
 # Git emits combined color
 BRIGHT_RED = '\x1b[1;31m'
 
+
+def print_help():
+  names = {
+    'Cyan': CYAN,
+    'Green': GREEN,
+    'Magenta': MAGENTA,
+    'Red': RED,
+    'White': WHITE,
+    'Blue background': BLUEBAK,
+  }
+  msg = "usage: git map [-h] [<args>]\n"
+
+  for line in __doc__.splitlines():
+    for key in names.keys():
+      if key in line:
+        msg += line.replace('* ', '* ' + names[key])+RESET+'\n'
+        break
+    else:
+      msg += line + '\n'
+  sys.stdout.write(msg)
+
+
 def main(argv):
+  if '-h' in argv:
+    print_help()
+    return 0
+
   map_extra = get_config_list('depot_tools.map_extra')
   fmt = '%C(red bold)%h%x09%Creset%C(green)%d%Creset %C(yellow)%ad%Creset ~ %s'
   log_proc = subprocess2.Popen(