This is a copy-paste with minor edits from my blog, which I use to save information that is potentially useful to me, but which I usually forget. Considered that infa may seem interesting to someone.
Relatively recently, I was looking for a way to launch a web server in one line in the current directory.
In the vast Stack Overflow found something like this:
ruby -run -e httpd -- -p 9090 [DIR]
What is this mysterious option -run
and why it is not in the manual?
Of course, this is not an option. More precisely, the option, but not run
. Please note that before it is one dash, not two.
In fact, this is the -r
option with the un
argument. In turn, un
is a file in the standard library that defines several useful functions that are conveniently used in one-liners.
One of them is httpd
which simply launches WebBrick
using parameters from ARGV
(in this case, the port and directory).
Obviously, this is a very old file, because I found the documentation for it already for version 1.8.6
.
So you can use without fear.
I copy from documentation:
ruby -run -e cp -- [OPTION] SOURCE DEST ruby -run -e ln -- [OPTION] TARGET LINK_NAME ruby -run -e mv -- [OPTION] SOURCE DEST ruby -run -e rm -- [OPTION] FILE ruby -run -e mkdir -- [OPTION] DIRS ruby -run -e rmdir -- [OPTION] DIRS ruby -run -e install -- [OPTION] SOURCE DEST ruby -run -e chmod -- [OPTION] OCTAL-MODE FILE ruby -run -e touch -- [OPTION] FILE ruby -run -e help [COMMAND]
I suppose that using un
outside one-line ruby -run -e
like ruby -run -e
does not make sense, since each of the methods defined there uses ARGV. But it's useful to have a note that ruby ​​can do this. Most likely, in Windows it will work exactly the same way (I don’t know how to delete a file or create a directory in Windows, but everything is defined in Ruby).
By the way, I added the following command to my bash:
alias start-webrick='ruby -run -e httpd -- -p 9090'
Very comfortably.
Github link
Source: https://habr.com/ru/post/319002/
All Articles