diff --git a/bin/showterm b/bin/showterm index 0235205..2baeca5 100755 --- a/bin/showterm +++ b/bin/showterm @@ -1,28 +1,104 @@ #!/usr/bin/env ruby -require File.join(File.dirname(File.dirname(__FILE__)), 'lib/showterm') +$LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__)) + +require 'optparse' +require 'showterm' +require 'showterm/version' class Showterm::Main def run - if ARGV.include?('-h') || ARGV.include?('--help') + @action = :record_and_upload + @ask_before_upload = false + @edit_timings = false + @save_only = false + + option_parser.parse! ARGV + send @action + end - help + def option_parser + @option_parser ||= OptionParser.new do |opts| + opts.version = Showterm::Version::STRING - elsif ARGV[0] == '--retry' + opts.summary_width = 20 + opts.summary_indent = ' ' - ARGV.shift - reupload - else + # newline + pad to align option descriptions + nl = "\n#{' ' * (opts.summary_width + 3)}" + + opts.banner = <" - if '-e' == ARGV[0] || '--edit' == ARGV[0] + opts.separator '' + opts.separator 'Recording Options:' + + opts.on("-a", "--ask", "Ask for confirmation before uploading") do |value| + @ask_before_upload = true + end + + opts.on("-e", "--edit", "Edit the timings file before uploading. This can#{nl}be nice if you want to take long pauses (such as#{nl}searching an answer out) in between commands.") do @edit_timings = true - ARGV.shift end - sf, tf = record + opts.on("-s", "--save", "Save the recording locally instead of uploading.#{nl}Afterwords, use --retry to finish the upload.") do + @save_only = true + end + + opts.on("-r", "--retry", "Attempt an upload again (args: