Class: CLI
- Inherits:
-
Object
- Object
- CLI
- Defined in:
- lib/qt-rebuild/cli.rb
Overview
Synopsis
The Command Line Interface
Class Method Summary collapse
-
.execute(stdout, arguments = []) ⇒ Object
Synopsis Here’s the main execution loop.
-
.setup_parser ⇒ Object
Synopsis Setup the command line option parser Returns:: OptionParser instances.
Class Method Details
.execute(stdout, arguments = []) ⇒ Object
Synopsis
Here’s the main execution loop
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/qt-rebuild/cli.rb', line 9 def self.execute(stdout, arguments=[]) exit_code = ExitCode::OK begin # parse the command line = setup_parser() od = .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 .to_s STDERR.puts argErr.backtrace.join("\n") exit_code = ExitCode::CRITICAL rescue Exception => eMsg STDERR.puts eMsg.to_s STDERR.puts .to_s STDERR.puts eMsg.backtrace.join("\n") exit_code = ExitCode::CRITICAL end exit_code end |
.setup_parser ⇒ Object
Synopsis
Setup the command line option parser
- Returns
-
OptionParser instances
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/qt-rebuild/cli.rb', line 47 def self.setup_parser() = 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 .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| << CommandLine::Option.new(:flag, opt) } end |