Skip to content

Commit

Permalink
cli: Inject the OS StepWriter to the installer
Browse files Browse the repository at this point in the history
  • Loading branch information
livingsilver94 committed Nov 25, 2023
1 parent e28365b commit 5311a92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 7 additions & 1 deletion cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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."`
Expand Down Expand Up @@ -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),
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion cli/privilege.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down
9 changes: 5 additions & 4 deletions installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5311a92

Please sign in to comment.