3 setopt localoptions extendedglob
5 if (( CURRENT == 2 )); then
7 # Sample output (ng help):
9 # add Adds support for an external library to your project.
10 for line in ${(@f)"$(ng help 2>/dev/null | sed -n '/^ /p')"}; do
11 if [[ "$line" =~ '^ ([^ ]+) \(([^)]+)\) (.*)$' ]]; then
12 alias=(${match[1]} ${(s:, :)match[2]})
13 cmds+=(${^alias}:"${match[3]//:/}")
14 elif [[ "$line" =~ '^ ([^ ]+) (.*)$' ]]; then
15 cmds+=("${match[1]}:${match[2]//:/}")
18 _describe commands cmds && return 0
19 elif (( CURRENT == 3 )); then
21 local section description
22 # Sample output (ng build --help):
23 # --configuration (-c)
24 # One or more named builder configurations as a comma-separated list as specified in the "configurations" section of angular.json.
25 # The builder uses the named configurations to run the given target.
26 # For more information, see https://angular.io/guide/workspace-config#alternate-build-configurations.
27 # Prefix --flags with literal \0, and split on that to get each flag section
28 for section in ${(s:\0:)"$(ng ${words[2]} --help 2>/dev/null | sed -e '1,/^options/ d;s/^ --/\\0--/')"}; do
29 # Split by newline and discard extra description lines (lines > 2)
30 for args description in ${${(@f)section}[1,2]}; do
31 args=(${(s: :)${${args%% #}## #}//[(),]/})
32 description=${${description%% #}## #}
33 flags+=(${^args}":$description")
39 b|build|l|lint|t|test)
40 # Sample output (ng config projects):
42 # "angular-project-1": {
45 # "angular-project-2": {
49 # In absence of a proper JSON parser, just grab the lines with
50 # a 2-space indentation and only the stuff inside quotes
52 projects=(${(@f)"$(ng config projects 2>/dev/null | sed -n 's/^ "\([^"]\+\)".*$/\1/p')"})
53 _describe projects projects