feat: remote recipes

This commit is contained in:
2024-07-08 15:13:13 +02:00
parent 1a3ec7a107
commit d7a870b887
11 changed files with 107 additions and 56 deletions

View File

@ -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