Skip to content

Commit

Permalink
improve example .env file format
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Feb 15, 2023
1 parent 0c10bbb commit 8e85847
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions cli/packages/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,11 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
}

tagsHashToSecretKey := make(map[string]int)
slugsToFilerBy := make(map[string]int)

for _, slug := range strings.Split(tagSlugs, ",") {
slugsToFilerBy[slug] = 1
}

type TagsAndSecrets struct {
Secrets []models.SingleEnvironmentVariable
Expand All @@ -410,6 +415,25 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
return len(secrets[i].Tags) > len(secrets[j].Tags)
})

for i, secret := range secrets {
filteredTag := []struct {
ID string "json:\"_id\""
Name string "json:\"name\""
Slug string "json:\"slug\""
Workspace string "json:\"workspace\""
}{}

for _, secretTag := range secret.Tags {
_, exists := slugsToFilerBy[secretTag.Slug]
if !exists {
filteredTag = append(filteredTag, secretTag)
}
}

secret.Tags = filteredTag
secrets[i] = secret
}

for _, secret := range secrets {
listOfTagSlugs := []string{}

Expand Down Expand Up @@ -473,6 +497,8 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
return len(listOfsecretDetails[i].Tags) < len(listOfsecretDetails[j].Tags)
})

tableOfContents := []string{}
fullyGeneratedDocuments := []string{}
for _, secretDetails := range listOfsecretDetails {
listOfKeyValue := []string{}

Expand Down Expand Up @@ -513,11 +539,22 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
heading := CenterString(strings.Join(listOfTagNames, " & "), 80)

if len(listOfTagNames) == 0 {
fmt.Printf("\n%s \n", strings.Join(listOfKeyValue, "\n \n"))
fullyGeneratedDocuments = append(fullyGeneratedDocuments, fmt.Sprintf("\n%s \n", strings.Join(listOfKeyValue, "\n")))
} else {
fmt.Printf("\n\n\n%s \n%s \n", heading, strings.Join(listOfKeyValue, "\n \n"))
fullyGeneratedDocuments = append(fullyGeneratedDocuments, fmt.Sprintf("\n\n\n%s \n%s \n", heading, strings.Join(listOfKeyValue, "\n")))
tableOfContents = append(tableOfContents, strings.ToUpper(strings.Join(listOfTagNames, " & ")))
}
}

dashedList := []string{}
for _, item := range tableOfContents {
dashedList = append(dashedList, fmt.Sprintf("# - %s \n", item))
}
if len(dashedList) > 0 {
fmt.Println(CenterString("TABLE OF CONTENTS", 80))
fmt.Println(strings.Join(dashedList, ""))
}
fmt.Println(strings.Join(fullyGeneratedDocuments, ""))
}

func CenterString(s string, numStars int) string {
Expand Down

0 comments on commit 8e85847

Please sign in to comment.