feat: simplify flag parsing in buildpacks plugin

Commands should be written such that they take arguments as is.
This commit is contained in:
Jose Diaz-Gonzalez committed 2020-05-29 01:59:50 -04:00
1 parent ce154aff09
commit 6636c48838
3 files changed
+56 -87

No files matched your search

+18 -6
View File
@@ -2,14 +2,26 @@ package buildpacks
import (
"errors"
"fmt"
"regexp"
"strings"
)
func getAppName(args []string) (appName string, err error) {
if len(args) >= 1 {
appName = args[0]
} else {
err = errors.New("Please specify an app to run the command on")
func validBuildpackURL(buildpack string) (string, error) {
if buildpack == "" {
return buildpack, errors.New("Must specify a buildpack to add")
}
return
reHerokuValue := regexp.MustCompile(`(?m)^([\w]+\/[\w]+)$`)
if found := reHerokuValue.Find([]byte(buildpack)); found != nil {
parts := strings.SplitN(buildpack, "/", 2)
return fmt.Sprintf("https://github.com/%s/heroku-buildpack-%s.git", parts[0], parts[1]), nil
}
reString := regexp.MustCompile(`(?m)^(http|https|git)(:\/\/|@)([^\/:]+)[\/:]([^\/:]+)\/(.+)(.git(#derp)?)?$`)
if found := reString.Find([]byte(buildpack)); found != nil {
return buildpack, nil
}
return buildpack, fmt.Errorf("Invalid buildpack specified: %v", buildpack)
}