10 changed files with 393 additions and 27 deletions
@ -0,0 +1,49 @@ |
|||||||
|
# Dry-Run Mode |
||||||
|
|
||||||
|
## Summary |
||||||
|
|
||||||
|
Add `--dry-run` flag to simulate the sync operation without making any changes |
||||||
|
to the system. Shows what packages would be installed and what would be removed. |
||||||
|
|
||||||
|
## Motivation |
||||||
|
|
||||||
|
Users want to preview the effects of a sync operation before committing changes. |
||||||
|
This is useful for: |
||||||
|
- Verifying the intended changes are correct |
||||||
|
- Avoiding unintended package installations |
||||||
|
- Understanding what orphan cleanup will remove |
||||||
|
|
||||||
|
## Interface |
||||||
|
|
||||||
|
``` |
||||||
|
declpac --dry-run --state packages.txt |
||||||
|
``` |
||||||
|
|
||||||
|
## Behavior |
||||||
|
|
||||||
|
1. Read state files and stdin (same as normal mode) |
||||||
|
2. Validate packages exist (same as normal mode) |
||||||
|
3. Query current installed packages via `pacman -Qq` |
||||||
|
4. Compare declared packages to current state |
||||||
|
5. Identify packages that would be installed (not currently installed) |
||||||
|
6. Identify orphans that would be removed via `pacman -Qdtq` |
||||||
|
7. Output results with "Would install:" and "Would remove:" sections |
||||||
|
|
||||||
|
## Output Format |
||||||
|
|
||||||
|
``` |
||||||
|
Installed 3 packages, removed 2 packages |
||||||
|
Would install: vim, git, docker |
||||||
|
Would remove: python2, perl-xml-parser |
||||||
|
``` |
||||||
|
|
||||||
|
## Non-Goals |
||||||
|
|
||||||
|
- Actual package operations (no pacman -Syu, no pacman -Rns execution) |
||||||
|
- Package version comparison |
||||||
|
- Detailed dependency analysis |
||||||
|
|
||||||
|
## Trade-offs |
||||||
|
|
||||||
|
- Doesn't predict transitive dependencies that pacman might install |
||||||
|
- Orphan list may change after packages are installed |
||||||
@ -1,12 +1,27 @@ |
|||||||
package output |
package output |
||||||
|
|
||||||
import "fmt" |
import ( |
||||||
|
"fmt" |
||||||
|
"strings" |
||||||
|
) |
||||||
|
|
||||||
type Result struct { |
type Result struct { |
||||||
Installed int |
Installed int |
||||||
Removed int |
Removed int |
||||||
|
ToInstall []string |
||||||
|
ToRemove []string |
||||||
} |
} |
||||||
|
|
||||||
func Format(r *Result) string { |
func Format(r *Result) string { |
||||||
return fmt.Sprintf("Installed %d packages, removed %d packages", r.Installed, r.Removed) |
var b strings.Builder |
||||||
|
b.WriteString(fmt.Sprintf("Installed %d packages, removed %d packages", r.Installed, r.Removed)) |
||||||
|
if len(r.ToInstall) > 0 { |
||||||
|
b.WriteString("\nWould install: ") |
||||||
|
b.WriteString(strings.Join(r.ToInstall, ", ")) |
||||||
|
} |
||||||
|
if len(r.ToRemove) > 0 { |
||||||
|
b.WriteString("\nWould remove: ") |
||||||
|
b.WriteString(strings.Join(r.ToRemove, ", ")) |
||||||
|
} |
||||||
|
return b.String() |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue