Module: Arli::Helpers::SystemCommands
Constant Summary
Constants included
from Output
Output::CHAR_FAILURE, Output::CHAR_SUCCESS
Instance Method Summary
collapse
Methods included from Output
#___, #__p, #__pf, #__pt, #abort?, #action_fail, #action_ok, #backup?, #cursor, #debug, #debug?, disable!, enable!, enabled?, #error, #fuck, #header, #hr, #indent_cursor, #info, #ok, #overwrite?, #print_action_failure, #print_action_starting, #print_action_success, #print_target_dir, #quiet?, #raise_invalid_arli_command!, #report_exception, #verbose?
Instance Method Details
#backup!(p) ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/arli/helpers/system_commands.rb', line 21
def backup!(p)
if Dir.exist?(p)
backup_path = "#{p}.arli-backup-#{Time.now.strftime('%Y%m%d%H%M%S')}"
FileUtils.mv(p, backup_path)
print_target_dir(backup_path, 'backed up')
if verbose?
___ "\nNOTE: path #{p.blue} has been backed up to #{backup_path.bold.green}\n"
end
end
end
|
#handle_preexisting_folder(to) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/arli/helpers/system_commands.rb', line 9
def handle_preexisting_folder(to)
if Dir.exist?(to)
if abort?
raise ::Arli::Errors::LibraryAlreadyExists, "Directory #{to} already exists"
elsif backup?
backup!(to)
elsif overwrite?
FileUtils.rm_rf(to)
end
end
end
|
#run_system_command(*args) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/arli/helpers/system_commands.rb', line 33
def run_system_command(*args)
cmd = args.join(' ')
raise 'No command to run was given' unless cmd
info("\n" + cmd.green) if Arli.debug?
o, e, s = Open3.capture3(cmd)
info("\n" + o) if o if Arli.debug?
info("\n" + e.red) if e && Arli.debug?
return o, e, s
rescue Exception => e
error "Error running [#{args.join(' ')}]\n" +
"Current folder is [#{Dir.pwd.yellow}]", e
raise e
end
|