]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/pm2/_pm2
initial
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / pm2 / _pm2
1 #!/bin/zsh -f
2 #compdef pm2
3 #autoload
4
5 local -a _1st_arguments
6
7 _1st_arguments=(
8     "start:start and daemonize an app"
9     "trigger:trigger process action"
10     "deploy:deploy your json"
11     "startOrRestart:start or restart JSON file"
12     "startOrReload:start or gracefully reload JSON file"
13     "pid:return pid of [app_name] or all"
14     "stop:stop a process"
15     "restart:restart a process"
16     "scale:scale up/down a process in cluster mode depending on total_number param"
17     "profile\:mem:Sample PM2 heap memory"
18     "profile\:cpu:Profile PM2 cpu"
19     "reload:reload processes (note that its for app using HTTP/HTTPS)"
20     "id:get process id by name"
21     "inspect:inspect a process"
22     "delete:stop and delete a process from pm2 process list"
23     "sendSignal:send a system signal to the target process"
24     "ping:ping pm2 daemon - if not up it will launch it"
25     "updatePM2:update in-memory PM2 with local PM2"
26     "install:install or update a module and run it forever"
27     "module\:update:update a module and run it forever"
28     "module\:generate:Generate a sample module in current folder"
29     "uninstall:stop and uninstall a module"
30     "package:Check & Package TAR type module"
31     "publish:Publish the module you are currently on"
32     "set:sets the specified config <key> <value>"
33     "multiset:multiset eg \"key1 val1 key2 val2\""
34     "get:get value for <key>"
35     "config:get / set module config values"
36     "unset:clears the specified config <key>"
37     "report:give a full pm2 report for https\://github.com/Unitech/pm2/issues"
38     "link:link with the pm2 monitoring dashboard"
39     "unlink:unlink with the pm2 monitoring dashboard"
40     "monitor:monitor target process"
41     "unmonitor:unmonitor target process"
42     "open:open the pm2 monitoring dashboard"
43     "plus:enable pm2 plus"
44     "login:Login to pm2 plus"
45     "logout:Logout from pm2 plus"
46     "web:launch a health API on 0.0.0.0\:9615"
47     "dump:dump all processes for resurrecting them later"
48     "cleardump:Create empty dump file"
49     "send:send stdin to <pm_id>"
50     "attach:attach stdin/stdout to application identified by <pm_id>"
51     "resurrect:resurrect previously dumped processes"
52     "unstartup:disable the pm2 startup hook"
53     "startup:enable the pm2 startup hook"
54     "logrotate:copy default logrotate configuration"
55     "ecosystem:generate a process conf file. (mode = null or simple)"
56     "reset:reset counters for process"
57     "describe:describe all parameters of a process id"
58     "list:list all processes"
59     "jlist:list all processes in JSON format"
60     "prettylist:print json in a prettified JSON"
61     "monit:launch termcaps monitoring"
62     "imonit:launch legacy termcaps monitoring"
63     "dashboard:launch dashboard with monitoring and logs"
64     "flush:flush logs"
65     "reloadLogs:reload all logs"
66     "logs:stream logs file. Default stream all logs"
67     "kill:kill daemon"
68     "pull:updates repository for a given app"
69     "forward:updates repository to the next commit for a given app"
70     "backward:downgrades repository to the previous commit for a given app"
71     "deepUpdate:performs a deep update of PM2"
72     "serve:serve a directory over http via port"
73     "examples:display pm2 usage examples"
74 )
75
76 local -a id_names
77
78 _id_names() {
79     local app_list
80     app_list=`pm2 list -m`
81
82     local -a names ids 
83     names=(`echo $app_list | grep '+---' | awk '{print $2}'`)
84     ids=(`echo $app_list | grep 'pm2 id' | awk '{print $4}'`)
85
86     if (( ${#ids} > 0 )); then
87         for i in {1..${#ids}}; do
88             id_names+=( "${ids[i]}:${names[i]}" )
89         done
90     fi
91 }
92
93 _arguments \
94     '(-v --version)'{-v,--version}'[output version]' \
95     '(-h --help)'{-h,--help}'[output usage information]' \
96     '*:: :->subcmds' && return 0
97
98 if (( CURRENT == 1 )); then
99     _describe "command" _1st_arguments
100     return
101 fi
102
103 local -a id_comp id_all_comp id_all_files_comp start_options logs_options
104 id_comp=('1: :->id_comp')
105 id_all_comp=('1: :->id_all_comp')
106 id_all_files_comp=('1: :->id_all_files_comp')
107 start_options=(
108     '--watch[Watch folder for changes]'
109     '--fresh[Rebuild Dockerfile]'
110     '--daemon[Run container in Daemon mode (debug purposes)]'
111     '--container[Start application in container mode]'
112     '--dist[with --container; change local Dockerfile to containerize all files in current directory]'
113     '--image-name[with --dist; set the exported image name]'
114     '--node-version[with --container, set a specific major Node.js version]'
115     '--dockerdaemon[for debugging purpose]'
116     '(-h --help)'{-h,--help}'[output usage information]'
117     $id_all_files_comp
118 )
119 logs_options=(
120     '--json[json log output]'
121     '--format[formatted log output]'
122     '--raw[raw output]'
123     '--err[only shows error output]'
124     '--out[only shows standard output]'
125     '--lines[output the last N lines, instead of the last 15 by default]'
126     '--timestamp[add timestamps (default format YYYY-MM-DD-HH:mm:ss)]'
127     '--nostream[print logs without launching the log stream]'
128     '(-h --help)'{-h,--help}'[output usage information]'
129     $id_all_comp
130 )
131
132 case "$words[1]" in
133     start)
134         _arguments $start_options && return 0
135         ;;
136     logs)
137         _arguments $logs_options && return 0
138         ;;
139     stop|restart|delete|reload|reset)
140         _arguments $id_all_comp && return 0
141         ;;
142     env|inspect|monitor|unmonitor|describe)
143         _arguments $id_comp && return 0
144         ;;
145     deploy|startOrRestart|startOrReload)
146         _files ;;
147 esac
148
149 case "$state" in
150     id_comp)
151         _id_names
152         _alternative \
153             'args:app args:(($id_names))'
154         ;;
155     id_all_comp)
156         _id_names
157         id_names+=(all)
158         _alternative \
159             'args:app args:(($id_names))'
160         ;;
161     id_all_files_comp)
162         _id_names
163         id_names+=(all)
164         _alternative \
165             'args:app args:(($id_names))' \
166             'files:filename:_files'
167         ;;
168 esac