bin/ferver
#!/usr/bin/env ruby
# frozen_string_literal: true
require "optparse"
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "/../lib")
require "ferver"
options = {}
OptionParser.new do |opts|
opts.banner = "Ferver: A simple web app to serve files over HTTP. Version: " + Ferver::VERSION
opts.separator ""
opts.on("-a", "--all", "Serve hidden files. False by default [optional]") do |a|
options[:hidden] = a
end
opts.on("-d", "--directory [DIRECTORY]", "Specify the path to the directory to serve files from [optional]") do |directory|
options[:directory] = directory
end
opts.on("-b", "--bind [IP or hostname]", "Set the hostname or IP address of the interface to listen on when running. Defaults to '0.0.0.0' [optional]") do |bind_address|
options[:bind_address] = bind_address
end
opts.on("-p", "--port [PORT]", "Set the port used by Ferver server. Defaults to 4567 [optional]") do |port|
options[:port] = port
end
opts.on("-h", "--help", "Displays help") do
puts opts
exit
end
end.parse!
Ferver.configure do |config|
config.serve_hidden = options[:hidden] if options[:hidden]
config.directory_path = options[:directory] if options[:directory]
end
Ferver::App.set :environment, :production
Ferver::App.set :bind, options[:bind_address] if options[:bind_address]
Ferver::App.set :port, options[:port] if options[:port]
# run!
Ferver::App.run!