WIP: recipe create

This commit is contained in:
2021-07-25 00:07:35 +02:00
parent 45c3bce7ff
commit 359b07b562
5 changed files with 100 additions and 4 deletions

View File

@ -6,11 +6,13 @@ import (
"io/ioutil"
"net/http"
"os"
"path"
"sort"
"time"
"coopcloud.tech/abra/config"
"github.com/go-git/go-git/v5"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
@ -210,11 +212,57 @@ var recipeVersionCommand = &cli.Command{
},
}
var recipeCreateCommand = &cli.Command{
Name: "create",
Usage: "Create a new recipe",
ArgsUsage: "<recipe>",
Action: func(c *cli.Context) error {
recipe := c.Args().First()
if recipe == "" {
cli.ShowSubcommandHelp(c)
return nil
}
directory := path.Join(config.APPS_DIR, recipe)
if _, err := os.Stat(directory); !os.IsNotExist(err) {
logrus.Fatalf("'%s' recipe directory already exists?", directory)
return nil
}
url := fmt.Sprintf("%s/example.git", config.REPOS_BASE_URL)
_, err := git.PlainClone(directory, false, &git.CloneOptions{URL: url})
if err != nil {
logrus.Fatal(err)
return nil
}
toRemove := []string{
path.Join(config.APPS_DIR, recipe, ".git"),
path.Join(config.APPS_DIR, recipe, ".gitea"),
path.Join(config.APPS_DIR, recipe, ".drone.yml"),
}
for _, path := range toRemove {
if err := os.RemoveAll(path); err != nil {
logrus.Fatal(err)
return nil
}
}
// TODO: implement final %s logic on new repo files
// sed -i "s/\${REPO_NAME}/$recipe/g" README.md
// sed -i "s/\${REPO_NAME_TITLE}/$recipe/g" README.md
// sed -i "s/\${REPO_NAME_KEBAB}/$recipe_kebab/g" .env.sample
return nil
},
}
var RecipeCommand = &cli.Command{
Name: "recipe",
HideHelp: true,
Subcommands: []*cli.Command{
recipeListCommand,
recipeVersionCommand,
recipeCreateCommand,
},
}