Class: Megam::App
Constant Summary collapse
- NO_COMMAND_GIVEN =
include(a_module) is called inside a class, and adds module methods as instance methods. extend(a_module) adds all module methods to the instance it is called on.
"You need to pass a command with option (e.g., birr -i <install_path>)\n"
Instance Attribute Summary collapse
-
#name_args ⇒ Object
attr_accessors are setters/getters in ruby.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
-
.debug_stacktrace(e) ⇒ Object
The exception in ruby carries the class, message and the trace.
- .exit!(msg, err = -1)) ⇒ Object
-
.fatal!(msg, err = -1)) ⇒ Object
Log a fatal error message to both STDERR and the Logger, exit the application.
Instance Method Summary collapse
-
#initialize ⇒ App
constructor
A new instance of App.
- #parse_options(args) ⇒ Object
-
#run ⇒ Object
Run the “birr app”.
Constructor Details
#initialize ⇒ App
Returns a new instance of App.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/megam/app.rb', line 74 def initialize super # The super calls the mixlib cli. ##Traps are being set for the following when an application starts. ##SIGHUP 1 Term Hangup detected on controlling terminal ## or death of controlling process ##SIGINT 2 Term Interrupt from keyboard ##SIGQUIT 3 Core Quit from keyboard trap("TERM") do Megam::App.fatal!("SIGTERM received, stopping", 1) end trap("INT") do Megam::App.fatal!("SIGINT received, stopping", 2) end trap("QUIT") do Megam::Log.info("SIGQUIT received, call stack:\n " + caller.join("\n ")) end @text ||= Megam::Text.new(STDOUT, STDERR, STDIN, {}) end |
Instance Attribute Details
#name_args ⇒ Object
attr_accessors are setters/getters in ruby. The arguments are filtered and available for use to subclasses.
71 72 73 |
# File 'lib/megam/app.rb', line 71 def name_args @name_args end |
#text ⇒ Object
Returns the value of attribute text.
73 74 75 |
# File 'lib/megam/app.rb', line 73 def text @text end |
Class Method Details
.debug_stacktrace(e) ⇒ Object
The exception in ruby carries the class, message and the trace. www.ruby-doc.org/core-2.0/Exception.html
164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/megam/app.rb', line 164 def debug_stacktrace(e) = "#{e.class}: #{e}\n#{e.backtrace.join("\n")}" megam_stacktrace_out = "Generated at #{Time.now.to_s}\n" megam_stacktrace_out += #after the message is formulated in the variable megam_stack_trace_out, its #stored in a file named megam-stacktrace.out Megam::FileCache.store("megam-stacktrace.out", megam_stacktrace_out) ##The same error is logged in the log file saying, go look at megam-stacktrace.out for error. Megam::Log.fatal("Stacktrace dumped to #{Megam::FileCache.load("megam-stacktrace.out", false)}") Megam::Log.debug() true end |
Instance Method Details
#parse_options(args) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/megam/app.rb', line 109 def (args) super rescue OptionParser::InvalidOption => e puts "Error: " + e.to_s puts self.opt_parser exit(1) end |
#run ⇒ Object
Run the “birr app”. Let it roam and stay by our side.[Go birr..Does it remind of the Hutch adv.]. The first thing run does is it parses the options. Once the first level of parsing is done, ie the help, no_command, sub_command entry is verified it proceeds to call Megam_Birr with the user entered options and arguments (ARGV)
102 103 104 105 106 107 |
# File 'lib/megam/app.rb', line 102 def run Mixlib::Log::Formatter.show_time = false Megam::Birr.new.run(@named_args, config) exit 0 end |