Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

14 flags #18

Closed
wants to merge 8 commits into from
40 changes: 18 additions & 22 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,43 @@ import (
"fmt"
"os"
"os/exec"
"strings"
"path/filepath"

"github.com/dasginganinja/drush-launcher/drushlauncher"
)

var drupalRoot string

func main() {
// Parse command-line flags
altRoot := ""
defaultRoot, _err := os.Getwd()

if _err != nil {
fmt.Println("Error getting current working directory:", _err)
os.Exit(1)
}

// Strip program name from arguments before looping
progArgs := os.Args[1:]

for i, arg := range progArgs {
// If we have -r or --root we will use the next argument as the drupal root (if exists)
if arg == "-r" || arg == "--root" {
if i+1 < len(progArgs) {
altRoot = progArgs[i+1]
defaultRoot = progArgs[i+1]
} else {
fmt.Println("Error: Missing value for root argument")
os.Exit(1)
}
} else if strings.HasPrefix(arg, "--root=") || strings.HasPrefix(arg, "-r=") {
defaultRoot = strings.Split(arg,"=")[1]
}
}

var drupalRoot string

// Use the alternative Drupal root if provided
if altRoot != "" {
drupalRoot = altRoot
} else {
// If no alternative root provided, find the Drupal root from the current directory
cwd, err := os.Getwd()
if err != nil {
fmt.Println("Error getting current directory:", err)
os.Exit(1)
}
drupalRoot, err = drushlauncher.FindDrupalRoot(cwd)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
drupalRoot, _err = drushlauncher.FindDrupalRoot(defaultRoot)

if _err != nil {
fmt.Println(_err)
os.Exit(1)
}

// Construct the full path to the drush executable
Expand All @@ -55,7 +51,7 @@ func main() {
fmt.Println("Error: Drush executable not found at", drushExec)
os.Exit(1)
}
// Construct the full command to run drush

drushCmd := exec.Command(drushExec, progArgs...)

// Pass the current environment variables to the drush command
Expand Down