mod: added basic logging + context in sub libs
Signed-off-by: Sam Alba <samalba@users.noreply.github.com>
This commit is contained in:
parent
d34bd86d99
commit
779dda1aca
@ -38,13 +38,13 @@ var getCmd = &cobra.Command{
|
|||||||
var err error
|
var err error
|
||||||
if update && len(args) == 0 {
|
if update && len(args) == 0 {
|
||||||
lg.Info().Msg("updating all installed packages...")
|
lg.Info().Msg("updating all installed packages...")
|
||||||
processedRequires, err = mod.UpdateInstalled(project.Path)
|
processedRequires, err = mod.UpdateInstalled(ctx, project.Path)
|
||||||
} else if update && len(args) > 0 {
|
} else if update && len(args) > 0 {
|
||||||
lg.Info().Msg("updating specified packages...")
|
lg.Info().Msg("updating specified packages...")
|
||||||
processedRequires, err = mod.UpdateAll(project.Path, args)
|
processedRequires, err = mod.UpdateAll(ctx, project.Path, args)
|
||||||
} else if !update && len(args) > 0 {
|
} else if !update && len(args) > 0 {
|
||||||
lg.Info().Msg("installing specified packages...")
|
lg.Info().Msg("installing specified packages...")
|
||||||
processedRequires, err = mod.InstallAll(project.Path, args)
|
processedRequires, err = mod.InstallAll(ctx, project.Path, args)
|
||||||
} else {
|
} else {
|
||||||
lg.Fatal().Msg("unrecognized update/install operation")
|
lg.Fatal().Msg("unrecognized update/install operation")
|
||||||
}
|
}
|
||||||
|
24
mod/mod.go
24
mod/mod.go
@ -1,12 +1,17 @@
|
|||||||
package mod
|
package mod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/gofrs/flock"
|
"github.com/gofrs/flock"
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Install(workspace, repoName, versionConstraint string) (*Require, error) {
|
func Install(ctx context.Context, workspace, repoName, versionConstraint string) (*Require, error) {
|
||||||
|
lg := log.Ctx(ctx)
|
||||||
|
|
||||||
|
lg.Info().Str("name", repoName).Msg("installing module")
|
||||||
require, err := newRequire(repoName, versionConstraint)
|
require, err := newRequire(repoName, versionConstraint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -38,14 +43,14 @@ func Install(workspace, repoName, versionConstraint string) (*Require, error) {
|
|||||||
return require, nil
|
return require, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func InstallAll(workspace string, repoNames []string) ([]*Require, error) {
|
func InstallAll(ctx context.Context, workspace string, repoNames []string) ([]*Require, error) {
|
||||||
installedRequires := make([]*Require, 0, len(repoNames))
|
installedRequires := make([]*Require, 0, len(repoNames))
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for _, repoName := range repoNames {
|
for _, repoName := range repoNames {
|
||||||
var require *Require
|
var require *Require
|
||||||
|
|
||||||
if require, err = Install(workspace, repoName, ""); err != nil {
|
if require, err = Install(ctx, workspace, repoName, ""); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +60,10 @@ func InstallAll(workspace string, repoNames []string) ([]*Require, error) {
|
|||||||
return installedRequires, err
|
return installedRequires, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func Update(workspace, repoName, versionConstraint string) (*Require, error) {
|
func Update(ctx context.Context, workspace, repoName, versionConstraint string) (*Require, error) {
|
||||||
|
lg := log.Ctx(ctx)
|
||||||
|
|
||||||
|
lg.Info().Str("name", repoName).Msg("updating module")
|
||||||
require, err := newRequire(repoName, versionConstraint)
|
require, err := newRequire(repoName, versionConstraint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -87,14 +95,14 @@ func Update(workspace, repoName, versionConstraint string) (*Require, error) {
|
|||||||
return updatedRequire, nil
|
return updatedRequire, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateAll(workspace string, repoNames []string) ([]*Require, error) {
|
func UpdateAll(ctx context.Context, workspace string, repoNames []string) ([]*Require, error) {
|
||||||
updatedRequires := make([]*Require, 0, len(repoNames))
|
updatedRequires := make([]*Require, 0, len(repoNames))
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
for _, repoName := range repoNames {
|
for _, repoName := range repoNames {
|
||||||
var require *Require
|
var require *Require
|
||||||
|
|
||||||
if require, err = Update(workspace, repoName, ""); err != nil {
|
if require, err = Update(ctx, workspace, repoName, ""); err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,7 +112,7 @@ func UpdateAll(workspace string, repoNames []string) ([]*Require, error) {
|
|||||||
return updatedRequires, err
|
return updatedRequires, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateInstalled(workspace string) ([]*Require, error) {
|
func UpdateInstalled(ctx context.Context, workspace string) ([]*Require, error) {
|
||||||
modfile, err := readPath(workspace)
|
modfile, err := readPath(workspace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -116,7 +124,7 @@ func UpdateInstalled(workspace string) ([]*Require, error) {
|
|||||||
repoNames = append(repoNames, require.String())
|
repoNames = append(repoNames, require.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
return UpdateAll(workspace, repoNames)
|
return UpdateAll(ctx, workspace, repoNames)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Ensure(workspace string) error {
|
func Ensure(workspace string) error {
|
||||||
|
@ -398,7 +398,7 @@ func vendorUniverse(ctx context.Context, p string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.Ctx(ctx).Debug().Str("mod", p).Msg("vendoring universe")
|
log.Ctx(ctx).Debug().Str("mod", p).Msg("vendoring universe")
|
||||||
if _, err := mod.Install(p, "alpha.dagger.io", universeVersionConstraint); err != nil {
|
if _, err := mod.Install(ctx, p, "alpha.dagger.io", universeVersionConstraint); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user