Skip to content

Commit

Permalink
Merge pull request #147 from criteo/update-cmd-with-extra-sources
Browse files Browse the repository at this point in the history
Update cmd with extra sources
  • Loading branch information
bhou-crto authored Jan 6, 2025
2 parents 4eca830 + 44226c8 commit 240c781
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func addBuiltinCommands() {
AddVersionCmd(rootCmd, rootCtxt.appCtx)
AddConfigCmd(rootCmd, rootCtxt.appCtx)
AddLoginCmd(rootCmd, rootCtxt.appCtx, rootCtxt.backend.SystemCommand(repository.SYSTEM_LOGIN_COMMAND))
AddUpdateCmd(rootCmd, rootCtxt.appCtx, rootCtxt.backend.DefaultRepository())
AddUpdateCmd(rootCmd, rootCtxt.appCtx, rootCtxt.backend.DefaultRepository(), rootCtxt.backend.ExtraPackageSources()...)
AddCompletionCmd(rootCmd, rootCtxt.appCtx)
AddPackageCmd(rootCmd, rootCtxt.appCtx)
AddRenameCmd(rootCmd, rootCtxt.appCtx, rootCtxt.backend)
Expand Down
19 changes: 17 additions & 2 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"time"

"github.com/criteo/command-launcher/internal/backend"
"github.com/criteo/command-launcher/internal/config"
"github.com/criteo/command-launcher/internal/console"
"github.com/criteo/command-launcher/internal/context"
Expand All @@ -25,7 +26,7 @@ var (
updateFlags = UpdateFlags{}
)

func AddUpdateCmd(rootCmd *cobra.Command, appCtx context.LauncherContext, localRepo repository.PackageRepository) {
func AddUpdateCmd(rootCmd *cobra.Command, appCtx context.LauncherContext, localRepo repository.PackageRepository, extraPackageSources ...*backend.PackageSource) {
appName := appCtx.AppName()
updateCmd := &cobra.Command{
Use: "update",
Expand Down Expand Up @@ -83,7 +84,21 @@ Check the update of %s and its commands.
if err != nil {
console.Error(err.Error())
} else {
console.Success("packages are up-to-date")
console.Success("packages in 'default' repository are up-to-date")
}

// now update the packages in extra remote
for _, source := range extraPackageSources {
updater := source.InitUpdater(&u, updateFlags.Timeout, enableCI, packageLockFile, false, false)
// force sync policy to always, as the intention of running this command is to update the packages
updater.SyncPolicy = "always"
updater.CheckUpdateAsync()
err := updater.Update()
if err != nil {
console.Error(err.Error())
} else {
console.Success("packages in '%s' repository are up-to-date", source.Name)
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions internal/backend/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type Backend interface {
// Get all packages sources managed by this backend
AllPackageSources() []*PackageSource

// get extra package sources without counting the default and dropin
ExtraPackageSources() []*PackageSource

// Return all repositories or an empty slice
AllRepositories() []repository.PackageRepository

Expand Down
13 changes: 10 additions & 3 deletions internal/backend/default-backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ func (backend *DefaultBackend) loadRepos() error {
func (backend *DefaultBackend) loadAlias() error {
if renameFile, err := os.Open(filepath.Join(backend.homeDir, RENAME_FILE_NAME)); err == nil {
defer renameFile.Close()
if err != nil {
return fmt.Errorf("no such rename file found (%s)", err)
}

stat, err := renameFile.Stat()
if err != nil {
Expand Down Expand Up @@ -285,6 +282,16 @@ func (backend DefaultBackend) AllPackageSources() []*PackageSource {
return backend.sources
}

func (backend DefaultBackend) ExtraPackageSources() []*PackageSource {
extras := []*PackageSource{}
for i, src := range backend.sources {
if i != DEFAULT_REPO_INDEX && i != DROPIN_REPO_INDEX {
extras = append(extras, src)
}
}
return extras
}

func (backend DefaultBackend) AllRepositories() []repository.PackageRepository {
repos := []repository.PackageRepository{}
for _, src := range backend.sources {
Expand Down

0 comments on commit 240c781

Please sign in to comment.