Finished feature

This commit is contained in:
Tristan Ancelet 2024-05-25 21:53:20 -05:00
parent 3aae6b998a
commit 5232f2bebb

View File

@ -25,8 +25,13 @@ Actions:
list : List all Bucket entries
list-files : List all files/paths that have been backed up to the bucket
get <entry-hash> : Get the content of a specific entry (by hash)
restore <value> : Restore previous state of file stored in bucket. Value can be hash or filename/filepath
backup <file> : Backup the file to the bucket
restore <value> : Restore previous state of file stored in bucket. Value can be hash or filename/filepath
: Note: To restore to an alternate path you will need to provide the path via the -o flag
:
backup <file> : Backup the file to the bucket (will work relatively unless full path is provided)
Restore Flags:
-o | --output-file <file> : Used to provide an alternate restoral path for the restore function
Global Flags:
-d | --debug : Set debug flag
@ -187,6 +192,7 @@ $CONFIG[:puppet_version]=` #{puppet_exe} --version `
$CONFIG[:action]=""
$CONFIG[:search_term]=""
$CONFIG[:log_file]=""
$CONFIG[:alt_filepath]=""
$CONFIG[:info_format]="inline"
File.open('/etc/hostname') do |file|
$HOSTNAME=file.read().strip()
@ -250,6 +256,18 @@ while i < ARGV.count
$CONFIG[:info_format]='inline'
log "$CONFIG[:info_format] was set to #{$CONFIG[:info_format]}"
i+=1
when '-o', '--output-file'
log "user provided ARGV[i.next] == #{ARGV[i.next]}"
if ARGV[i.next] != "" and not ARGV[i.next] =~ FLAG_REGEX
$CONFIG[:alt_filepath]=ARGV[i.next]
log "search_term was set to #{ARGV[i.next]}"
i+=2
else
puts "Flag[#{ARGV[i]}] : Argument[#{ARGV[i.next]}] : Either the argument was not provided or it was a flag"
usage
exit
end
else
i+=1
end
@ -470,6 +488,10 @@ def restore_entry (bucket)
entry, filepath = get_entry_by_hash bucket
end
if $CONFIG[:alt_filepath] != ""
filepath=$CONFIG[:alt_filepath]
end
if get_verification "Are you sure you want to overwrite #{filepath}?"
File.open(filepath,'w') do |file|
file.write(entry.content)