forked from toolshed/abra
feat: remote recipes
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"slices"
|
||||
@ -123,11 +124,28 @@ type Features struct {
|
||||
}
|
||||
|
||||
func Get(name string) Recipe {
|
||||
dir := path.Join(config.RECIPES_DIR, name)
|
||||
gitURL := fmt.Sprintf("%s/%s.git", config.REPOS_BASE_URL, name)
|
||||
sshURL := fmt.Sprintf(config.SSH_URL_TEMPLATE, name)
|
||||
if strings.Contains(name, "/") {
|
||||
u, err := url.Parse(name)
|
||||
if err != nil {
|
||||
log.Fatalf("invalid recipe: %s", err)
|
||||
}
|
||||
u.Scheme = "https"
|
||||
gitURL = u.String() + ".git"
|
||||
|
||||
u.Scheme = "ssh"
|
||||
u.User = url.User("git")
|
||||
sshURL = u.String() + ".git"
|
||||
}
|
||||
|
||||
dir := path.Join(config.RECIPES_DIR, escapeRecipeName(name))
|
||||
|
||||
return Recipe{
|
||||
Name: name,
|
||||
Dir: dir,
|
||||
SSHURL: fmt.Sprintf(config.SSH_URL_TEMPLATE, name),
|
||||
GitURL: gitURL,
|
||||
SSHURL: sshURL,
|
||||
|
||||
ComposePath: path.Join(dir, "compose.yml"),
|
||||
ReadmePath: path.Join(dir, "README.md"),
|
||||
@ -139,6 +157,7 @@ func Get(name string) Recipe {
|
||||
type Recipe struct {
|
||||
Name string
|
||||
Dir string
|
||||
GitURL string
|
||||
SSHURL string
|
||||
|
||||
ComposePath string
|
||||
@ -147,6 +166,12 @@ type Recipe struct {
|
||||
AbraShPath string
|
||||
}
|
||||
|
||||
func escapeRecipeName(recipeName string) string {
|
||||
recipeName = strings.ReplaceAll(recipeName, "/", "_")
|
||||
recipeName = strings.ReplaceAll(recipeName, ".", "_")
|
||||
return recipeName
|
||||
}
|
||||
|
||||
// GetRecipesLocal retrieves all local recipe directories
|
||||
func GetRecipesLocal() ([]string, error) {
|
||||
var recipes []string
|
||||
|
Reference in New Issue
Block a user