Skip to content

🛠️ SetPossiblePaths

Replaces the detector's internal list of Composer candidate paths.

When to Use

Use this when you know exactly which paths Composer should appear at (for example, a custom install directory, or a fixed path inside a container) and want to bypass the default platform path lookup logic. 📦

Signature

go
func (d *Detector) SetPossiblePaths(paths []string)

Parameters

ParameterTypeDescription
paths[]stringThe new candidate path list, which fully overrides the default paths

Return Value

No return value.

Example

go
package main

import (
	"fmt"
	"log"

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

func main() {
	d := detector.NewDetector()
	// Only search in custom paths
	d.SetPossiblePaths([]string{
		"/data/composer/bin/composer",
		"/opt/composer/composer.phar",
	})
	path, err := d.Detect()
	if err != nil {
		log.Fatalf("not detected: %v", err)
	}
	fmt.Printf("hit: %s\n", path)
}

Advanced

  • This method has override semantics; to append on top of the default paths, use AddPossiblePath. ⚠️
  • The environment variables COMPOSER_PATH and COMPOSER_HOME still take priority over the paths set here. 🔒
  • Setting an empty slice is equivalent to clearing the candidate paths (but environment variables and the which fallback still take effect).

Released under the MIT License