@@ -127,7 +127,7 @@ const MagefilesDirName = "magefiles"
127
127
128
128
// UsesMagefiles returns true if we are getting our mage files from a magefiles directory.
129
129
func (i Invocation ) UsesMagefiles () bool {
130
- return i .Dir == MagefilesDirName
130
+ return filepath . Base ( i .Dir ) == MagefilesDirName
131
131
}
132
132
133
133
// ParseAndRun parses the command line, and then compiles and runs the mage
@@ -316,34 +316,29 @@ func Invoke(inv Invocation) int {
316
316
if inv .GoCmd == "" {
317
317
inv .GoCmd = "go"
318
318
}
319
- var noDir bool
320
319
if inv .Dir == "" {
321
- noDir = true
322
320
inv .Dir = dotDirectory
323
- // . will be default unless we find a mage folder.
324
- mfSt , err := os .Stat (MagefilesDirName )
325
- if err == nil {
326
- if mfSt .IsDir () {
327
- stderrBuf := & bytes.Buffer {}
328
- inv .Dir = MagefilesDirName // preemptive assignment
329
- // TODO: Remove this fallback and the above Magefiles invocation when the bw compatibility is removed.
330
- files , err := Magefiles (dotDirectory , inv .GOOS , inv .GOARCH , inv .GoCmd , stderrBuf , false , inv .Debug )
331
- if err == nil {
332
- if len (files ) != 0 {
333
- errlog .Println ("[WARNING] You have both a magefiles directory and mage files in the " +
334
- "current directory, in future versions the files will be ignored in favor of the directory" )
335
- inv .Dir = dotDirectory
336
- }
337
- }
338
- }
339
- }
340
321
}
341
-
342
322
if inv .WorkDir == "" {
343
- if noDir {
344
- inv .WorkDir = dotDirectory
345
- } else {
346
- inv .WorkDir = inv .Dir
323
+ inv .WorkDir = inv .Dir
324
+ }
325
+ magefilesDir := filepath .Join (inv .Dir , MagefilesDirName )
326
+ // . will be default unless we find a mage folder.
327
+ mfSt , err := os .Stat (magefilesDir )
328
+ if err == nil {
329
+ if mfSt .IsDir () {
330
+ stderrBuf := & bytes.Buffer {}
331
+ originalDir := inv .Dir
332
+ inv .Dir = magefilesDir // preemptive assignment
333
+ // TODO: Remove this fallback and the above Magefiles invocation when the bw compatibility is removed.
334
+ files , err := Magefiles (originalDir , inv .GOOS , inv .GOARCH , inv .GoCmd , stderrBuf , false , inv .Debug )
335
+ if err == nil {
336
+ if len (files ) != 0 {
337
+ errlog .Println ("[WARNING] You have both a magefiles directory and mage files in the " +
338
+ "current directory, in future versions the files will be ignored in favor of the directory" )
339
+ inv .Dir = originalDir
340
+ }
341
+ }
347
342
}
348
343
}
349
344
0 commit comments