Skip to content

Instantly share code, notes, and snippets.

@nalanj
Created August 24, 2014 16:58
Show Gist options
  • Save nalanj/ca6bdade852764c88d9d to your computer and use it in GitHub Desktop.
Save nalanj/ca6bdade852764c88d9d to your computer and use it in GitHub Desktop.
Radicle Command Line
#
# This was the command line implementation for Radicle. It's no longer in use, but I thought it was worthwhile
# to keep around, just in case.
#
require "optparse"
module Radicle
class CommandLine
# Public: Parses a command line array and returns a hash
# of options for starting a server.
def self.parse(argv)
defaults = Radicle::Server.defaults
options = defaults.clone
OptionParser.new do |opts|
opts.banner = "Usage: radicle [options] [services_directory]"
opts.separator("")
opts.separator("services_directory defaults to #{defaults[:services_dir]}")
opts.separator("")
opts.on("-h", "--host HOST", "listen on HOST (default: #{defaults[:host]})") do |hostname|
options[:host] = hostname
end
opts.on("-p", "--port PORT", "use PORT (default: #{defaults[:port]})") do |port|
begin
port = Integer(port)
raise if port < 0
rescue
raise "Invalid port number"
end
options[:port] = port
end
opts.on("-n", "--instances INSTANCES", "use INSTANCES number of processes (default: #{defaults[:instance_count]})") do |instances|
begin
instances = Integer(instances)
raise if instances < 0
rescue
raise "Invalid instance count"
end
options[:instance_count] = instances
end
opts.on_tail("-h", "--help", "show this message") do
puts opts
exit
end
end.parse!(argv)
# Use the remaining arg for our services directory
if argv.length > 0
options[:services_dir] = argv[0]
end
options
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment