Parent directory

_pm2

15545 bytes
  1#compdef pm2
  2# ------------------------------------------------------------------------------
  3# Description
  4# -----------
  5#
  6#  Completion script for pm2 5.2.2 (https://pm2.keymetrics.io/).
  7#
  8# ------------------------------------------------------------------------------
  9# Authors
 10# -------
 11#
 12#  * Myoungdo Park <mdo.park@gmail.com>
 13#  * Shohei Yoshida <https://github.com/syohex>
 14#
 15# ------------------------------------------------------------------------------
 16
 17_pm2() {
 18  typeset -A opt_args
 19  local context state line
 20
 21  local curcontext="$curcontext"
 22
 23  local ret=1
 24
 25  _arguments -C \
 26    '(- *)'{-v,-V,--version}'[print pm2 version]' \
 27    '(-s --silent)'{-s,--silent}'[hide all messages]' \
 28    '--ext[watch only this file extension]:extension' \
 29    '(-n --name)'{-n,--name}'[set a name for the process in the process list]:name' \
 30    '(-m --mini-list)'{-m,--mini-list}'[display a compacted list without formatting]' \
 31    '--interpreter[set a specific interpreter to use for executing app(default: node)]:prog' \
 32    '(--interpreter-args --node-args)'{--interpreter-args,--node-args}'[set arguments to pass to the interpreter]:args' \
 33    '(-o --output)'{-o,--output}'[specify log file for stdout]: :_files' \
 34    '(-e --error)'{-e,--error}'[specify log file for stderr]: :_files' \
 35    '(-l --log)'{-l,--log}'[specify log file which gathers both stdout and stderr]' \
 36    '--filter-env[filter out outgoing global values that contain provided strings]:envs' \
 37    '--log-type[specify log output style]: :(raw json)' \
 38    '--log-date-format[specify log output style]:format' \
 39    '--time[enable time logging]' \
 40    '--disable-logs[disable all logs storage]' \
 41    '*--env[specify which set of environment variables from ecosystem file must be injected]:env' \
 42    '(-a --update-env)'{-a,--update-env}'[force and update of the environment with restart/reload]' \
 43    '(-f --force)'{-f,--force}'[force actions]' \
 44    '(-i --instances)'{-i,--instances}'[launch number instances]:num' \
 45    '--parallel[number of parallel actions]:num' \
 46    '--shutdown-with-message[shutdown an application with process.send("shutdown") instead of process.kill(pid, SIGINT)]' \
 47    '(-p --pid)'{-p,--pid}'[specify pid file]: :_files' \
 48    '(-k --kill-timeout)'{-k,--kill-timeout}'[delay before sending final SIGKILL signal to process]:delay' \
 49    '--listen-timeout[listen timeout an application reload]:delay' \
 50    '--max-memory-restart[restart the app if an amount of memory is exceeded (in bytes)]:bytes' \
 51    '--restart-delay[specify a delay between restarts(in milliseconds)]:delay' \
 52    '--exp-backoff-restart-delay[specify a delay between restarts(in milliseconds)]:delay' \
 53    '(-x --execute-command)'{-e,--execute-command}'[execute a program using fork system]' \
 54    '--max-restarts[only start the script COUNT times]:count' \
 55    '(-u --user)'{-u,--user}'[define user when generating startup script]:username' \
 56    '--uid[run target script with <uid> rights]:uid' \
 57    '--gid[run target script with <gid> rights]:gui' \
 58    '--namespace[start application within specified namespace]:namespace' \
 59    '--cwd[run target script from path <cwd>]:cwd:_paths -/' \
 60    '--hp[define home path when generating startup script]: :_paths -/' \
 61    '--wait-ip[override systemd script to wait for full internet connectivity to launch pm2]' \
 62    '--service-name[define service name when generating startup script]' \
 63    '(-c --cron --cron-restart)'{-c,--cron,--cron-restart}'[restart a running process based on a cron pattern]:pattern' \
 64    '(-w --write)'{-w,--write}'[write configuration in local folder]' \
 65    '--no-daemon[run pm2 daemon in the foreground if it does not exist already]' \
 66    '(--disable-source-map-support --source-map-support)--source-map-support[force source map support]' \
 67    '--only[with json declaration, allow to only act on one application]:app' \
 68    '(--disable-source-map-support --source-map-support)--disable-source-map-support[force disable source map support]' \
 69    '--wait-ready[ask pm2 to wait for ready event from your app]' \
 70    '--merge-logs[merge logs from different instances but keep error and out separated]' \
 71    '*--watch[watch application folder for changes]: :_files -/' \
 72    '*--ignore-watch[list of paths to ignore]: :_files' \
 73    '--no-color[skip colors]' \
 74    '--no-vizion[start an app without vizion feature]' \
 75    '--np-autorestart[start an app without automatic restart]' \
 76    '--no-treekill[Only kill the main process, not detached children]' \
 77    '--no-pmx[start an app without pmx]' \
 78    '--no-automation[start an app without automation]' \
 79    '(--disable-trace --trace)--trace[enable transaction tracing with km]' \
 80    '(--disable-trace --trace)--disable-trace[disable transaction tracing with km]' \
 81    "--sort[sort process according to field's]:field_name" \
 82    '--attach[attach logging after your start/restart/stop/reload]' \
 83    '--v8[enable v8 data collecting]' \
 84    '--event-loop-inspector[enable event-loop-inspector dump in pmx]' \
 85    '--deep-monitoring[enable all monitoring tools]' \
 86    '(- *)'{-h,--help}'[output usage information]' \
 87    '1: :_pm2_subcommands' \
 88    '*:: :->subcmds' && return 0
 89
 90  case "$state" in
 91    (subcmds)
 92      case $words[1] in
 93        (start)
 94          _arguments \
 95            '--watch[watch folder for changes]' \
 96            '--fresh[Rebuild Dockerfile]' \
 97            '--daemon[Run container in Daemon mode(debug purposes)]' \
 98            '--container[Start application in container mode]' \
 99            '--dist[--with-container; change local Dockerfile to containerize all files in current directory]' \
100            '--image-name[with --dist; set the exported image name]:name' \
101            '--node-version[with --container, set a specific major Node.js version]:version' \
102            '--dockerdaemon[for debugging purpose]' \
103            '(- *)'{-h,--help}'[output usage information]' \
104            '*: :_pm2_id_namespace_file' \
105            && ret=0
106          ;;
107        (trigger)
108          _arguments \
109            '(- *)'{-h,--help}'[output usage information]' \
110            '1: :_pm2_id_names' \
111            && ret=0
112          ;;
113        (deploy|startOrRestart|startOrReload|startOrGracefulReload)
114          _arguments \
115            '(- *)'{-h,--help}'[output usage information]' \
116            '1: :_files -g "*.json"' \
117            && ret=0
118          ;;
119        (stop|restart)
120          _arguments \
121            '(- *)'{-h,--help}'[output usage information]' \
122            '--watch[Stop watching folder for changes]' \
123            '*: :_pm2_id_namespace_all' \
124            && ret=0
125          ;;
126        (reload|delete|reset)
127          _arguments \
128            '(- *)'{-h,--help}'[output usage information]' \
129            '*: :_pm2_id_namespace_all' \
130            && ret=0
131          ;;
132        (module:install)
133          _arguments \
134            '(- *)'{-h,--help}'[output usage information]' \
135            '--tarball[is local tarball]' \
136            '--install[run yarn install before starting module]' \
137            '--docker[is docker container]' \
138            '--v1[install module in v1 manner(do not use it)]' \
139            '--safe[keep module backup, if new module fail = restore with previous]:time' \
140            && ret=0
141          ;;
142        (publish|module:publish)
143          _arguments \
144            '(- *)'{-h,--help}'[output usage information]' \
145            '--npm[publish on npm]' \
146            '*: :_files -/' \
147            && ret=0
148          ;;
149        (link)
150          _arguments \
151            '(- *)'{-h,--help}'[output usage information]' \
152            '--info-node[set url info node]:url' \
153            && ret=0
154          ;;
155        (plus)
156          _arguments \
157            '(- *)'{-h,--help}'[output usage information]' \
158            '--info-node[set url info node]:url' \
159            '(-d --discrete)'{-d,--discrete}'[silent mode]' \
160            '(-a --install-all)'{-a,--install-all}'[install all modules (force yes)]' \
161            && ret=0
162          ;;
163        (dump|save)
164          _arguments \
165            '(- *)'{-h,--help}'[output usage information]' \
166            '--force[force deletion of dump file even if empty]' \
167            && ret=0
168          ;;
169        (send|attach|describe|env)
170          _arguments \
171            '(- *)'{-h,--help}'[output usage information]' \
172            '1: :_pm2_id_names' \
173            && ret=0
174          ;;
175        (slist|sysinfos)
176          _arguments \
177            '(- *)'{-h,--help}'[output usage information]' \
178            '--tree[show as tree]' \
179            && ret=0
180          ;;
181        (logs)
182          _arguments \
183            '(- *)'{-h,--help}'[output usage information]' \
184            '--json[json log output]' \
185            '--format[formatted log output]' \
186            '--raw[raw output]' \
187            '--err[only shows error output]' \
188            '--out[only shows standard output]' \
189            '--line[output the last N lines, instead of the last 15 by default]:lines' \
190            '--timestamp[add timestamps(default format YYYY-MM-DD-HH:mm:ss)]:format' \
191            '--nostream[print logs without launching the log stream]' \
192            '*--highlight[highlights the given value]' \
193            '1: :_pm2_id_namespace' \
194            && ret=0
195          ;;
196        (serve)
197          _arguments \
198            '(- *)'{-h,--help}'[output usage information]' \
199            '--port[specify port to listen to]:port' \
200            '--spa[always serving index.html on inexistent sub path]' \
201            '--basic-auth-username[set basic auth username]:username' \
202            '--basic-auth-password[set basic auth password]:password' \
203            '--monitor[frontend app monitoring]:app' \
204            '*: :_files -/' \
205            && ret=0
206          ;;
207        (*)
208          _arguments \
209            '(- *)'{-h,--help}'[output usage information]' \
210            '*: :_files' \
211            && ret=0
212          ;;
213      esac
214      ;;
215  esac
216
217  return ret
218}
219
220(( $+functions[_pm2_subcommands] )) ||
221_pm2_subcommands() {
222  local -a subcommands=(
223    "start:start and daemonize an app"
224    "trigger:trigger process action"
225    "deploy:deploy your json"
226    "startOrRestart:start or restart JSON file"
227    "startOrReload:start or gracefully reload JSON file"
228    "pid:return pid of [app_name] or all"
229    "create:return pid of [app_name] or all"
230    "startOrGracefulReload:start or gracefully reload JSON file"
231    "stop:stop a process"
232    "restart:restart a process"
233    "scale:scale up/down a process in cluster mode depending on total_number param"
234    "profile\:mem:Sample PM2 heap memory"
235    "profile\:cpu:Profile PM2 cpu"
236    "reload:reload processes (note that its for app using HTTP/HTTPS)"
237    "id:get process id by name"
238    "inspect:inspect a process"
239    "delete:stop and delete a process from pm2 process list"
240    "sendSignal:send a system signal to the target process"
241    "ping:ping pm2 daemon - if not up it will launch it"
242    "updatePM2:update in-memory PM2 with local PM2"
243    "update:update in-memory PM2 with local PM2"
244    "install:install or update a module and run it forever"
245    "module\:install:install or update a module and run it forever"
246    "module\:update:update a module and run it forever"
247    "module\:generate:Generate a sample module in current folder"
248    "uninstall:stop and uninstall a module"
249    "module\:uninstall:stop and uninstall a module"
250    "package:Check & Package TAR type module"
251    "publish:Publish the module you are currently on"
252    "module\:publish:Publish the module you are currently on"
253    "set:sets the specified config <key> <value>"
254    "multiset:multiset eg \"key1 val1 key2 val2\""
255    "get:get value for <key>"
256    "conf:get / set module config values"
257    "config:get / set module config values"
258    "unset:clears the specified config <key>"
259    "report:give a full pm2 report for https://github.com/Unitech/pm2/issues"
260    "link:link with the pm2 monitoring dashboard"
261    "unlink:unlink with the pm2 monitoring dashboard"
262    "monitor:monitor target process"
263    "unmonitor:unmonitor target process"
264    "open:open the pm2 monitoring dashboard"
265    "plus:enable pm2 plus"
266    "login:Login to pm2 plus"
267    "logout:Logout from pm2 plus"
268    "dump:dump all processes for resurrecting them later"
269    "save:dump all processes for resurrecting them later"
270    "cleardump:Create empty dump file"
271    "send:send stdin to <pm_id>"
272    "attach:attach stdin/stdout to application identified by <pm_id>"
273    "resurrect:resurrect previously dumped processes"
274    "unstartup:disable the pm2 startup hook"
275    "startup:enable the pm2 startup hook"
276    "logrotate:copy default logrotate configuration"
277    "ecosystem:generate a process conf file"
278    "init:generate a process conf file"
279    "reset:reset counters for process"
280    "describe:describe all parameters of a process"
281    "desc:describe all parameters of a process"
282    "info:describe all parameters of a process"
283    "show:describe all parameters of a process"
284    "env:list all environment variables of a process id"
285    "list:list all processes"
286    "l:list all processes"
287    "ps:list all processes"
288    "status:list all processes"
289    "jlist:list all processes in JSON format"
290    "sysmonit:start system monitoring daemon"
291    "slist:list system infos in JSON"
292    "sysinfos:list system infos in JSON"
293    "prettylist:print json in a prettified JSON"
294    "monit:launch termcaps monitoring"
295    "imonit:launch legacy termcaps monitoring"
296    "dashboard:launch dashboard with monitoring and logs"
297    "dash:launch dashboard with monitoring and logs"
298    "flush:flush logs"
299    "reloadLogs:reload all logs"
300    "logs:stream logs file. Default stream all logs"
301    "kill:kill daemon"
302    "pull:updates repository for a given app"
303    "forward:updates repository to the next commit for a given app"
304    "backward:downgrades repository to the previous commit for a given app"
305    "deepUpdate:performs a deep update of PM2"
306    "serve:serve a directory over http via port"
307    "autoinstall:auto install"
308    "examples:display pm2 usage examples"
309  )
310
311  _describe -t subcommands 'subcommand' subcommands "$@"
312}
313
314(( $+functions[_pm2_id_names] )) ||
315_pm2_id_names() {
316  local app_list=$(pm2 list -m)
317  local -a names=(${(@f)"$(echo $app_list | awk '/^\+---/{sub("\\+--- ", ""); print}')"})
318  local -a ids=(${(@f)"$(echo $app_list | awk '/^pm2 id/{sub("pm2 id :", ""); print}')"})
319
320  if (( ${#ids} > 0 )); then
321    local -a id_names
322    for i in {1..${#ids}}; do
323      id_names+=( "${ids[i]}:${names[i]}" )
324    done
325
326    _describe 'id' id_names
327  fi
328}
329
330(( $+functions[_pm2_namespaces] )) ||
331_pm2_namespaces() {
332  local -a namespaces=(${(@f)"$(pm2 list -m | awk '/^namespace :/{ print $3 }')"})
333  if (( ${#namespaces} > 0 )); then
334    _values 'namespace' $namespaces
335  fi
336}
337
338(( $+functions[_pm2_id_namespace] )) ||
339_pm2_id_namespace() {
340  _alternative \
341    'ids:id:_pm2_id_names' \
342    'namespaces:namespace:_pm2_namespaces'
343}
344
345(( $+functions[_pm2_id_namespace_all] )) ||
346_pm2_id_namespace_all() {
347  _alternative \
348    'ids:id:_pm2_id_names' \
349    'namespaces:namespace:_pm2_namespaces' \
350    'all:all:(all)'
351}
352
353(( $+functions[_pm2_id_namespace_file] )) ||
354_pm2_id_namespace_file() {
355  _alternative \
356    'ids:id:_pm2_id_names' \
357    'namespaces:namespace:_pm2_namespaces' \
358    'files:file:_files'
359}
360
361if [ "$funcstack[1]" = "_pm2" ]; then
362    _pm2 "$@"
363else
364    compdef _pm2 pm2
365fi
366
367# Local Variables:
368# mode: Shell-Script
369# sh-indentation: 2
370# indent-tabs-mode: nil
371# sh-basic-offset: 2
372# End:
373
374# vim: ft=zsh sw=2 ts=2 et