From 5311a9241f949c925271f7ec872b023f4a77bc16 Mon Sep 17 00:00:00 2001 From: Fabio Forni Date: Fri, 24 Nov 2023 18:37:41 +0100 Subject: [PATCH] cli: Inject the OS StepWriter to the installer --- cli/install.go | 8 +++++++- cli/privilege.go | 2 +- installer/installer.go | 9 +++++---- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cli/install.go b/cli/install.go index b4b2ef7..49b3be1 100644 --- a/cli/install.go +++ b/cli/install.go @@ -10,6 +10,7 @@ import ( "strings" "github.com/livingsilver94/backee/installer" + "github.com/livingsilver94/backee/installer/stepwriter" "github.com/livingsilver94/backee/repo" "github.com/livingsilver94/backee/repo/solver" "github.com/livingsilver94/backee/service" @@ -22,6 +23,7 @@ type keepassXC struct { type install struct { Directory string `short:"C" type:"existingdir" help:"Change the base directory."` + DryRun bool `short:"d" help:"Test the installation without writing any file."` KeepassXC keepassXC `embed:"" prefix:"keepassxc."` PkgManager []string `name:"pkgmanager" help:"Override the package manager command for services."` Variant string `help:"Specify the system variant."` @@ -99,6 +101,10 @@ func (in *install) installer(rep repo.FS, fileList **os.File) installer.Installe } } + writ := installer.StepWriter(stepwriter.OS{}) + if in.DryRun { + writ = stepwriter.DryRun{} + } opts := []installer.Option{ installer.WithCommonVars(envVars()), installer.WithList(list), @@ -110,7 +116,7 @@ func (in *install) installer(rep repo.FS, fileList **os.File) installer.Installe installer.WithVarSolvers(map[service.VarKind]repo.VarSolver{"keepassxc": kee}), ) } - return installer.New(rep, opts...) + return installer.New(rep, writ, opts...) } // envVars returns a map of environment variables. diff --git a/cli/privilege.go b/cli/privilege.go index f380b42..a061b5b 100644 --- a/cli/privilege.go +++ b/cli/privilege.go @@ -6,7 +6,7 @@ package cli import ( "os" - _ "github.com/livingsilver94/backee/installer" + _ "github.com/livingsilver94/backee/installer/stepwriter" priv "github.com/livingsilver94/backee/privilege" ) diff --git a/installer/installer.go b/installer/installer.go index c2bfdd8..72d1701 100644 --- a/installer/installer.go +++ b/installer/installer.go @@ -13,17 +13,18 @@ import ( type Installer struct { repository repo.Repo - variables repo.Variables - list List writer StepWriter + + variables repo.Variables + list List } -func New(repository repo.Repo, options ...Option) Installer { +func New(repository repo.Repo, sw StepWriter, options ...Option) Installer { i := Installer{ repository: repository, + writer: sw, variables: repo.NewVariables(), list: NewList(), - writer: nil, // TODO: pass a real writer. } i.variables.RegisterSolver(service.Datadir, solver.NewDatadir(repository)) for _, option := range options {