-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from gobuffalo/task/moving-to-genny
Moving it to use genny
- Loading branch information
Showing
480 changed files
with
76,404 additions
and
2,492 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"context" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/gobuffalo/buffalo-auth/auth" | ||
"github.com/gobuffalo/envy" | ||
"github.com/gobuffalo/makr" | ||
"github.com/gobuffalo/buffalo-auth/genny/auth" | ||
"github.com/gobuffalo/genny" | ||
"github.com/gobuffalo/genny/movinglater/gotools" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var dryRun bool | ||
|
||
// authCmd generates a actions/auth.go file configured to the specified providers. | ||
var authCmd = &cobra.Command{ | ||
Use: "auth", | ||
Short: "Generates a full auth implementation", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
pwd, err := os.Getwd() | ||
if err != nil { | ||
return errors.WithStack(err) | ||
r := genny.WetRunner(context.Background()) | ||
if dryRun { | ||
r = genny.DryRunner(context.Background()) | ||
} | ||
|
||
g, err := auth.New(args) | ||
if err != nil { | ||
if err := r.WithNew(auth.New(args)); err != nil { | ||
return err | ||
} | ||
return g.Run(".", makr.Data{ | ||
"packagePath": packagePath(pwd), | ||
}) | ||
}, | ||
} | ||
|
||
func goPath(root string) string { | ||
gpMultiple := envy.GoPaths() | ||
path := "" | ||
|
||
for i := 0; i < len(gpMultiple); i++ { | ||
if strings.HasPrefix(root, filepath.Join(gpMultiple[i], "src")) { | ||
path = gpMultiple[i] | ||
break | ||
if err := r.WithNew(gotools.GoFmt(r.Root)); err != nil { | ||
return err | ||
} | ||
} | ||
return path | ||
} | ||
|
||
func packagePath(rootPath string) string { | ||
gosrcpath := strings.Replace(filepath.Join(goPath(rootPath), "src"), "\\", "/", -1) | ||
rootPath = strings.Replace(rootPath, "\\", "/", -1) | ||
return strings.Replace(rootPath, gosrcpath+"/", "", 2) | ||
return r.Run() | ||
}, | ||
} | ||
|
||
func init() { | ||
authCmd.Flags().BoolVarP(&dryRun, "dry-run", "d", false, "run the generator without creating files or running commands") | ||
RootCmd.AddCommand(authCmd) | ||
} |
Oops, something went wrong.