refactor(recipe): don't use README.md path directly
This commit is contained in:
parent
c861c09cce
commit
6f90fc3025
@ -57,6 +57,7 @@ keys configured on your account.
|
||||
BashComplete: autocomplete.RecipeNameComplete,
|
||||
Action: func(c *cli.Context) error {
|
||||
recipeName := c.Args().First()
|
||||
r := recipe.Get2(recipeName)
|
||||
|
||||
if recipeName != "" {
|
||||
internal.ValidateRecipe(c)
|
||||
@ -103,7 +104,7 @@ keys configured on your account.
|
||||
log.Warn(err)
|
||||
}
|
||||
|
||||
features, category, err := recipe.GetRecipeFeaturesAndCategory(recipeMeta.Name)
|
||||
features, category, err := recipe.GetRecipeFeaturesAndCategory(r)
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
}
|
||||
|
@ -80,11 +80,7 @@ recipe and domain in the sample environment config).
|
||||
|
||||
meta := newRecipeMeta(recipeName)
|
||||
|
||||
toParse := []string{
|
||||
path.Join(config.RECIPES_DIR, recipeName, "README.md"),
|
||||
r.SampleEnvPath,
|
||||
}
|
||||
for _, path := range toParse {
|
||||
for _, path := range []string{r.ReadmePath, r.SampleEnvPath} {
|
||||
tpl, err := template.ParseFiles(path)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
@ -358,7 +358,8 @@ func LintHasPublishedVersion(recipe recipe.Recipe) (bool, error) {
|
||||
}
|
||||
|
||||
func LintMetadataFilledIn(r recipe.Recipe) (bool, error) {
|
||||
features, category, err := recipe.GetRecipeFeaturesAndCategory(r.Name)
|
||||
r2 := recipe.Get2(r.Name)
|
||||
features, category, err := recipe.GetRecipeFeaturesAndCategory(r2)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
@ -215,9 +215,11 @@ func Get(recipeName string, offline bool) (Recipe, error) {
|
||||
func Get2(name string) Recipe2 {
|
||||
dir := path.Join(config.RECIPES_DIR, name)
|
||||
return Recipe2{
|
||||
Name: name,
|
||||
Dir: dir,
|
||||
SSHURL: fmt.Sprintf(config.SSH_URL_TEMPLATE, name),
|
||||
Name: name,
|
||||
Dir: dir,
|
||||
SSHURL: fmt.Sprintf(config.SSH_URL_TEMPLATE, name),
|
||||
|
||||
ReadmePath: path.Join(dir, "README.md"),
|
||||
SampleEnvPath: path.Join(dir, ".env.sample"),
|
||||
}
|
||||
}
|
||||
@ -227,6 +229,7 @@ type Recipe2 struct {
|
||||
Dir string
|
||||
SSHURL string
|
||||
|
||||
ReadmePath string
|
||||
SampleEnvPath string
|
||||
}
|
||||
|
||||
@ -261,22 +264,20 @@ func GetVersionLabelLocal(recipe Recipe) (string, error) {
|
||||
return label, nil
|
||||
}
|
||||
|
||||
func GetRecipeFeaturesAndCategory(recipeName string) (Features, string, error) {
|
||||
func GetRecipeFeaturesAndCategory(r Recipe2) (Features, string, error) {
|
||||
feat := Features{}
|
||||
|
||||
var category string
|
||||
|
||||
readmePath := path.Join(config.RECIPES_DIR, recipeName, "README.md")
|
||||
log.Debugf("attempting to open %s for recipe metadata parsing", r.ReadmePath)
|
||||
|
||||
log.Debugf("attempting to open %s for recipe metadata parsing", readmePath)
|
||||
|
||||
readmeFS, err := ioutil.ReadFile(readmePath)
|
||||
readmeFS, err := ioutil.ReadFile(r.ReadmePath)
|
||||
if err != nil {
|
||||
return feat, category, err
|
||||
}
|
||||
|
||||
readmeMetadata, err := GetStringInBetween( // Find text between delimiters
|
||||
recipeName,
|
||||
r.Name,
|
||||
string(readmeFS),
|
||||
"<!-- metadata -->", "<!-- endmetadata -->",
|
||||
)
|
||||
@ -327,7 +328,7 @@ func GetRecipeFeaturesAndCategory(recipeName string) (Features, string, error) {
|
||||
if strings.Contains(val, "**Image**") {
|
||||
imageMetadata, err := GetImageMetadata(strings.TrimSpace(
|
||||
strings.TrimPrefix(val, "* **Image**:"),
|
||||
), recipeName)
|
||||
), r.Name)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user