]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/ng/_ng
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / ng / _ng
1 #compdef ng
2
3 setopt localoptions extendedglob
4
5 if (( CURRENT == 2 )); then
6   local -a cmds alias
7   # Sample output (ng help):
8   # Available Commands:
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]//:/}")
16     fi
17   done
18   _describe commands cmds && return 0
19 elif (( CURRENT == 3 )); then
20   local -a flags args
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")
34     done
35   done
36   _describe flags flags
37
38   case "$words[2]" in
39   b|build|l|lint|t|test)
40     # Sample output (ng config projects):
41     # {
42     #   "angular-project-1": {
43     #     ...
44     #   },
45     #   "angular-project-2": {
46     #     ...
47     #   }
48     # }
49     # In absence of a proper JSON parser, just grab the lines with
50     # a 2-space indentation and only the stuff inside quotes
51     local -a projects
52     projects=(${(@f)"$(ng config projects 2>/dev/null | sed -n 's/^  "\([^"]\+\)".*$/\1/p')"})
53     _describe projects projects
54     ;;
55   esac
56 fi