mirror of
https://github.com/sbrow/envr.git
synced 2026-06-27 10:38:33 -04:00
chore: Cleaned up code.
This commit is contained in:
@@ -6,48 +6,50 @@ import "core:path/filepath"
|
||||
import "core:strings"
|
||||
|
||||
cmd_restore :: proc(cmd: ^Command) {
|
||||
if len(cmd.args) != 1 {
|
||||
if len(cmd.args) != 1 {
|
||||
print_command_help("restore")
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
path := cmd.args[0]
|
||||
if len(strings.trim_space(path)) == 0 {
|
||||
fmt.println("Error: No path provided")
|
||||
return
|
||||
}
|
||||
path := cmd.args[0]
|
||||
if len(strings.trim_space(path)) == 0 {
|
||||
fmt.println("Error: No path provided")
|
||||
return
|
||||
}
|
||||
|
||||
abs_path: string
|
||||
if filepath.is_abs(path) {
|
||||
abs_path = path
|
||||
} else {
|
||||
resolved, abs_err := filepath.abs(path)
|
||||
if abs_err != nil {
|
||||
fmt.printf("Error getting absolute path: %v\n", abs_err)
|
||||
return
|
||||
}
|
||||
abs_path = resolved
|
||||
}
|
||||
// TODO: Is this the right way to handle this?
|
||||
abs_path: string
|
||||
if filepath.is_abs(path) {
|
||||
abs_path = path
|
||||
} else {
|
||||
resolved, abs_err := filepath.abs(path)
|
||||
if abs_err != nil {
|
||||
fmt.printf("Error getting absolute path: %v\n", abs_err)
|
||||
return
|
||||
}
|
||||
abs_path = resolved
|
||||
}
|
||||
|
||||
db, db_ok := db_open(cmd.config_path)
|
||||
if !db_ok {
|
||||
return
|
||||
}
|
||||
defer db_close(&db)
|
||||
db, db_ok := db_open(cmd.config_path)
|
||||
if !db_ok {
|
||||
return
|
||||
}
|
||||
defer db_close(&db)
|
||||
|
||||
file, fetch_ok := db_fetch(&db, abs_path)
|
||||
if !fetch_ok {
|
||||
return
|
||||
}
|
||||
file, fetch_ok := db_fetch(&db, abs_path)
|
||||
if !fetch_ok {
|
||||
return
|
||||
}
|
||||
|
||||
dir := filepath.dir(file.Path)
|
||||
os.mkdir_all(dir)
|
||||
dir := filepath.dir(file.Path)
|
||||
os.mkdir_all(dir)
|
||||
|
||||
write_err := os.write_entire_file(file.Path, file.contents)
|
||||
if write_err != nil {
|
||||
fmt.printf("Error writing file: %v\n", write_err)
|
||||
return
|
||||
}
|
||||
write_err := os.write_entire_file(file.Path, file.contents)
|
||||
if write_err != nil {
|
||||
fmt.printf("Error writing file: %v\n", write_err)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.printf("Restored %s\n", file.Path)
|
||||
fmt.printf("Restored %s\n", file.Path)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user