feat: Implemented sync command.

This commit is contained in:
2025-10-28 17:02:49 -04:00
parent 7604454b74
commit 1a3634ba84
2 changed files with 11 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
## TODOS
- [ ] `envr sync` - Restore missing .env files, and update backed up ones.
- [x] `envr sync` - Restore missing .env files, and update backed up ones.
- [x] `envr scan` - Search for missing / moved .env files.

17
mod.nu
View File

@@ -177,7 +177,6 @@ export def "envr init" [
source: $source
priv_key: $identity
pub_key: $'($identity).pub'
# TODO: scan settings
scan: {
matcher: '\.env'
exclude: '*.envrc'
@@ -209,17 +208,21 @@ def files [] {
)
}
# Update your env backups
# Update or restore your env backups
export def "envr sync" [] {
let $files = (files);
$files | each { |it|
# TODO: Check for file existence
# TODO: If file exists and sha changed: `envr backup $it.path`
# TODO: If file doesn't exist: `envr restore $it.path`
if ($it.path | path type | $in == 'file') {
if (open $it.path | hash sha256 | $in != $it.sha256) {
envr backup $it.path
} else {
'Nothing to do!'
}
} else {
envr restore $it.path
}
}
'TODO: Need to implement'
}
# Search for .env files and select ones to back up.