Skip to content

🚀 SelfUpdate

Upgrades Composer itself to the latest version. Equivalent to running composer self-update.

When to use

Call this when a CI/CD pipeline or local script needs to ensure the latest Composer is used. After the upgrade, the version number is usually re-read to confirm; pair it with GetVersion.

Signature

go
func (c *Composer) SelfUpdate() error

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
Sole return valueerrorReturned when an error occurs during the upgrade

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)
	}

	if err := comp.SelfUpdate(); err != nil {
		log.Fatalf("update Composer failed: %v", err)
	}

	version, _ := comp.GetVersion()
	fmt.Printf("Composer updated to the latest version: %s\n", version)
}

Advanced

  • For an upgrade experience with a progress callback, use SelfUpdateWithProgress() (in auto_install.go).
  • To compare version numbers before and after the upgrade, combine with GetVersion or GetVersionInfo.
  • To roll back or pin a specific version, pass arguments such as self-update --rollback directly through Run.

Released under the MIT License