Skip to content

🔧 SetWorkingDir

Sets the working directory for Composer commands; all subsequent commands will be executed in that directory.

When to use

Use this when you need to switch between multiple project directories, or run Composer operations in a directory other than the current one. You can also dynamically adjust the working directory after an instance is created, avoiding the need to rebuild the instance.

Signature

go
func (c *Composer) SetWorkingDir(dir string)

Parameters

ParameterTypeDescription
dirstringWorking directory path to set; absolute or relative paths are both accepted

Return value

This method has no return value.

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

	comp.SetWorkingDir("/path/to/php/project")
	fmt.Printf("current working directory: %s\n", comp.GetWorkingDir())
}

Advanced

  • You can also specify it once at construction time via Options.WorkingDir.
  • To read the current working directory, use GetWorkingDir.
  • To set environment variables, use SetEnv, commonly used to configure a proxy or COMPOSER_HOME.

Released under the MIT License