From c99e192863f22376abc1c8e131639320819de11e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 26 Jun 2010 08:48:48 +0000 Subject: [PATCH] command-line option parsing --- README | 15 ++++++++++++--- bin/local-openid | 18 +++++++++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/README b/README index b8def5e..9999479 100644 --- a/README +++ b/README @@ -44,9 +44,18 @@ server. To be useful, it also depends on having a user account on a machine with a publically-accessible IP and DNS name to use as your OpenID identity. -"local-openid" should be installed in your $PATH by RubyGems. -It is a Sinatra application and takes all the usual command-line -arguments. Run "local-openid -h" for help. +== Running + +"local-openid" should be installed in your $PATH by RubyGems or +setup.rb. It is a Sinatra application and takes the usual +command-line arguments. It binds on all addresses (0.0.0.0) and port +4567 by default, using the standard WEBrick web server. + +You may specify a different port with the *-p* switch and address with +the *-o* switch. The following command will start local-openid on port +3000 bound to localhost (useful if behind a reverse proxy like nginx). + + local-openid -o 127.0.0.1 -p 3000 == Hacking diff --git a/bin/local-openid b/bin/local-openid index 7fc6b33..4b8f315 100755 --- a/bin/local-openid +++ b/bin/local-openid @@ -1,3 +1,19 @@ #!/usr/bin/env ruby require 'local_openid' -LocalOpenID.run! +require 'optparse' +require 'socket' +BasicSocket.do_not_reverse_lookup = true +opts = { + :server => 'webrick', # webrick is standard, and plenty fast enough +} +OptionParser.new { |op| + op.on('-s ') { |v| opts[:server] = v } + op.on('-p port') { |val| opts[:port] = val.to_i } + op.on('-o addr') { |val| opts[:bind] = val } + op.on('-h', '--help', 'Show this message') do + puts op.to_s + exit + end +}.parse!(ARGV) + +LocalOpenID.run!(opts) -- 2.11.4.GIT