Update cros_overlay_list to support returning a list of overlays for all boards.

BUG=none
TEST=Try ./cros_workon_list --all_boards

Change-Id: Ic1138b62d3dcc37662bfe70ecaf8f1444df70b8d

Review URL: http://codereview.chromium.org/6596117
diff --git a/host/cros_overlay_list b/host/cros_overlay_list
index 09a54bf..c66415c 100755
--- a/host/cros_overlay_list
+++ b/host/cros_overlay_list
@@ -28,10 +28,16 @@
 get_default_board
 
 # Flags
+DEFINE_boolean all_boards "${FLAGS_FALSE}" \
+  "Return paths to overlays for all boards. (Default: false)"
 DEFINE_string board "$DEFAULT_BOARD" "The name of the board to set up."
 DEFINE_string board_overlay "" "Location of the board overlay."
 DEFINE_boolean primary_only ${FLAGS_FALSE} \
   "Only return the path to the board's primary overlay. (Default: false)"
+DEFINE_boolean private ${FLAGS_TRUE} \
+  "Include private overlays. (Default: true)"
+DEFINE_boolean public ${FLAGS_TRUE} \
+  "Include public overlays. (Default: true)"
 DEFINE_string variant "" "Board variant."
 
 # Parse command line flags
@@ -42,6 +48,21 @@
 # so will die prematurely if 'set -e' is specified before now.
 set -e
 
+public() { [ "$FLAGS_public" = "$FLAGS_TRUE" ]; }
+private() { [ "$FLAGS_private" = "$FLAGS_TRUE" ]; }
+
+if [ "$FLAGS_all_boards" = "$FLAGS_TRUE" ] ; then
+  overlays=
+  public && overlays="$overlays ${SRC_ROOT}/overlays/*overlay*"
+  private && overlays="$overlays ${SRC_ROOT}/private-overlays/*overlay*"
+  for overlay in $overlays ; do
+    if [ -d "$overlay" ] ; then
+      echo $overlay
+    fi
+  done
+  exit 0
+fi
+
 if [ -z "$FLAGS_board" ] ; then
   error "--board required."
   exit 1
@@ -86,9 +107,9 @@
 #
 # Identify the primary board overlay or die.
 #
-if is_primary_overlay ${BOARD_OVERLAY}; then
+if public && is_primary_overlay ${BOARD_OVERLAY}; then
   PRIMARY_OVERLAY="${BOARD_OVERLAY}"
-elif is_primary_overlay "${PRIVATE_BOARD_OVERLAY}"; then
+elif private && is_primary_overlay "${PRIVATE_BOARD_OVERLAY}"; then
   PRIMARY_OVERLAY="${PRIVATE_BOARD_OVERLAY}"
 fi
 if [ ! -n "${PRIMARY_OVERLAY}" ]; then
@@ -109,14 +130,14 @@
 #
 CHROMEOS_OVERLAY="${SRC_ROOT}/private-overlays/chromeos-overlay"
 
-if [ -d "${CHROMEOS_OVERLAY}" ]; then
+if private && [ -d "${CHROMEOS_OVERLAY}" ]; then
   echo "${CHROMEOS_OVERLAY}"
 fi
 
 #
 # Check if there are any public board overlays.
 #
-if [ -d "${BOARD_OVERLAY}" ]; then
+if public && [ -d "${BOARD_OVERLAY}" ]; then
   echo "${BOARD_OVERLAY}"
 
   #
@@ -132,7 +153,7 @@
 #
 # Add any private overlays and private variant overlays for this board.
 #
-if [ -d "${SRC_ROOT}/private-overlays" ] ; then
+if private && [ -d "${SRC_ROOT}/private-overlays" ] ; then
   OVERLAY_NAME="overlay-${FLAGS_board}-private"
   PRIVATE_OVERLAY="${SRC_ROOT}/private-overlays/${OVERLAY_NAME}"