Skip to content

🛠️ InstallWithOptions ​

Installs project dependencies using a custom option map; it is the flexible variant of Install.

When to use ​

Use this when the two boolean parameters of Install are not enough and you need to combine multiple native Composer options such as --prefer-dist, --no-scripts, --no-progress, or --classmap-authoritative.

Signature ​

go
func (c *Composer) InstallWithOptions(options map[string]string) error

Parameters ​

ParameterTypeDescription
optionsmap[string]stringInstall option map; keys are option names (without --), values are option values, and boolean options take an empty string

Return value ​

error: Returns the corresponding error message when an error occurs during installation; 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("Initialization failed: %v", err)
	}

	// Typical production combination
	options := map[string]string{
		"no-dev":               "",
		"optimize-autoloader":  "",
		"prefer-dist":          "",
		"no-progress":          "",
	}
	if err := comp.InstallWithOptions(options); err != nil {
		log.Fatalf("Failed to install dependencies: %v", err)
	}

	fmt.Println("Dependencies installed")
}

Advanced ​

  • The option map is expanded into command-line arguments in a deterministic order, so repeated calls produce reproducible results.
  • For simple scenarios that only need --no-dev / --optimize, Install is more straightforward.
  • For single-option convenience wrappers, see InstallWithPreferDist, InstallNoScripts, etc.
  • To simulate an install, see InstallDryRun.

Released under the MIT License