Skip to content

🛠️ UpdateWithOptions

Updates project dependencies using a custom option map. A flexible variant of Update.

When to use

Use this when the noDev parameter of Update is not enough and you need to combine multiple native Composer options such as --prefer-dist, --with-dependencies, --no-progress, --dry-run, etc.

Signature

go
func (c *Composer) UpdateWithOptions(packages []string, options map[string]string) error

Parameters

ParameterTypeDescription
packages[]stringList of package names to update; pass an empty slice to update all packages
optionsmap[string]stringUpdate option map; keys are option names (without --), values are option values; pass an empty string for boolean options

Return value

error: returns the corresponding error message when an error occurs during the update; nil on success.

Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("init failed: %v", err)
	}

	options := map[string]string{
		"no-dev":            "",
		"prefer-dist":       "",
		"with-dependencies": "",
		"no-progress":       "",
	}
	if err := comp.UpdateWithOptions([]string{"symfony/console"}, options); err != nil {
		log.Fatalf("update dependencies failed: %v", err)
	}

	fmt.Println("dependencies update complete")
}

Advanced

  • The option map is expanded in a deterministic order: options first, then package names, consistent with Composer CLI semantics.
  • For simple scenarios that only need --no-dev, Update is more straightforward.
  • For single-option shortcuts, see UpdateWithDependencies, UpdateWithLock, etc.
  • To simulate an update, see UpdateDryRun.

Released under the MIT License