Skip to content

🚀 New

Creates a new Composer instance; the entry point for using the SDK. If the executable path is not specified, it auto-detects Composer on the system; if not found and AutoInstall is enabled, it installs it automatically.

When to use

In almost all scenarios, you first call New to obtain a *Composer instance, then call methods on it. It is typically used together with DefaultOptions.

Signature

go
func New(options Options) (*Composer, error)

Parameters

ParameterTypeDescription
optionsOptionsConfiguration, including executable path, working directory, auto-install flag, timeout, etc.

Return value

Return valueTypeDescription
First return value*ComposerThe created Composer instance
Second return valueerrorReturned when detection and auto-install both fail, or when the specified path does not exist

Example

go
package main

import (
	"fmt"
	"log"

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

func main() {
	options := composer.DefaultOptions()
	options.WorkingDir = "/path/to/project"
	comp, err := composer.New(options)
	if err != nil {
		log.Fatalf("init Composer failed: %v", err)
	}
	fmt.Printf("Composer ready: %s\n", comp.GetExecutablePath())
}

Advanced

  • To detect, install, and initialize in one line, use the more convenient QuickSetup.
  • To skip auto-install and only use Composer when already installed, set Options.AutoInstall to false.
  • After the instance is created, you can switch the working directory at any time with SetWorkingDir.

Released under the MIT License