Class: CliFuncs

Inherits:
Object
  • Object
show all
Defined in:
lib/cli_funcs.rb

Direct Known Subclasses

Cpio, Rpm, Rpm2Cpio, Rsync

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCliFuncs

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_dirObject

Returns the value of attribute base_dir.



5
6
7
# File 'lib/cli_funcs.rb', line 5

def base_dir
  @base_dir
end

#data_dirObject

Returns the value of attribute data_dir.



5
6
7
# File 'lib/cli_funcs.rb', line 5

def data_dir
  @data_dir
end

#flags_allObject

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_exitObject

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

#outputObject (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_valuesObject



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_runObject



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_dirsObject



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