[fx][zsh] complete build dirs

Complete build directories (ie: directories under out/ that contain an
args.gn) in both `fx set` and `fx use`. Also make sure that flags always
come after positional parameters for `fx set`.

Change-Id: I6976bc622d574ca5eb726c9dec22915df2d9244f
diff --git a/zsh-completion/_fx b/zsh-completion/_fx
index f96f769..45a17d7 100644
--- a/zsh-completion/_fx
+++ b/zsh-completion/_fx
@@ -11,6 +11,11 @@
   _values $(cd ${fuchsia_build_dir}/amber-files/repository/targets && echo *(/))
 }
 
+__fx_build_dir() {
+  # build dirs are directories under out/ with an args.gn
+  compadd $(cd ${fuchsia_dir}; echo out/*/args.gn(N:h))
+}
+
 __fx_gn_target() {
   # use a cache of "gn ls" that's updated when build.ninja changes.
   local -r absolute_build_dir="${fuchsia_dir}/${fuchsia_build_dir}"
diff --git a/zsh-completion/_fx_set b/zsh-completion/_fx_set
index dfb795f..23875b6 100644
--- a/zsh-completion/_fx_set
+++ b/zsh-completion/_fx_set
@@ -46,11 +46,13 @@
 )
 
 # arguments to fx set
-_arguments '1:arch:{_describe "arch" archs}' '--release[release build]' \
-  '--packages[packages to build]:packages:_packages' \
-  '--products[products to build]:products:_products' \
-  '--goma[use goma]' "--no-goma[don't use goma]" \
-  "--no-ensure-goma[don't make sure goma is running]" \
-  "--ccache[use ccache]" "--no-ccache[don't use ccache]" \
-  "--args[arguments for gn gen]:args:{_gn_args}" \
-  '--goma-dir[goma directory to use]:directory:_files -/'
+_arguments '1:arch:{_describe "arch" archs}' \
+  '2::build_dir:{__fx_build_dir}' \
+  '(:)--release[release build]' \
+  '(:)--packages[packages to build]:packages:_packages' \
+  '(:)--products[products to build]:products:_products' \
+  '(:)--goma[use goma]' "--no-goma[don't use goma]" \
+  "(:)--no-ensure-goma[don't make sure goma is running]" \
+  "(:)--ccache[use ccache]" "--no-ccache[don't use ccache]" \
+  "(:)--args[arguments for gn gen]:args:{_gn_args}" \
+  '(:)--goma-dir[goma directory to use]:directory:_files -/'
diff --git a/zsh-completion/_fx_use b/zsh-completion/_fx_use
index 267e57d..febdd9c 100644
--- a/zsh-completion/_fx_use
+++ b/zsh-completion/_fx_use
@@ -1,3 +1,3 @@
 if (( $CURRENT == 2 )); then
-  _path_files -/
+  __fx_build_dir
 fi