Class: CliFuncs
- Inherits:
-
Object
- Object
- CliFuncs
- Defined in:
- lib/cli_funcs.rb
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
Returns the value of attribute base_dir.
-
#data_dir ⇒ Object
Returns the value of attribute data_dir.
-
#flags_all ⇒ Object
Returns the value of attribute flags_all.
-
#ignore_bad_exit ⇒ Object
Returns the value of attribute ignore_bad_exit.
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Instance Method Summary collapse
- #clear_values ⇒ Object
- #flag_add(flag) ⇒ Object
- #flags_run ⇒ Object
-
#initialize ⇒ CliFuncs
constructor
A new instance of CliFuncs.
- #run_and_capture(*args) ⇒ Object
- #set_dirs ⇒ Object
Constructor Details
#initialize ⇒ CliFuncs
Returns a new instance of CliFuncs.
8 9 10 11 12 13 14 15 |
# File 'lib/cli_funcs.rb', line 8 def initialize @ignore_bad_exit = false @base_dir = String @data_dir = String @output = Array.new @flags_all = Array.new set_dirs end |
Instance Attribute Details
#base_dir ⇒ Object
Returns the value of attribute base_dir.
5 6 7 |
# File 'lib/cli_funcs.rb', line 5 def base_dir @base_dir end |
#data_dir ⇒ Object
Returns the value of attribute data_dir.
5 6 7 |
# File 'lib/cli_funcs.rb', line 5 def data_dir @data_dir end |
#flags_all ⇒ Object
Returns the value of attribute flags_all.
5 6 7 |
# File 'lib/cli_funcs.rb', line 5 def flags_all @flags_all end |
#ignore_bad_exit ⇒ Object
Returns the value of attribute ignore_bad_exit.
5 6 7 |
# File 'lib/cli_funcs.rb', line 5 def ignore_bad_exit @ignore_bad_exit end |
#output ⇒ Object (readonly)
Returns the value of attribute output.
6 7 8 |
# File 'lib/cli_funcs.rb', line 6 def output @output end |
Instance Method Details
#clear_values ⇒ Object
30 31 32 33 |
# File 'lib/cli_funcs.rb', line 30 def clear_values @flags_all = Array.new @output = Array.new end |
#flag_add(flag) ⇒ Object
26 27 28 |
# File 'lib/cli_funcs.rb', line 26 def flag_add(flag) @flags_all.push(flag) unless flag == nil end |
#flags_run ⇒ Object
22 23 24 |
# File 'lib/cli_funcs.rb', line 22 def flags_run @flags_all end |
#run_and_capture(*args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/cli_funcs.rb', line 35 def run_and_capture(*args) args.flatten! begin puts "Args: #{args}" if DEBUG stdin, stdout_and_stderr, wait_thr = Open3.popen2e(*args) if(wait_thr.value.exitstatus != 0 unless @ignore_bad_exit) stdout_and_stderr.each do |line| puts line end raise "Ran #{args} and command with pid #{wait_thr.value.to_i} exited #{wait_thr.value.exitstatus}, error above." end stdout_and_stderr.each do |line| @output.push(line) p line if DEBUG end rescue Exception => e puts "Tried to run command: #{args[0, args.size]}, received exception: #{e}" end end |
#set_dirs ⇒ Object
17 18 19 20 |
# File 'lib/cli_funcs.rb', line 17 def set_dirs @base_dir = SYSTEM_CONFIG["base_dir"] @data_dir = SYSTEM_CONFIG["data_dir"] end |