{"id":13635900,"url":"https://github.com/openresty/resty-cli","last_synced_at":"2025-04-19T04:31:40.072Z","repository":{"id":23729486,"uuid":"27102797","full_name":"openresty/resty-cli","owner":"openresty","description":"Fancy command-line utilities for OpenResty","archived":false,"fork":false,"pushed_at":"2023-10-25T05:37:44.000Z","size":262,"stargazers_count":259,"open_issues_count":14,"forks_count":64,"subscribers_count":32,"default_branch":"master","last_synced_at":"2024-02-13T10:05:18.115Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://openresty.org","language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openresty.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-11-25T01:05:15.000Z","updated_at":"2023-10-23T21:01:10.000Z","dependencies_parsed_at":"2024-01-13T07:25:43.186Z","dependency_job_id":"c9dcd866-5f28-4846-b4e3-ff37f158aba9","html_url":"https://github.com/openresty/resty-cli","commit_stats":null,"previous_names":[],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Fresty-cli","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Fresty-cli/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Fresty-cli/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openresty%2Fresty-cli/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openresty","download_url":"https://codeload.github.com/openresty/resty-cli/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223790478,"owners_count":17203355,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T00:00:53.890Z","updated_at":"2024-11-09T05:31:05.501Z","avatar_url":"https://github.com/openresty.png","language":"Perl","funding_links":[],"categories":["Modules"],"sub_categories":[],"readme":"Name\n====\n\nresty-cli - Fancy command-line utilities for OpenResty.\n\nTable of Contents\n=================\n\n* [Name](#name)\n* [Description](#description)\n* [Videos](#videos)\n* [Synopsis](#synopsis)\n* [New Lua API](#new-lua-api)\n* [Installation](#installation)\n* [Test Suite](#test-suite)\n* [Authors](#authors)\n* [Copyright and License](#copyright-and-license)\n\nDescription\n===========\n\nThe `resty` command-line utility can be used to run OpenResty's Lua scripts directly off the command-line just like the `lua` or `luajit` command-line utilities. It can be used to create various command-line utilities using OpenResty Lua.\n\nThis tool works by creating a head-less `nginx` instance,\ndisabling [daemon](http://nginx.org/en/docs/ngx_core_module.html#daemon), [master_process](http://nginx.org/en/docs/ngx_core_module.html#master_process), [access_log](http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log), and other things it does\nnot need. No `server {}` is configured hence *no* listening sockets\nare involved at all.\n\nThe Lua code is initiated by the [init_worker_by_lua](https://github.com/openresty/lua-nginx-module#init_worker_by_lua)\ndirective and run in the context of [ngx.timer](https://github.com/openresty/lua-nginx-module#ngxtimerat) callback. So all of\n[ngx_lua](https://github.com/openresty/lua-nginx-module#readme)'s Lua APIs available in the [ngx.timer](https://github.com/openresty/lua-nginx-module#ngxtimerat) callback context are\nalso available in the `resty` utility. We may remove some of the\nremaining limitations in the future though.\n\nVideos\n======\n\n* YouTube video \"[OpenResty's resty Command-Line Utility Demo](https://youtu.be/L1c7aw4mSOo)\"\n\n    [![OpenResty's resty Command-Line Utility Demo](https://img.youtube.com/vi/L1c7aw4mSOo/0.jpg)](https://youtu.be/L1c7aw4mSOo)\n\nYou are welcome to subscribe to our [official YouTube channel, OpenResty](https://www.youtube.com/channel/UCXVmwF-UCScv2ftsGoMqxhw).\n\nSynopsis\n========\n\n```\n$ export PATH=/usr/local/openresty/bin:$PATH\n\n$ which resty\n/usr/local/openresty/bin/resty\n\n$ resty -h\nresty [options] [lua-file [args]]\n\nOptions:\n    -c NUM              Set maximal connection count (default: 64).\n    -e PROG             Run the inlined Lua code in \"prog\".\n\n    --errlog-level LEVEL\n                        Set nginx error_log level.\n                        Can be debug, info, notice, warn, error, crit, alert,\n                        or emerg.\n\n    --gdb               Use GDB to run the underlying nginx C process.\n\n    --gdb-opts OPTS     Pass extra command-line options to GDB.\n\n    --help              Print this help.\n\n    --http-conf CONF    Specifies nginx.conf snippet inserted into the http {}\n                        configuration block (multiple instances are supported).\n\n    --http-include PATH Include the specified file in the nginx http\n                        configuration block (multiple instances are supported).\n\n    -I DIR              Add dir to the search paths for Lua libraries.\n\n    -j dump             Use LuaJIT's jit.dump module to output detailed info of\n                        the traces generated by the JIT compiler.\n\n    -j off              Turn off the LuaJIT JIT compiler.\n\n    -j v                Use LuaJIT's jit.v module to output brief info of the\n                        traces generated by the JIT compiler.\n\n    -l LIB              Require library \"lib\".\n\n    --main-conf CONF    Specifies nginx.conf snippet inserted into the nginx\n                        main {} configuration block (multiple instances are\n                        supported).\n\n    --main-include PATH Include the specified file in the nginx main\n                        configuration block (multiple instances are supported).\n\n    --nginx             Specify the nginx path (this option might be removed\n                        in the future).\n\n    --no-stream         Disable the stream {} configuration in auto-generated\n                        nginx.conf.\n\n    --ns IP             Specify a custom name server (multiple instances are\n                        supported).\n\n    --resolve-ipv6      Make the nginx resolver lookup both IPv4 and IPv6\n                        addresses.\n\n    --rr                Use Mozilla rr to record the execution of the\n                        underlying nginx C process.\n\n    --shdict 'NAME SIZE'\n                        Create the specified lua shared dicts in the http\n                        configuration block (multiple instances are supported).\n\n    --stap\n                        Use sysetmtap to run the underlying nginx C process.\n\n    --stap-opts OPTS\n                        Pass extra systemtap command line options.\n\n    -V                  Print version numbers and nginx configurations.\n\n    --valgrind          Use valgrind to run nginx.\n\n    --valgrind-opts OPTS\n                        Pass extra options to valgrind.\n\nFor bug reporting instructions, please see:\n\n    \u003chttps://openresty.org/en/community.html\u003e\n\nCopyright (C) Yichun Zhang (agentzh). All rights reserved.\n\n$ resty -e 'print(\"hello\")'\nhello\n\n$ time resty -e 'ngx.sleep(3) print(\"done\\n\")'\ndone\n\nreal 0m3.085s\nuser 0m0.071s\nsys 0m0.010s\n\n$ resty -e 'ngx.say(ngx.md5(\"hello\"))'\n5d41402abc4b2a76b9719d911017c592\n\n$ resty -e 'io.stderr:write(\"hello world\\n\")' \u003e /dev/null\nhello world\n```\n\nTo run the code example in [lua-resty-mysql](https://github.com/openresty/lua-resty-mysql)'s\n\"Synopsis\" documentation section:\n\n```\n$ resty mysql-example.lua\nconnected to mysql.\ntable cats created.\n3 rows inserted into table cats (last insert id: 1)\nresult: [{\"name\":\"Bob\",\"id\":\"1\"},{\"name\":\"\",\"id\":\"2\"},{\"name\":null,\"id\":\"3\"}]\n```\n\nwhere `mysql-example.lua` is from [lua-resty-mysql](https://github.com/openresty/lua-resty-mysql)'s docs.\n\nStdin also works (in addition to stdout and stderr):\n\n```\n$ resty -e 'print(\"got: \", io.stdin:read(\"*l\"))'\nhiya\ngot: hiya\n```\n\nwhere the first \"hiya\" line was entered from the keyboard.\n\n\"Light threads\" also work:\n\n```\n$ time resty -e 'local ths = {}\n                 for i = 1, 3 do\n                     ths[i] = ngx.thread.spawn(function ()\n                                  ngx.sleep(3) ngx.say(\"done \", i)\n                              end)\n                 end\n                 for i = 1, #ths do ngx.thread.wait(ths[i]) end'\ndone 1\ndone 2\ndone 3\n\nreal 0m3.073s\nuser 0m0.053s\nsys 0m0.015s\n```\n\nUser command-line arguments are also passed:\n\n```\n$ resty -e 'print(arg[1], \", \", arg[2])' hello world\nhello, world\n```\n\nIf you need to use a shared dict:\n\n```\n$ resty --shdict='dogs 1m' -e 'local dict = ngx.shared.dogs\n                               dict:set(\"Tom\", 56)\n                               print(dict:get(\"Tom\"))'\n56\n```\n\nTo check version numbers:\n\n```\n$ resty -V\nresty 0.01\nnginx version: openresty/1.7.7.2\nbuilt by gcc 4.8.3 20140911 (Red Hat 4.8.3-7) (GCC)\nTLS SNI support enabled\nconfigure arguments: --prefix=/usr/local/openresty/nginx ...\n```\n\n[Back to TOC](#table-of-contents)\n\nNew Lua API\n===========\n\nWhen Lua scripts are run by the `resty` utility, the `ngx.config.is_console`\nfield will be set to `true`, so that the Lua scripts have a chance to know\nthat they are running in the console environment where stdin, stdout, stderr,\nand etc are all available to them.\n\n[Back to TOC](#table-of-contents)\n\nInstallation\n============\n\nThe `resty` command-line utility is bundled and enabled in OpenResty 1.7.7.2+ by\ndefault and is installed under `\u003copenresty-prefix\u003e/bin/` by default.\nIf the OpenResty prefix is the default value (`/usr/local/openresty`),\nthen you can just add `/usr/local/openresty/bin` to your PATH environment:\n\n```bash\nexport PATH=/usr/local/openresty/bin:$PATH\n```\n\nIf you are using the official OpenResty\n[pre-built Linux packages](https://openresty.org/en/linux-packages.html), you should install the\n[openresty-resty](https://openresty.org/en/rpm-packages.html#openresty-resty) package and/or\nthe [openresty-doc](https://openresty.org/en/rpm-packages.html#openresty-doc) (or `openresty-restydoc` on\nDebian/Ubuntu) package\nsince the [openresty](https://openresty.org/en/rpm-packages.html#openresty) binary package itself does not\ncontain the `resty` or `restydoc` utilities.\n\n[Back to TOC](#table-of-contents)\n\nTest Suite\n==========\n\nThis project comes with a test suite powered by Perl's testing toolchain.\n\nTo run the test suite on your side, first install some of the CPAN modules required by the test\nscaffold:\n\n```bash\nsudo cpan Test::Base IPC::Run\n```\n\nAlso, you need to make your nginx executable visible in your PATH environment:\n\n```bash\nexport PATH=/path/to/your/nginx/sbin:$PATH\n```\n\nThen you can run the tests with the `prove` command provided by Perl:\n\n```bash\nprove -r t\n```\n\nTo run an individual test file, just specify the test file on the command-line, for instance,\n\n```bash\nprove t/resty/user-args.t\n```\n\nTo run an individual test case in a test file, just (temporarily) add the line\n\n```\n--- ONLY\n```\n\nto the end of that test block, then run that particular test file as mentioned above.\n\n[Back to TOC](#table-of-contents)\n\nAuthors\n=======\n\n* Yichun Zhang (agentzh) \u003cagentzh@gmail.com\u003e, CloudFlare Inc.\n\n* Guanlan Dai \u003cguanlan@cloudflare.com\u003e, CloudFlare Inc.\n\n[Back to TOC](#table-of-contents)\n\nCopyright and License\n=====================\n\nThis module is licensed under the BSD license.\n\nCopyright (C) 2014-2020, by Yichun \"agentzh\" Zhang (章亦春) \u003cyichun@openresty.com\u003e, OpenResty Inc.\nCopyright (C) 2014-2016, by Guanlan Dai.\n\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n\n* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.\n\n* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n\nTHIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n\n[Back to TOC](#table-of-contents)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Fresty-cli","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenresty%2Fresty-cli","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenresty%2Fresty-cli/lists"}