This commit is contained in:
2025-04-13 20:22:32 +03:00
parent b8cb7af3bb
commit e3aaa88822
8 changed files with 139 additions and 109 deletions

View File

@ -53,6 +53,14 @@ func New(ctx context.Context) *AppBuilder {
return &AppBuilder{ctx: ctx}
}
func (b *AppBuilder) UseConfig(cfg *config.ALRConfig) *AppBuilder {
if b.err != nil {
return b
}
b.deps.Cfg = cfg
return b
}
func (b *AppBuilder) WithConfig() *AppBuilder {
if b.err != nil {
return b
@ -92,16 +100,21 @@ func (b *AppBuilder) WithDB() *AppBuilder {
}
func (b *AppBuilder) WithRepos() *AppBuilder {
b.withRepos(false)
b.withRepos(true, false)
return b
}
func (b *AppBuilder) WithReposForcePull() *AppBuilder {
b.withRepos(true)
b.withRepos(true, true)
return b
}
func (b *AppBuilder) withRepos(forcePull bool) *AppBuilder {
func (b *AppBuilder) WithReposNoPull() *AppBuilder {
b.withRepos(false, false)
return b
}
func (b *AppBuilder) withRepos(enablePull, forcePull bool) *AppBuilder {
if b.err != nil {
return b
}
@ -115,7 +128,7 @@ func (b *AppBuilder) withRepos(forcePull bool) *AppBuilder {
rs := repos.New(cfg, db)
if forcePull || cfg.AutoPull() {
if enablePull && (forcePull || cfg.AutoPull()) {
if err := rs.Pull(b.ctx, cfg.Repos()); err != nil {
slog.Error(gotext.Get("Error pulling repositories"), "err", err)
b.err = cli.Exit("", 1)

View File

@ -17,6 +17,7 @@
package cliutils
import (
"errors"
"fmt"
"log/slog"
@ -52,5 +53,8 @@ func FormatCliExit(msg string, err error) cli.ExitCoder {
}
func FormatCliExitWithCode(msg string, err error, exitCode int) cli.ExitCoder {
if err == nil {
return cli.Exit(errors.New(msg), exitCode)
}
return cli.Exit(fmt.Errorf("%s: %w", msg, err), exitCode)
}