refactor: construct recipe struct proper

This commit is contained in:
2021-09-06 01:41:16 +02:00
parent 6a1ecd0f85
commit 356c8f8c4e
6 changed files with 26 additions and 33 deletions

View File

@ -19,9 +19,9 @@ var recipeCreateCommand = &cli.Command{
Aliases: []string{"c"},
ArgsUsage: "<recipe>",
Action: func(c *cli.Context) error {
recipeName := internal.ValidateRecipe(c)
recipe := internal.ValidateRecipe(c)
directory := path.Join(config.APPS_DIR, recipeName)
directory := path.Join(config.APPS_DIR, recipe.Name)
if _, err := os.Stat(directory); !os.IsNotExist(err) {
logrus.Fatalf("'%s' recipe directory already exists?", directory)
return nil
@ -34,16 +34,16 @@ var recipeCreateCommand = &cli.Command{
return nil
}
gitRepo := path.Join(config.APPS_DIR, recipeName, ".git")
gitRepo := path.Join(config.APPS_DIR, recipe.Name, ".git")
if err := os.RemoveAll(gitRepo); err != nil {
logrus.Fatal(err)
return nil
}
toParse := []string{
path.Join(config.APPS_DIR, recipeName, "README.md"),
path.Join(config.APPS_DIR, recipeName, ".env.sample"),
path.Join(config.APPS_DIR, recipeName, ".drone.yml"),
path.Join(config.APPS_DIR, recipe.Name, "README.md"),
path.Join(config.APPS_DIR, recipe.Name, ".env.sample"),
path.Join(config.APPS_DIR, recipe.Name, ".drone.yml"),
}
for _, path := range toParse {
file, err := os.OpenFile(path, os.O_RDWR, 0755)
@ -64,7 +64,7 @@ var recipeCreateCommand = &cli.Command{
if err := tpl.Execute(file, struct {
Name string
Description string
}{recipeName, "TODO"}); err != nil {
}{recipe.Name, "TODO"}); err != nil {
logrus.Fatal(err)
return nil
}
@ -72,7 +72,7 @@ var recipeCreateCommand = &cli.Command{
logrus.Infof(
"New recipe '%s' created in %s, happy hacking!\n",
recipeName, path.Join(config.APPS_DIR, recipeName),
recipe.Name, path.Join(config.APPS_DIR, recipe.Name),
)
return nil