# Need the package name, and whether to generate documentation. PACKAGE = File.read(Dir.glob('{.,meta/}unixname{,.txt}', File::FNM_CASEFOLD).first).strip GENERATE_RDOCS = true # package developer may need to deactivate require 'optparse' require 'rbconfig' class SetupError < StandardError; end # module Setup # # CLI runner # def self.run_cli(task) opts = OptionParser.new opts.banner = "Usage: #{File.basename($0)} [options]" if task == 'config' or task == 'all' opts.separator "" opts.separator "Config options:" Setup::ConfigTable::DESCRIPTIONS.each do |name, type, desc| opts.on("--#{name} #{type.to_s.upcase}", desc) do |val| ENV[name.to_s] = val.to_s end end end if task == 'install' opts.separator "" opts.separator "Install options:" opts.on("--prefix PATH", "Installation prefix") do |val| installer.install_prefix = val end end if task == 'test' opts.separator "" opts.separator "Install options:" opts.on("--runner TYPE", "Test runner (auto|console|gtk|gtk2|tk)") do |val| installer.config.testrunner = val end end # common options opts.separator "" opts.separator "General options:" opts.on("-q", "--quiet", "Silence output") do |val| installer.quiet = val end opts.on("--verbose", "Provide verbose output") do |val| installer.verbose = val end opts.on("-n", "--no-write", "Do not write to disk") do |val| installer.no_harm = !val end opts.on("--dryrun", "Same as --no-write") do |val| installer.no_harm = val end # common options opts.separator "" opts.separator "Inform options:" # Tail options (eg. commands in option form) opts.on_tail("-h", "--help", "display this help information") do puts Setup.help exit end opts.on_tail("--version", "Show version") do puts File.basename($0) + ' v' + Setup::Version.join('.') exit end opts.on_tail("--copyright", "Show copyright") do puts Setup::Copyright exit end begin opts.parse!(ARGV) rescue OptionParser::InvalidOption $stderr.puts $!.to_s.capitalize exit 1 end begin installer.__send__("exec_#{task}") rescue SetupError raise if $DEBUG $stderr.puts $!.message $stderr.puts "Try 'ruby #{$0} --help' for detailed usage." exit 1 end end end