diff --git a/taskfile.yml b/Taskfile.yml similarity index 100% rename from taskfile.yml rename to Taskfile.yml diff --git a/pkg/commands/init.go b/pkg/commands/init.go index 0deb3b5..98dde50 100644 --- a/pkg/commands/init.go +++ b/pkg/commands/init.go @@ -3,6 +3,7 @@ package commands import ( "errors" "fmt" + "path" "github.com/Glow-Project/ppm/pkg/utility" "github.com/fatih/color" @@ -22,5 +23,9 @@ func initialize(ctx *cli.Context) error { fmt.Println(color.GreenString("new ppm.json config-file generated")) + if ok, _ := utility.DoesPathExist(path.Join(paths.Root, ".git")); ok { + fmt.Println(color.YellowString("when using ppm it is recommended to add the addons directory to your .gitignore file")) + } + return nil } diff --git a/pkg/commands/install.go b/pkg/commands/install.go index 433bf78..8d167ef 100644 --- a/pkg/commands/install.go +++ b/pkg/commands/install.go @@ -3,6 +3,7 @@ package commands import ( "fmt" + "github.com/Glow-Project/ppm/pkg/fetch" "github.com/Glow-Project/ppm/pkg/utility" "github.com/fatih/color" "github.com/urfave/cli/v2" @@ -18,11 +19,11 @@ func install(ctx *cli.Context) error { dependencies := ctx.Args() if dependencies.Len() == 0 { - installAllDependencies(&config, paths) + installAllDependencies(&config, &paths) } - for _, repo := range dependencies.Slice() { - if err = installDependency(&config, paths, repo, false); err != nil { + for _, dep := range dependencies.Slice() { + if err = installDependency(&config, &paths, utility.DependencyFromString(dep), false); err != nil { return err } } @@ -30,7 +31,7 @@ func install(ctx *cli.Context) error { return nil } -func installAllDependencies(config *utility.PpmConfig, paths utility.Paths) error { +func installAllDependencies(config *utility.PpmConfig, paths *utility.Paths) error { for _, dependency := range config.Dependencies { if err := installDependency(config, paths, dependency, false); err != nil { return err @@ -39,25 +40,20 @@ func installAllDependencies(config *utility.PpmConfig, paths utility.Paths) erro return nil } -func installDependency(config *utility.PpmConfig, paths utility.Paths, dependency string, isSubDependency bool) error { - dependency, version := utility.GetVersionOrNot(dependency) +func installDependency(config *utility.PpmConfig, paths *utility.Paths, dependency *utility.Dependency, isSubDependency bool) error { if !isSubDependency { - fmt.Printf("\rinstalling %s\n", color.YellowString(utility.GetPluginIdentifier(dependency))) + fmt.Printf("\rinstalling %s\n", color.YellowString(utility.GetPluginIdentifier(dependency.Identifier))) } else { - fmt.Printf("\t -> installing %s\n", color.YellowString(utility.GetPluginIdentifier(dependency))) + fmt.Printf("\t -> installing %s\n", color.YellowString(utility.GetPluginIdentifier(dependency.Identifier))) } loadAnim := utility.StartLoading() - err := utility.Clone(paths.Addons, dependency, version) + err := fetch.InstallDependency(dependency, paths) loadAnim.Stop() if err != nil { - if err.Error() == "repository already exists" { - alreadyInstalled(dependency) - } else { - installError(dependency) - return err - } + installError(dependency.Identifier) + return err } shouldAddDep := (!isSubDependency && !config.HasDependency(dependency)) || @@ -69,7 +65,7 @@ func installDependency(config *utility.PpmConfig, paths utility.Paths, dependenc config.AddDependency(dependency) } - subConfig, err := utility.GetPluginConfig(paths.Addons, dependency) + subConfig, err := utility.GetPluginConfig(paths.Addons, dependency.Identifier) if err != nil { if !isSubDependency { utility.PrintDone() diff --git a/pkg/commands/reinstall.go b/pkg/commands/reinstall.go index 08e01f0..472eb45 100644 --- a/pkg/commands/reinstall.go +++ b/pkg/commands/reinstall.go @@ -16,7 +16,7 @@ func reinstall(ctx *cli.Context) error { return err } - err = installAllDependencies(&config, paths) + err = installAllDependencies(&config, &paths) if err != nil { return err } diff --git a/pkg/commands/tidy.go b/pkg/commands/tidy.go index 5d63ccd..9d0f210 100644 --- a/pkg/commands/tidy.go +++ b/pkg/commands/tidy.go @@ -1,24 +1,51 @@ package commands import ( - "fmt" - "strings" + "encoding/json" + "os" "github.com/Glow-Project/ppm/pkg/utility" "github.com/urfave/cli/v2" ) func tidy(ctx *cli.Context) error { - _, config, err := utility.GetPathsAndConfig() + paths, err := utility.CreatePathsFromCwd() if err != nil { return err } - for i, dep := range config.Dependencies { - if utility.IsGithubRepoUrl(dep) { - tmp := strings.Split(dep, "/") - config.Dependencies[i] = fmt.Sprintf("%s/%s", tmp[len(tmp)-2], tmp[len(tmp)-1]) + content, err := os.ReadFile(paths.ConfigFile) + if err != nil { + return err + } + + var jsonContent map[string]interface{} + err = json.Unmarshal(content, &jsonContent) + if err != nil { + return err + } + + strDeps, ok := jsonContent["dependencies"].([]interface{}) + if !ok { + return nil + } + + deps := []*utility.Dependency{} + for _, dep := range strDeps { + str, ok := dep.(string) + if !ok { + return nil } + deps = append(deps, utility.DependencyFromString(str)) + } + + jsonContent["dependencies"] = deps + jsonData, err := json.MarshalIndent(jsonContent, "", "\t") + os.WriteFile(paths.ConfigFile, jsonData, 0644) + + config, err := utility.ParsePpmConfig(paths.ConfigFile) + if err != nil { + return err } return config.Write() diff --git a/pkg/commands/uninstall.go b/pkg/commands/uninstall.go index 7698f7e..274c2a3 100644 --- a/pkg/commands/uninstall.go +++ b/pkg/commands/uninstall.go @@ -23,13 +23,13 @@ func uninstall(ctx *cli.Context) error { } for i := 0; i < dependencies.Len(); i++ { - dep := dependencies.Get(i) + dep := utility.DependencyFromString(dependencies.Get(i)) if config.HasDependency(dep) && !config.HasSubDependency(dep) { uninstallDependency(&config, paths, dep, false) } else if config.HasSubDependency(dep) { - fmt.Println(color.RedString("the plugin"), color.YellowString(dep), color.RedString("is a sub dependency and can only be uninstalled by uninstalling its parent")) + fmt.Println(color.RedString("the plugin"), color.YellowString(dep.Identifier), color.RedString("is a sub dependency and can only be uninstalled by uninstalling its parent")) } else { - fmt.Println(color.RedString("the plugin"), color.YellowString(dep), color.RedString("is not installed")) + fmt.Println(color.RedString("the plugin"), color.YellowString(dep.Identifier), color.RedString("is not installed")) } } @@ -53,16 +53,15 @@ func uninstallAllDependencies(config *utility.PpmConfig, paths utility.Paths, ha return nil } -func uninstallDependency(config *utility.PpmConfig, paths utility.Paths, dependency string, isSubDependency bool) error { - dep := utility.GetPluginIdentifier(dependency) +func uninstallDependency(config *utility.PpmConfig, paths utility.Paths, dependency *utility.Dependency, isSubDependency bool) error { if !isSubDependency { - fmt.Println("\runinstalling", color.YellowString(dep)) + fmt.Println("\runinstalling", color.YellowString(dependency.Identifier)) } else { - fmt.Println("\t -> uninstalling", color.YellowString(dep)) + fmt.Println("\t -> uninstalling", color.YellowString(dependency.Identifier)) } loadAnim := utility.StartLoading() - subConfig, err := utility.GetPluginConfig(paths.Addons, dep) + subConfig, err := utility.GetPluginConfig(paths.Addons, dependency.Identifier) if err == nil { for i := 0; i < len(subConfig.Dependencies); i++ { subDep := subConfig.Dependencies[i] @@ -73,16 +72,16 @@ func uninstallDependency(config *utility.PpmConfig, paths utility.Paths, depende } // path: root/addons/dependency - err = os.RemoveAll(path.Join(paths.Addons, utility.GetPluginName(dep))) + err = os.RemoveAll(path.Join(paths.Addons, dependency.Identifier)) loadAnim.Stop() if err != nil { return err } if !isSubDependency { - config.RemoveDependency(dep) + config.RemoveDependency(dependency) } else { - config.RemoveSubDependency(dep) + config.RemoveSubDependency(dependency) } if !isSubDependency { diff --git a/pkg/commands/update.go b/pkg/commands/update.go index a0ef7fc..97a9d0a 100644 --- a/pkg/commands/update.go +++ b/pkg/commands/update.go @@ -28,12 +28,11 @@ func update(ctx *cli.Context) error { func updateAllDependencies(config utility.PpmConfig, paths utility.Paths) error { for _, dependency := range config.Dependencies { - _, version := utility.GetVersionOrNot(dependency) - if len(version) > 0 { + if dependency.Type != utility.GithubAsset { continue } - err := utility.Update(filepath.Join(paths.Addons, dependency)) + err := utility.UpdateGithubRepo(filepath.Join(paths.Addons, dependency.Identifier)) if err != nil { return err } diff --git a/pkg/fetch/fetch.go b/pkg/fetch/fetch.go new file mode 100644 index 0000000..54ff4ba --- /dev/null +++ b/pkg/fetch/fetch.go @@ -0,0 +1,153 @@ +package fetch + +import ( + "archive/zip" + "fmt" + "io" + "os" + "path" + "path/filepath" + "regexp" + "strings" + + "github.com/Glow-Project/ppm/pkg/utility" + "github.com/go-git/go-git/v5" +) + +// install a dependency `dep` into its directory inside the `addons` directory +func InstallDependency(dep *utility.Dependency, paths *utility.Paths) error { + var err error + if dep.Type == utility.GithubAsset { + err = installGithubRepo(dep, paths) + } else { + err = installGodotAsset(dep, paths) + } + + return err +} + +// install a plugin from github +func installGithubRepo(dep *utility.Dependency, paths *utility.Paths) error { + fullPath := path.Join(paths.Addons, dep.Identifier) + _, err := git.PlainClone(fullPath, false, &git.CloneOptions{ + URL: dep.Url, + }) + if err != nil { + return err + } + + return nil +} + +// install a plugin from the godot asset store +func installGodotAsset(dep *utility.Dependency, paths *utility.Paths) error { + r := Requester{} + data, err := r.Get(dep.Url) + if err != nil { + return err + } + + /* structure of data: + { + "result": [ + { + "asset_id": "" + } + ] + } + */ + results := data["result"].([]interface{}) + if len(results) == 0 { + return fmt.Errorf("No results for dependency \"%s\"", dep.Identifier) + } + + id := results[0].(map[string]interface{})["asset_id"].(string) + + data, err = r.Get(fmt.Sprintf("https://godotengine.org/asset-library/api/asset/%s", id)) + if err != nil { + return err + } + + dwdUrl := data["download_url"].(string) + f, err := os.CreateTemp("", "tempfile") + if err != nil { + return err + } + defer os.Remove(f.Name()) + + r.Download(dwdUrl, f) + f.Close() + err = unzip(f.Name(), paths.Addons) + if err != nil { + return err + } + + return nil +} + +// unzip a .zip file from src into dest +func unzip(src, dest string) error { + r, err := zip.OpenReader(src) + if err != nil { + return err + } + defer func() { + if err := r.Close(); err != nil { + panic(err) + } + }() + + os.MkdirAll(dest, 0755) + + shaRegex := regexp.MustCompile("-[0-9a-f]{40}") + + writeFile := func(f *zip.File) error { + rc, err := f.Open() + if err != nil { + return err + } + defer func() { + if err := rc.Close(); err != nil { + panic(err) + } + }() + + fileName := string(shaRegex.ReplaceAll([]byte(f.Name), []byte(""))) + path := filepath.Join(dest, fileName) + + // Check for ZipSlip (Directory traversal) + if !strings.HasPrefix(path, filepath.Clean(dest)+string(os.PathSeparator)) { + return fmt.Errorf("illegal file path: %s", path) + } + + if f.FileInfo().IsDir() { + os.MkdirAll(path, f.Mode()) + } else { + os.MkdirAll(filepath.Dir(path), f.Mode()) + f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode()) + if err != nil { + return err + } + defer func() { + if err := f.Close(); err != nil { + panic(err) + } + }() + + _, err = io.Copy(f, rc) + if err != nil { + return err + } + } + return nil + } + + for _, f := range r.File { + err := writeFile(f) + if err != nil { + return err + } + } + + return nil +} diff --git a/pkg/fetch/requester.go b/pkg/fetch/requester.go new file mode 100644 index 0000000..a916116 --- /dev/null +++ b/pkg/fetch/requester.go @@ -0,0 +1,43 @@ +package fetch + +import ( + "encoding/json" + "fmt" + "io" + "net/http" +) + +type Requester struct { + BaseUrl string +} + +func (r *Requester) Get(url string) (map[string]any, error) { + rawResp, err := http.Get(r.BaseUrl + url) + if err != nil { + return map[string]any{}, err + } + + var result map[string]any + json.NewDecoder(rawResp.Body).Decode(&result) + + return result, err +} + +func (r *Requester) Download(url string, w io.Writer) error { + response, err := http.Get(r.BaseUrl + url) + if err != nil { + return err + } + defer response.Body.Close() + + if response.StatusCode != 200 { + return fmt.Errorf("request to %s failed", url) + } + + _, err = io.Copy(w, response.Body) + if err != nil { + return err + } + + return nil +} diff --git a/pkg/utility/dependency.go b/pkg/utility/dependency.go new file mode 100644 index 0000000..b6a188d --- /dev/null +++ b/pkg/utility/dependency.go @@ -0,0 +1,44 @@ +package utility + +import ( + "fmt" + "strings" +) + +const ( + GithubAsset = "GITHUB_ASSET" + GDAsset = "GODOT_ASSET" +) + +type Dependency struct { + Identifier string `json:"identifier"` + Url string `json:"url"` + Type string `json:"type"` +} + +func DependencyFromString(str string) *Dependency { + var identifier string + var url string + var t string + + if isGithubUrl := IsGithubRepoUrl(str); isGithubUrl || IsUserAndRepo(str) { + if isGithubUrl { + url = str + } else { + url = fmt.Sprintf("https://github.com/%s", str) + } + tmp := strings.Split(str, "/") + identifier = tmp[len(tmp)-1] + t = GithubAsset + } else { + identifier = strings.Replace(str, " ", "-", -1) + url = fmt.Sprintf("https://godotengine.org/asset-library/api/asset?filter=%s", str) + t = GDAsset + } + + return &Dependency{ + Identifier: identifier, + Url: url, + Type: t, + } +} diff --git a/pkg/utility/generics.go b/pkg/utility/generics.go new file mode 100644 index 0000000..5fb1c67 --- /dev/null +++ b/pkg/utility/generics.go @@ -0,0 +1,66 @@ +package utility + +// get the index of a certain item in a string slice +func IndexOf[T comparable](target T, data []T) int { + for index, value := range data { + if target == value { + return index + } + } + return -1 +} + +// check whether a certain item exists in a string slice +func SliceContains[T comparable](target T, data []T) bool { + for _, v := range data { + if v == target { + return true + } + } + + return false +} + +// get the first predicate match of the slice +// +// returns nil if none of the items match +func GetFirstMatch[T any](arr []T, predicate func(T, int) bool) *T { + for i, value := range arr { + if predicate(value, i) { + return &value + } + } + + return nil +} + +// returns a new slice containing all the items on which the predicate returns true +func Filter[T any](arr []T, predicate func(T, int) bool) []T { + newArr := []T{} + for i, item := range arr { + if predicate(item, i) { + newArr = append(newArr, item) + } + } + + return newArr +} + +func Map[T any, N any](arr []T, predicate func(T, int) N) []N { + newArr := []N{} + for i, item := range arr { + newArr = append(newArr, predicate(item, i)) + } + + return newArr +} + +func Some[T any](arr []T, predicate func(T, int) bool) bool { + for i, item := range arr { + if predicate(item, i) { + return true + } + } + + return false +} diff --git a/pkg/utility/git.go b/pkg/utility/git.go index cdc8353..412f024 100644 --- a/pkg/utility/git.go +++ b/pkg/utility/git.go @@ -1,44 +1,11 @@ package utility import ( - "errors" - "fmt" - "path/filepath" - "strings" - git "github.com/go-git/go-git/v5" ) -// clone a certain github repository into a certain folder -func Clone(path string, repoName string, version string) error { - // the clonable name of the repository - var repository string - // the name of the repository - var name string - - if IsUrl(repoName) { - repository = repoName - tmp := strings.Split(repository, "/") - name = tmp[len(tmp)-1] - } else if IsUserAndRepo(repoName) { - repository = fmt.Sprintf("https://github.com/%s", repoName) - tmp := strings.Split(repoName, "/") - name = tmp[1] - } else { - // TODO: add godot asset library support - // name = repoName - return errors.New("godot asset library not supported yet") - } - - _, err := git.PlainClone(filepath.Join(path, name), false, &git.CloneOptions{ - URL: repository, - }) - - return err -} - // update a certain repository -func Update(path string) error { +func UpdateGithubRepo(path string) error { repo, err := git.PlainOpen(path) if err != nil { return err diff --git a/pkg/utility/ppmconfig.go b/pkg/utility/ppmconfig.go index 704a791..5beafb3 100644 --- a/pkg/utility/ppmconfig.go +++ b/pkg/utility/ppmconfig.go @@ -13,57 +13,59 @@ import ( // representing a ppm.json configuration file type PpmConfig struct { - IsPlugin bool `json:"plugin"` - Dependencies []string `json:"dependencies"` - SubDependencies []string `json:"sub-dependencies"` + IsPlugin bool `json:"plugin"` + Dependencies []*Dependency `json:"dependencies"` + SubDependencies []*Dependency `json:"sub-dependencies"` filePath string } // add an item safely to the Dependencies property -func (ppm *PpmConfig) AddDependency(dependency string) { +func (ppm *PpmConfig) AddDependency(dependency *Dependency) { ppm.Dependencies = append(ppm.Dependencies, dependency) ppm.Write() } // add an item safely to the sub-dependencies property -func (ppm *PpmConfig) AddSubDependency(dependency string) { +func (ppm *PpmConfig) AddSubDependency(dependency *Dependency) { ppm.SubDependencies = append(ppm.SubDependencies, dependency) ppm.Write() } // remove ALL (sub)dependencies func (ppm *PpmConfig) RemoveAllDependencies() { - ppm.Dependencies = []string{} - ppm.SubDependencies = []string{} + ppm.Dependencies = []*Dependency{} + ppm.SubDependencies = []*Dependency{} ppm.Write() } // remove an item safely from the Dependencies property by its name -func (ppm *PpmConfig) RemoveSubDependency(dependency string) { - dependency = GetPluginIdentifier(dependency) - ppm.SubDependencies = Filter(ppm.SubDependencies, func(item string, _ int) bool { - return item != dependency +func (ppm *PpmConfig) RemoveSubDependency(dependency *Dependency) { + ppm.SubDependencies = Filter(ppm.SubDependencies, func(item *Dependency, _ int) bool { + return item.Identifier != dependency.Identifier }) ppm.Write() } // remove an item safely from the sub-dependencies property by its name -func (ppm *PpmConfig) RemoveDependency(dependency string) { - dependency = GetPluginIdentifier(dependency) - ppm.Dependencies = Filter(ppm.Dependencies, func(item string, _ int) bool { - return item != dependency +func (ppm *PpmConfig) RemoveDependency(dependency *Dependency) { + ppm.Dependencies = Filter(ppm.Dependencies, func(item *Dependency, _ int) bool { + return item.Identifier != dependency.Identifier }) ppm.Write() } // check wether the config file has a certain dependency -func (ppm PpmConfig) HasDependency(dependency string) bool { - return SliceContains(dependency, ppm.Dependencies) +func (ppm PpmConfig) HasDependency(dependency *Dependency) bool { + return Some(ppm.Dependencies, func(dep *Dependency, _ int) bool { + return dep.Identifier == dependency.Identifier + }) } // check wether the config file has a certain sub-dependency -func (ppm PpmConfig) HasSubDependency(dependency string) bool { - return SliceContains(dependency, ppm.SubDependencies) +func (ppm PpmConfig) HasSubDependency(dependency *Dependency) bool { + return Some(ppm.SubDependencies, func(dep *Dependency, _ int) bool { + return dep.Identifier == dependency.Identifier + }) } func (ppm PpmConfig) PrettyPrint() { @@ -72,8 +74,13 @@ func (ppm PpmConfig) PrettyPrint() { ppmType = "plugin" } - dependencies := SliceToString(ppm.Dependencies, ", ") - subDependencies := SliceToString(ppm.SubDependencies, ", ") + depsToIdentifiers := func(deps []*Dependency) []string { + return Map(deps, func(item *Dependency, _ int) string { + return item.Identifier + }) + } + dependencies := SliceToString(depsToIdentifiers(ppm.Dependencies), ", ") + subDependencies := SliceToString(depsToIdentifiers(ppm.SubDependencies), ", ") fmt.Printf("this project is a %s\ndependencies: %v\nsubdependencies: %v\n", ppmType, dependencies, subDependencies) } @@ -107,7 +114,10 @@ func ParsePpmConfig(filePath string) (PpmConfig, error) { } config := PpmConfig{} - json.Unmarshal([]byte(content), &config) + err = json.Unmarshal([]byte(content), &config) + if err != nil { + return PpmConfig{}, err + } config.filePath = filePath return config, nil @@ -133,11 +143,11 @@ func CreateNewPpmConfig(path string) error { config := PpmConfig{ IsPlugin: isPlugin, - Dependencies: []string{}, - SubDependencies: []string{}, + Dependencies: []*Dependency{}, + SubDependencies: []*Dependency{}, } - content, err := json.MarshalIndent(config, "", " ") + content, err := json.MarshalIndent(config, "", "\t") if err != nil { return err } diff --git a/pkg/utility/regex.go b/pkg/utility/regex.go new file mode 100644 index 0000000..e9ecee6 --- /dev/null +++ b/pkg/utility/regex.go @@ -0,0 +1,26 @@ +package utility + +import "regexp" + +var ( + urlRegex = regexp.MustCompile(`^https?:\/\/[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{1,5}([a-zA-Z0-9_\/\-\=\&\?\:]+)*$`) + githubUrlRegex = regexp.MustCompile(`^https?:\/\/github\.com(\/[a-zA-Z0-9_\-\=\&\?\:]+){2}$`) + userAndRepoRegex = regexp.MustCompile(`^[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+$`) + assetDependencyRegex = regexp.MustCompile(`^[a-zA-Z0-9\-\_]+$`) +) + +func IsUrl(str string) bool { + return urlRegex.MatchString(str) +} + +func IsGithubRepoUrl(str string) bool { + return githubUrlRegex.MatchString(str) +} + +func IsUserAndRepo(str string) bool { + return userAndRepoRegex.MatchString(str) +} + +func IsAssetDependency(str string) bool { + return assetDependencyRegex.MatchString(str) +} diff --git a/pkg/utility/utility.go b/pkg/utility/utility.go index ca4df27..3857c80 100644 --- a/pkg/utility/utility.go +++ b/pkg/utility/utility.go @@ -4,7 +4,6 @@ import ( "errors" "fmt" "os" - "regexp" "strings" "github.com/fatih/color" @@ -39,27 +38,6 @@ func CheckOrCreateDir(path string) error { return nil } -// get the index of a certain item in a string slice -func IndexOf[t comparable](target t, data []t) int { - for index, value := range data { - if target == value { - return index - } - } - return -1 -} - -// check whether a certain item exists in a string slice -func SliceContains[t comparable](target t, data []t) bool { - for _, v := range data { - if v == target { - return true - } - } - - return false -} - func GetVersionOrNot(dependency string) (string, string) { version := "" @@ -125,43 +103,3 @@ func SliceToString(slice []string, seperator string) string { return str } - -// get the first predicate match of the slice -// -// returns nil if none of the items match -func GetFirstMatch[t any](slice []t, predicate func(t, int) bool) *t { - for i, value := range slice { - if predicate(value, i) { - return &value - } - } - - return nil -} - -// returns a new slice containing all the items on which the predicate returns true -func Filter[t any](slice []t, predicate func(t, int) bool) []t { - newSlice := []t{} - for i, item := range slice { - if predicate(item, i) { - newSlice = append(newSlice, item) - } - } - - return newSlice -} - -func IsUrl(str string) bool { - a, _ := regexp.Match(`https?:\/\/[a-zA-Z0-9_\-\.]+\.[a-zA-Z]{1,5}([a-zA-Z0-9_\/\-\=\&\?\:]+)*`, []byte(str)) - return a -} - -func IsGithubRepoUrl(str string) bool { - a, _ := regexp.Match(`https?:\/\/github\.com(\/[a-zA-Z0-9_\-\=\&\?\:]+){2}`, []byte(str)) - return a -} - -func IsUserAndRepo(str string) bool { - a, _ := regexp.Match(`[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-]+`, []byte(str)) - return a -} diff --git a/tests/utility_test.go b/tests/utility_test.go index 99740d9..c28f1fd 100644 --- a/tests/utility_test.go +++ b/tests/utility_test.go @@ -1,7 +1,6 @@ package tests import ( - "fmt" "path/filepath" "testing" @@ -17,7 +16,6 @@ func TestPaths(t *testing.T) { path := "/this/is/a/test" addonsPath := filepath.Join(path + "/addons") paths := utility.CreatePaths(path) - fmt.Println(path) if paths.Root != path { t.Errorf(pathNotEqualMessage, paths.Root, path) }