Parent

Class Index [+]

Quicksearch

TaskJuggler::Tj3AppBase

Public Class Methods

new() click to toggle source
    # File lib/taskjuggler/Tj3AppBase.rb, line 28
28:     def initialize
29:       # Indent and width of options. The deriving class may has to change
30:       # this.
31:       @optsSummaryWidth = 22
32:       @optsSummaryIndent = 5
33:       # Show some progress information by default
34:       @silent = false
35:       @configFile = nil
36:       @mandatoryArgs = ''
37:       @mininumRubyVersion = '1.9.2'
38:     end

Public Instance Methods

main(argv = ARGV) click to toggle source
     # File lib/taskjuggler/Tj3AppBase.rb, line 89
 89:     def main(argv = ARGV)
 90:       if Gem::Version.new(RUBY_VERSION.dup) <
 91:          Gem::Version.new(@mininumRubyVersion)
 92:         error('This program requires at least Ruby version ' +
 93:               "#{@mininumRubyVersion}!")
 94:       end
 95: 
 96:       # Install signal handler to exit gracefully on CTRL-C.
 97:       intHandler = Kernel.trap('INT') do
 98:         error("Aborting on user request!")
 99:       end
100: 
101:       begin
102:         args = processArguments(argv)
103: 
104:         # If DEBUG mode has been enabled, we restore the INT trap handler again
105:         # to get Ruby backtrackes.
106:         Kernel.trap('INT', intHandler) if $DEBUG
107: 
108:         unless @silent
109:           puts "#{AppConfig.softwareName} v#{AppConfig.version} - " +
110:                "#{AppConfig.packageInfo}\n\n" +
111:                "Copyright (c) #{AppConfig.copyright.join(', ')}\n" +
112:                "              by #{AppConfig.authors.join(', ')}\n\n" +
113:                "#{AppConfig.license}\n"
114:         end
115: 
116:         @rc = RuntimeConfig.new(AppConfig.packageName, @configFile)
117: 
118:         appMain(args)
119:       rescue Exception => e
120:         if e.is_a?(SystemExit) || e.is_a?(Interrupt)
121:           # Don't show backtrace on user interrupt unless we are in debug mode.
122:           $stderr.puts e.backtrace.join("\n") if $DEBUG
123:           1
124:         else
125:           error("Ups, you have triggered a bug in #{AppConfig.softwareName}!\n" +
126:                 "#{e}\n" +
127:                 e.backtrace.join("\n") +
128:                 "Please see the user manual on how to get this bug fixed!")
129:         end
130:       end
131:     end
processArguments(argv) click to toggle source
    # File lib/taskjuggler/Tj3AppBase.rb, line 40
40:     def processArguments(argv)
41:       @opts = OptionParser.new
42:       @opts.summary_width = @optsSummaryWidth
43:       @opts.summary_indent = ' ' * @optsSummaryIndent
44: 
45:       @opts.banner = "#{AppConfig.softwareName} v#{AppConfig.version} - " +
46:                      "#{AppConfig.packageInfo}\n\n" +
47:                      "Copyright (c) #{AppConfig.copyright.join(', ')}\n" +
48:                      "              by #{AppConfig.authors.join(', ')}\n\n" +
49:                      "#{AppConfig.license}\n" +
50:                      "For more info about #{AppConfig.softwareName} see " +
51:                      "#{AppConfig.contact}\n\n" +
52:                      "Usage: #{AppConfig.appName} [options] " +
53:                      "#{@mandatoryArgs}\n\n"
54:       @opts.separator ""
55:       @opts.on('-c', '--config <FILE>', String,
56:                format('Use the specified YAML configuration file')) do |arg|
57:          @configFile = arg
58:       end
59:       @opts.on('--silent',
60:                format("Don't show program and progress information")) do
61:         @silent = true
62:       end
63:       @opts.on('--debug', format('Enable Ruby debug mode')) do
64:         $DEBUG = true
65:       end
66: 
67:       yield
68: 
69:       @opts.on_tail('-h', '--help', format('Show this message')) do
70:         puts @opts.to_s
71:         quit
72:       end
73:       @opts.on_tail('--version', format('Show version info')) do
74:         puts "#{AppConfig.softwareName} v#{AppConfig.version} - " +
75:           "#{AppConfig.packageInfo}"
76:         quit
77:       end
78: 
79:       begin
80:         files = @opts.parse(argv)
81:       rescue OptionParser::ParseError => msg
82:         puts @opts.to_s + "\n"
83:         error(msg, 2)
84:       end
85: 
86:       files
87:     end

Private Instance Methods

error(message, exitVal = 1) click to toggle source
     # File lib/taskjuggler/Tj3AppBase.rb, line 139
139:     def error(message, exitVal = 1)
140:       $stderr.puts "\nERROR: #{message}"
141:       exit exitVal
142:     end
format(str, indent = nil) click to toggle source
     # File lib/taskjuggler/Tj3AppBase.rb, line 144
144:     def format(str, indent = nil)
145:       indent = @optsSummaryWidth + @optsSummaryIndent + 1 unless indent
146:       TextFormatter.new(79, indent).format(str)[indent..1]
147:     end
quit() click to toggle source
     # File lib/taskjuggler/Tj3AppBase.rb, line 135
135:     def quit
136:       exit 0
137:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.