From c1f04c1feed16b3b4fc3fb7ce93324518d4efb21 Mon Sep 17 00:00:00 2001 From: Jim Myhrberg Date: Sun, 13 Nov 2011 14:00:26 +0000 Subject: [PATCH] some decent option parsing --- build.rb | 56 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/build.rb b/build.rb index 5d0335c..9ade435 100755 --- a/build.rb +++ b/build.rb @@ -1,7 +1,7 @@ #!/usr/bin/env ruby - require 'json' require 'date' +require 'optparse' # @@ -17,18 +17,40 @@ SOURCES_DIR = "#{ROOT_DIR}/sources" BUILDS_DIR = "#{ROOT_DIR}/builds" +# +# Main +# + +def main + opts = parse_options + + ref = ARGV.shift + meta = get_ref_info(ref) + + if meta['sha'] && meta['date'] + tarball = download_tarball(meta['sha']) + source = extract_tarball(tarball, patches(opts)) + app = compile_source(source) + + archive_app(app, meta['sha'], meta['date']) + else + raise "\nERROR: Failed to get commit info from GitHub API." + end +end + + # # Patches # -def patches +def patches(opts = {}) p = [] - if !ARGV.include?('--no-fullscreen') + if !opts[:no_fullscreen] p << 'https://raw.github.com/gist/1012927' end - if ARGV.include?('--srgb') + if opts[:srgb] p << 'https://raw.github.com/gist/1361934' end @@ -37,23 +59,25 @@ end # -# Main +# Options # -def main - ref = ARGV.shift +def parse_options + options = {} - meta = get_ref_info(ref) + OptionParser.new do |opts| + opts.banner = "Usage: build.rb [options] [branch/sha]" - if meta['sha'] && meta['date'] - tarball = download_tarball(meta['sha']) - source = extract_tarball(tarball, patches) - app = compile_source(source) + opts.on('--srgb', "Include sRGB patch.") do + options[:srgb] = true + end - archive_app(app, meta['sha'], meta['date']) - else - raise "\nERROR: Failed to get commit info from GitHub API." - end + opts.on("--no-fullscreen", "Don't include fullscreen patch") do + options[:no_fullscreen] = true + end + end.parse! + + options end