Skip to content

Commit cd8cff9

Browse files
committed
update logs
1 parent fde6c11 commit cd8cff9

File tree

10 files changed

+58
-71
lines changed

10 files changed

+58
-71
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ LOCAL_BIN:=$(CURDIR)/bin
2424

2525
# Linter config.
2626
GOLANGCI_BIN:=$(LOCAL_BIN)/golangci-lint
27-
GOLANGCI_TAG:=1.61.0
27+
GOLANGCI_TAG:=1.64.5
2828

2929
.PHONY: all
3030
all: deps test build

compose/builder.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ import (
1111

1212
"github.com/go-git/go-git/v5"
1313
"github.com/go-git/go-git/v5/plumbing/object"
14-
"github.com/stevenle/topsort"
15-
1614
"github.com/launchrctl/launchr/pkg/action"
15+
"github.com/stevenle/topsort"
1716
)
1817

1918
const (
@@ -123,8 +122,8 @@ func identifyStrategy(name string) (mergeStrategyType, mergeStrategyTarget) {
123122

124123
// Builder struct, provides methods to merge packages into build
125124
type Builder struct {
126-
withLogger action.WithLogger
127-
withTerm action.WithTerm
125+
action.WithLogger
126+
action.WithTerm
128127

129128
platformDir string
130129
targetDir string
@@ -144,8 +143,8 @@ type fsEntry struct {
144143

145144
func createBuilder(c *Composer, targetDir, sourceDir string, packages []*Package) *Builder {
146145
return &Builder{
147-
c.withLogger,
148-
c.withTerm,
146+
c.WithLogger,
147+
c.WithTerm,
149148
c.pwd,
150149
targetDir,
151150
sourceDir,
@@ -182,7 +181,7 @@ func getVersionedMap(gitDir string) (map[string]bool, error) {
182181
}
183182

184183
func (b *Builder) build(ctx context.Context) error {
185-
b.withTerm.Term().Println("Creating composition...")
184+
b.Term().Println("Creating composition...")
186185
err := EnsureDirExists(b.targetDir)
187186
if err != nil {
188187
return err
@@ -258,7 +257,7 @@ func (b *Builder) build(ctx context.Context) error {
258257
targetsMap := getTargetsMap(b.packages)
259258

260259
if b.logConflicts {
261-
b.withTerm.Term().Info().Printf("Conflicting files:\n")
260+
b.Term().Info().Printf("Conflicting files:\n")
262261
}
263262

264263
for i := 0; i < len(items); i++ {
@@ -350,7 +349,7 @@ func (b *Builder) logConflictResolve(resolveto mergeConflictResolve, path, pkgNa
350349
return
351350
}
352351

353-
b.withTerm.Term().Info().Printfln("[%s] - %s > Selected from %s", pkgName, path, entry.From)
352+
b.Term().Info().Printfln("[%s] - %s > Selected from %s", pkgName, path, entry.From)
354353
}
355354

356355
func getTargetsMap(packages []*Package) map[string]string {

compose/compose.go

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ import (
1010
"syscall"
1111

1212
"github.com/launchrctl/keyring"
13-
14-
"github.com/launchrctl/launchr"
1513
"github.com/launchrctl/launchr/pkg/action"
1614
)
1715

1816
const (
19-
MainDir = ".compose" // MainDir is a compose directory.
20-
BuildDir = MainDir + "/build" // BuildDir is a result directory of compose action.
17+
// MainDir is a compose directory.
18+
MainDir = ".compose"
19+
// BuildDir is a result directory of compose action.
20+
BuildDir = MainDir + "/build"
2121
composeFile = "plasma-compose.yaml"
2222
dirPermissions = 0755
2323
)
@@ -42,7 +42,7 @@ func (kw *keyringWrapper) getForURL(url string) (keyring.CredentialsItem, error)
4242
if errors.Is(errGet, keyring.ErrEmptyPass) {
4343
return ci, errGet
4444
} else if !errors.Is(errGet, keyring.ErrNotFound) {
45-
kw.WithLogger.Log().Debug(errGet.Error())
45+
kw.Log().Debug(errGet.Error())
4646
return ci, errors.New("the keyring is malformed or wrong passphrase provided")
4747
}
4848

@@ -70,7 +70,7 @@ func (kw *keyringWrapper) getForURL(url string) (keyring.CredentialsItem, error)
7070

7171
func (kw *keyringWrapper) fillCredentials(ci keyring.CredentialsItem) (keyring.CredentialsItem, error) {
7272
if ci.URL != "" {
73-
kw.WithTerm.Term().Printfln("Please add login and password for URL - %s", ci.URL)
73+
kw.Term().Printfln("Please add login and password for URL - %s", ci.URL)
7474
}
7575
err := keyring.RequestCredentialsFromTty(&ci)
7676
if err != nil {
@@ -82,8 +82,8 @@ func (kw *keyringWrapper) fillCredentials(ci keyring.CredentialsItem) (keyring.C
8282

8383
// Composer stores compose definition
8484
type Composer struct {
85-
withLogger action.WithLogger
86-
withTerm action.WithTerm
85+
action.WithLogger
86+
action.WithTerm
8787

8888
pwd string
8989
options *ComposerOptions
@@ -110,16 +110,6 @@ func CreateComposer(pwd string, opts ComposerOptions, k keyring.Keyring) (*Compo
110110
return &Composer{pwd: pwd, options: &opts, compose: config, k: k}, nil
111111
}
112112

113-
// SetLogger sets logger for composer.
114-
func (c *Composer) SetLogger(logger *launchr.Logger) {
115-
c.withLogger.SetLogger(logger)
116-
}
117-
118-
// SetTerm sets terminal for composer.
119-
func (c *Composer) SetTerm(term *launchr.Terminal) {
120-
c.withTerm.SetTerm(term)
121-
}
122-
123113
// RunInstall on Composer
124114
func (c *Composer) RunInstall() error {
125115
ctx, cancel := context.WithCancel(context.Background())
@@ -129,7 +119,7 @@ func (c *Composer) RunInstall() error {
129119

130120
go func() {
131121
<-signalChan
132-
c.withTerm.Term().Printfln("\nTermination signal received. Cleaning up...")
122+
c.Term().Printfln("\nTermination signal received. Cleaning up...")
133123
// cleanup dir
134124
_, _, _ = c.prepareInstall(false)
135125

@@ -150,8 +140,8 @@ func (c *Composer) RunInstall() error {
150140
shouldUpdate: false,
151141
interactive: c.options.Interactive,
152142
}
153-
kw.WithLogger = c.withLogger
154-
kw.WithTerm = c.withTerm
143+
kw.SetLogger(c.Log())
144+
kw.SetTerm(c.Term())
155145
dm := CreateDownloadManager(kw)
156146
packages, err := dm.Download(ctx, c.getCompose(), packagesDir)
157147
if err != nil {
@@ -171,21 +161,21 @@ func (c *Composer) RunInstall() error {
171161
func (c *Composer) prepareInstall(clean bool) (string, string, error) {
172162
for _, dep := range c.compose.Dependencies {
173163
if dep.Source.Tag != "" {
174-
c.withTerm.Term().Warning().Printfln("found deprecated field `tag` in `%s` dependency. Use `ref` field for tags or branches.", dep.Name)
164+
c.Term().Warning().Printfln("found deprecated field `tag` in `%s` dependency. Use `ref` field for tags or branches.", dep.Name)
175165
}
176166
}
177167

178168
buildPath := c.getPath(BuildDir)
179169
packagesPath := c.getPath(c.options.WorkingDir)
180170

181-
c.withTerm.Term().Printfln("Cleaning build dir: %s", BuildDir)
171+
c.Term().Printfln("Cleaning build dir: %s", BuildDir)
182172
err := os.RemoveAll(buildPath)
183173
if err != nil {
184174
return "", "", err
185175
}
186176

187177
if clean {
188-
c.withTerm.Term().Printfln("Cleaning packages dir: %s", packagesPath)
178+
c.Term().Printfln("Cleaning packages dir: %s", packagesPath)
189179
err = os.RemoveAll(packagesPath)
190180
if err != nil {
191181
return "", "", err

compose/downloadManager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (m DownloadManager) downloadPackage(ctx context.Context, pkg *Package, targ
140140
if err != nil {
141141
errRemove := os.RemoveAll(downloadPath)
142142
if errRemove != nil {
143-
m.kw.WithLogger.Log().Debug("error cleaning package folder", "path", downloadPath, "err", err)
143+
m.kw.Log().Debug("error cleaning package folder", "path", downloadPath, "err", err)
144144
}
145145
}
146146

compose/forms.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99

1010
"dario.cat/mergo"
1111
"github.com/charmbracelet/huh"
12-
1312
"github.com/launchrctl/launchr/pkg/action"
1413
)
1514

@@ -80,7 +79,7 @@ func (f *FormsAction) AddPackage(doCreate bool, newDependency *Dependency, rawSt
8079

8180
sanitizeDependency(newDependency)
8281
config.Dependencies = append(config.Dependencies, *newDependency)
83-
f.WithTerm.Term().Println("Saving plasma-compose...")
82+
f.Term().Println("Saving plasma-compose...")
8483
sortPackages(config)
8584
err = writeComposeYaml(config)
8685

@@ -121,7 +120,7 @@ func (f *FormsAction) UpdatePackage(dependency *Dependency, rawStrategies *RawSt
121120
}
122121

123122
sanitizeDependency(toUpdate)
124-
f.WithTerm.Term().Println("Saving plasma-compose...")
123+
f.Term().Println("Saving plasma-compose...")
125124
sortPackages(config)
126125
err = writeComposeYaml(config)
127126

@@ -185,7 +184,7 @@ func (f *FormsAction) UpdatePackages(dir string) error {
185184
}
186185
}
187186

188-
f.WithTerm.Term().Println("Saving plasma-compose...")
187+
f.Term().Println("Saving plasma-compose...")
189188
var newDeps []Dependency
190189
for _, dep := range packagesMap {
191190
newDeps = append(newDeps, *dep)
@@ -245,12 +244,12 @@ OUTER:
245244
}
246245

247246
if saveRequired {
248-
f.WithTerm.Term().Println("Updating plasma-compose...")
247+
f.Term().Println("Updating plasma-compose...")
249248
config.Dependencies = dependencies
250249
sortPackages(config)
251250
err = writeComposeYaml(config)
252251
} else {
253-
f.WithTerm.Term().Println("Nothing to update, quiting")
252+
f.Term().Println("Nothing to update, quiting")
254253
}
255254

256255
return err

compose/git.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (g *gitDownloader) fetchRemotes(r *git.Repository, url string, refSpec []co
2929
return errR
3030
}
3131

32-
g.k.WithTerm.Term().Printfln("Fetching remote %s", url)
32+
g.k.Term().Printfln("Fetching remote %s", url)
3333
for _, rem := range remotes {
3434
options := git.FetchOptions{
3535
//RefSpecs: []config.RefSpec{"refs/*:refs/*", "HEAD:refs/heads/HEAD"},
@@ -69,7 +69,7 @@ func (g *gitDownloader) fetchRemotes(r *git.Repository, url string, refSpec []co
6969
if err != nil {
7070
if errors.Is(err, transport.ErrAuthorizationFailed) || errors.Is(err, transport.ErrAuthenticationRequired) {
7171
if g.k.interactive {
72-
g.k.WithTerm.Term().Println("invalid auth, trying manual authorisation")
72+
g.k.Term().Println("invalid auth, trying manual authorisation")
7373
continue
7474
}
7575
}
@@ -129,13 +129,13 @@ func (g *gitDownloader) EnsureLatest(pkg *Package, downloadPath string) (bool, e
129129

130130
r, err := git.PlainOpen(downloadPath)
131131
if err != nil {
132-
g.k.WithLogger.Log().Debug("git init error", "err", err)
132+
g.k.Log().Debug("git init error", "err", err)
133133
return false, nil
134134
}
135135

136136
head, err := r.Head()
137137
if err != nil {
138-
g.k.WithLogger.Log().Debug("get head error", "err", err)
138+
g.k.Log().Debug("get head error", "err", err)
139139
return false, fmt.Errorf("can't get HEAD of '%s', ensure package is valid", pkg.GetName())
140140
}
141141

@@ -154,22 +154,22 @@ func (g *gitDownloader) EnsureLatest(pkg *Package, downloadPath string) (bool, e
154154
pullTarget = "branch"
155155
isLatest, err = g.ensureLatestBranch(r, pkg.GetURL(), pkgRefName, remoteRefName)
156156
if err != nil {
157-
g.k.WithTerm.Term().Warning().Printfln("Couldn't check local branch, marking package %s(%s) as outdated, see debug for detailed error.", pkg.GetName(), pkgRefName)
158-
g.k.WithLogger.Log().Debug("ensure branch error", "err", err)
157+
g.k.Term().Warning().Printfln("Couldn't check local branch, marking package %s(%s) as outdated, see debug for detailed error.", pkg.GetName(), pkgRefName)
158+
g.k.Log().Debug("ensure branch error", "err", err)
159159
return isLatest, nil
160160
}
161161
} else {
162162
pullTarget = "tag"
163163
isLatest, err = g.ensureLatestTag(r, pkg.GetURL(), pkgRefName)
164164
if err != nil {
165-
g.k.WithTerm.Term().Warning().Printfln("Couldn't check local tag, marking package %s(%s) as outdated, see debug for detailed error.", pkg.GetName(), pkgRefName)
166-
g.k.WithLogger.Log().Debug("ensure tag error", "err", err)
165+
g.k.Term().Warning().Printfln("Couldn't check local tag, marking package %s(%s) as outdated, see debug for detailed error.", pkg.GetName(), pkgRefName)
166+
g.k.Log().Debug("ensure tag error", "err", err)
167167
return isLatest, nil
168168
}
169169
}
170170

171171
if !isLatest {
172-
g.k.WithTerm.Term().Info().Printfln("Pulling new changes from %s '%s' of %s package", pullTarget, pkgRefName, pkg.GetName())
172+
g.k.Term().Info().Printfln("Pulling new changes from %s '%s' of %s package", pullTarget, pkgRefName, pkg.GetName())
173173
}
174174

175175
return isLatest, nil
@@ -242,7 +242,7 @@ func (g *gitDownloader) ensureLatestTag(r *git.Repository, fetchURL, refName str
242242

243243
// Download implements Downloader.Download interface
244244
func (g *gitDownloader) Download(ctx context.Context, pkg *Package, targetDir string) error {
245-
g.k.WithTerm.Term().Printfln("git fetch: %s", pkg.GetURL())
245+
g.k.Term().Printfln("git fetch: %s", pkg.GetURL())
246246

247247
url := pkg.GetURL()
248248
if url == "" {
@@ -303,10 +303,10 @@ func (g *gitDownloader) tryDownload(ctx context.Context, targetDir string, optio
303303
for _, authType := range auths {
304304
if authType == authorisationNone {
305305
_, err := git.PlainCloneContext(ctx, targetDir, false, options)
306-
g.k.WithTerm.Term().Println("")
306+
g.k.Term().Println("")
307307
if err != nil {
308308
if errors.Is(err, transport.ErrAuthenticationRequired) {
309-
g.k.WithTerm.Term().Println("auth required, trying keyring authorisation")
309+
g.k.Term().Println("auth required, trying keyring authorisation")
310310
continue
311311
}
312312

@@ -329,7 +329,7 @@ func (g *gitDownloader) tryDownload(ctx context.Context, targetDir string, optio
329329
if err != nil {
330330
if errors.Is(err, transport.ErrAuthorizationFailed) || errors.Is(err, transport.ErrAuthenticationRequired) {
331331
if g.k.interactive {
332-
g.k.WithTerm.Term().Println("invalid auth, trying manual authorisation")
332+
g.k.Term().Println("invalid auth, trying manual authorisation")
333333
continue
334334
}
335335
}

compose/http.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (h *httpDownloader) Download(_ context.Context, pkg *Package, targetDir str
5858
return errNoURL
5959
}
6060

61-
h.k.WithTerm.Term().Printfln("http download: %s", name)
61+
h.k.Term().Printfln("http download: %s", name)
6262
fpath := filepath.Clean(filepath.Join(targetDir, name))
6363

6464
err := os.MkdirAll(targetDir, dirPermissions)
@@ -73,7 +73,7 @@ func (h *httpDownloader) Download(_ context.Context, pkg *Package, targetDir str
7373

7474
defer func() {
7575
if err = out.Close(); err != nil {
76-
h.k.WithLogger.Log().Debug(errFailedClose.Error())
76+
h.k.Log().Debug(errFailedClose.Error())
7777
}
7878
}()
7979

@@ -93,11 +93,11 @@ func (h *httpDownloader) Download(_ context.Context, pkg *Package, targetDir str
9393
resp, err = doRequest(client, req)
9494
if err != nil {
9595
if errors.Is(err, errAuthenticationRequired) {
96-
h.k.WithTerm.Term().Println("auth required, trying keyring authorisation")
96+
h.k.Term().Println("auth required, trying keyring authorisation")
9797
continue
9898
}
9999

100-
h.k.WithLogger.Log().Debug(err.Error())
100+
h.k.Log().Debug(err.Error())
101101
return errDownloadFailed
102102
}
103103
}
@@ -113,12 +113,12 @@ func (h *httpDownloader) Download(_ context.Context, pkg *Package, targetDir str
113113
if err != nil {
114114
if errors.Is(err, errAuthorizationFailed) {
115115
if h.k.interactive {
116-
h.k.WithTerm.Term().Println("invalid auth, trying manual authorisation")
116+
h.k.Term().Println("invalid auth, trying manual authorisation")
117117
continue
118118
}
119119
}
120120

121-
h.k.WithLogger.Log().Debug(err.Error())
121+
h.k.Log().Debug(err.Error())
122122
return errDownloadFailed
123123
}
124124
}
@@ -134,7 +134,7 @@ func (h *httpDownloader) Download(_ context.Context, pkg *Package, targetDir str
134134
req.SetBasicAuth(ci.Username, ci.Password)
135135
resp, err = doRequest(client, req)
136136
if err != nil {
137-
h.k.WithLogger.Log().Debug(err.Error())
137+
h.k.Log().Debug(err.Error())
138138
return errDownloadFailed
139139
}
140140
}
@@ -144,7 +144,7 @@ func (h *httpDownloader) Download(_ context.Context, pkg *Package, targetDir str
144144

145145
defer func() {
146146
if err = resp.Body.Close(); err != nil {
147-
h.k.WithLogger.Log().Debug(errFailedClose.Error())
147+
h.k.Log().Debug(errFailedClose.Error())
148148
}
149149
}()
150150

0 commit comments

Comments
 (0)