require 'commandline/optionparser' # == Synopsis # The Command Line Interface class CLI # == Synopsis # Here's the main execution loop def self.execute(stdout, arguments=[]) exit_code = ExitCode::OK begin # parse the command line options = setup_parser() od = options.parse(arguments) skip_execution = false %w(--help --version).each {|flag| skip_execution = true if od[flag] } unless skip_execution # create and execute class instance here app = QtRebuild.new() app.scan if od["--set"] puts app.to_set.join("\n") elsif !od["--quiet"] puts app.to_s end app.emerge(od["--pretend"], od['--nocolor']) end rescue ArgumentError => argErr STDERR.puts argErr.to_s STDERR.puts options.to_s STDERR.puts argErr.backtrace.join("\n") exit_code = ExitCode::CRITICAL rescue Exception => eMsg STDERR.puts eMsg.to_s STDERR.puts options.to_s STDERR.puts eMsg.backtrace.join("\n") exit_code = ExitCode::CRITICAL end exit_code end # == Synopsis # Setup the command line option parser # Returns:: OptionParser instances def self.setup_parser() options = CommandLine::OptionParser.new() # flag options [ { :names => %w(--version -v), :opt_found => lambda {puts QtRebuild.version; true }, :opt_description => "This version of qt-rebuild" }, { :names => %w(--help -h), :opt_found => lambda {puts options.to_s; true}, :opt_description => "Print usage." }, { :names => %w(--quiet -q), :opt_description => 'Display error messages only.' }, { :names => %w(--debug -d), :opt_description => 'Display debug messages.' }, { :names => %w(--set -s), :opt_description => "Output in portage's set format." }, { :names => %w(--nocolor -C), :opt_description => "Turn off colored output. (This option is also passed to portage.)" }, { :names => %w(--pretend -p), :opt_description => "Do a dry-run." }, ].each { |opt| options << CommandLine::Option.new(:flag, opt) } options end end