From d1e7dbff2f0c399c739e699b5ec7ba494b727855 Mon Sep 17 00:00:00 2001 From: Tom Donahue Date: Wed, 27 Sep 2023 16:48:39 -0400 Subject: [PATCH 1/3] #7 - Options not defined in module aren't passed on --- main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index a2bd56c..5254df6 100644 --- a/main.go +++ b/main.go @@ -10,9 +10,16 @@ import ( ) func main() { - // Parse command-line flags + // Set up command-line flags altRoot := flag.String("r", "", "Set an alternative Drupal root") altRootLong := flag.String("root", "", "Set an alternative Drupal root (long form)") + + // We need to pash ALL options to Drush, even those we don't set (thanks flag module :)) + flag.CommandLine.ParseErrorsWhitelist = flag.ParseErrorsWhitelist{ + UnknownFlags: true, + } + + // Parse command-line flags flag.Parse() var drupalRoot string From 6457482c67778b5888ba332cfea557cd3a798429 Mon Sep 17 00:00:00 2001 From: "Thomas M. Donahue" Date: Mon, 18 Dec 2023 17:40:05 -0500 Subject: [PATCH 2/3] Revert "#7 - Options not defined in module aren't passed on" This reverts commit d1e7dbff2f0c399c739e699b5ec7ba494b727855. --- main.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/main.go b/main.go index 5254df6..a2bd56c 100644 --- a/main.go +++ b/main.go @@ -10,16 +10,9 @@ import ( ) func main() { - // Set up command-line flags + // Parse command-line flags altRoot := flag.String("r", "", "Set an alternative Drupal root") altRootLong := flag.String("root", "", "Set an alternative Drupal root (long form)") - - // We need to pash ALL options to Drush, even those we don't set (thanks flag module :)) - flag.CommandLine.ParseErrorsWhitelist = flag.ParseErrorsWhitelist{ - UnknownFlags: true, - } - - // Parse command-line flags flag.Parse() var drupalRoot string From f6ca53bb10055e730c0fdf000ba0f4b54dd2486e Mon Sep 17 00:00:00 2001 From: "Thomas M. Donahue" Date: Mon, 18 Dec 2023 17:38:43 -0500 Subject: [PATCH 3/3] #7: Fix flags by not using the package --- main.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index a2bd56c..5a253a5 100644 --- a/main.go +++ b/main.go @@ -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() @@ -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()