I would like to be able to start a mongrel or webrick server by passing an extra command line argument that I can read somewhere inside my rails application. An example would be:
ruby script/server -p3000 --target=FOO
Here, --target is a custom switch who's value I would like to intercept in my rails application.
However, this yields the error:
server: invalid option: --target=FOO
I found mongrel documentation which mentions a -C (--config=PATH) argument specifying a full path to a y开发者_开发百科ml configuration file, but specifying that switch gives the same error as above. I presume this option is deprecated.
Is there another way to accomplish this?
You can't pass mongrel/webrick an extra command line argument without rewriting the argument processing code. If mongrel/webrick doesn't recognize the option, it will complain and give an error.
Rather than rewriting the argument processing, why not put the custom value in an environment variable and have your app query the variable? You could add your own script to handle starting mongrel/webrick and setting the environment so a single command would kick off everything.
精彩评论