Skip to content

Commit

Permalink
Merge pull request #11 from dasginganinja/7-missing-flags-not-passed
Browse files Browse the repository at this point in the history
#7 missing flags not passed
  • Loading branch information
dasginganinja authored Dec 19, 2023
2 parents 81c31ba + f6ca53b commit 9b59420
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
package main

import (
"flag"
"fmt"
"os"
"os/exec"
"path/filepath"

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

func main() {
// Parse command-line flags
altRoot := flag.String("r", "", "Set an alternative Drupal root")
altRootLong := flag.String("root", "", "Set an alternative Drupal root (long form)")
flag.Parse()
altRoot := ""

// 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]
} else {
fmt.Println("Error: Missing value for root argument")
os.Exit(1)
}
}
}

var drupalRoot string

// Use the alternative Drupal root if provided
if *altRoot != "" {
drupalRoot = *altRoot
} else if *altRootLong != "" {
drupalRoot = *altRootLong
if altRoot != "" {
drupalRoot = altRoot
} else {
// If no alternative root provided, find the Drupal root from the current directory
cwd, err := os.Getwd()
Expand All @@ -44,9 +55,8 @@ 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, flag.Args()...)
drushCmd := exec.Command(drushExec, progArgs...)

// Pass the current environment variables to the drush command
drushCmd.Env = os.Environ()
Expand Down

0 comments on commit 9b59420

Please sign in to comment.