Skip to content

Commit

Permalink
Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
c2thorn committed Jun 3, 2024
1 parent 5fadd13 commit c110ce0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
16 changes: 6 additions & 10 deletions mmv1/description-copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
)

// Used to copy/paste text from Ruby -> Go YAML files
func CopyText(identifier string) {
var allProductFiles []string = make([]string, 0)
files, err := filepath.Glob("products/**/go_product.yaml")
Expand All @@ -21,13 +22,12 @@ func CopyText(identifier string) {
}

for _, productPath := range allProductFiles {
// Gather go and ruby file pairs
yamlMap := make(map[string][]string)

yamlPaths, err := filepath.Glob(fmt.Sprintf("%s/*", productPath))
if err != nil {
log.Fatalf("Cannot get yaml files: %v", err)
}

for _, yamlPath := range yamlPaths {
if strings.HasSuffix(yamlPath, "_new") {
continue
Expand All @@ -51,11 +51,10 @@ func CopyText(identifier string) {
currText := ""
recording := false

// Ready Ruby yaml
file, _ := os.Open(rubyPath)
defer file.Close()

scanner := bufio.NewScanner(file)

for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, identifier) {
Expand All @@ -71,23 +70,18 @@ func CopyText(identifier string) {
}
}
}

if recording {
text = append(text, currText)
}

// Read Go yaml while writing to a temp file
index := 0

newFilePath := fmt.Sprintf("%s_new", goPath)
fo, _ := os.Create(newFilePath)

w := bufio.NewWriter(fo)

file, _ = os.Open(goPath)
defer file.Close()

scanner = bufio.NewScanner(file)

for scanner.Scan() {
line := scanner.Text()
if strings.Contains(line, identifier) {
Expand All @@ -100,13 +94,15 @@ func CopyText(identifier string) {
panic(err)
}

// Overwrite original file with temp
os.Rename(newFilePath, goPath)
}

}

}

// quick and dirty logic to determine if a description/note is terminated
func terminateText(line string) bool {
terminalStrings := []string{
"!ruby/",
Expand Down
3 changes: 2 additions & 1 deletion mmv1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ var version = flag.String("version", "", "optional version name. If specified, t

var product = flag.String("product", "", "optional product name. If specified, the resources under the specific product will be generated. Otherwise, resources under all products will be generated.")

var yamlMode = flag.Bool("yaml", false, "only copy text over from ruby yaml to go yaml")
// Example usage: --yaml
var yamlMode = flag.Bool("yaml", false, "strictly copy text over from ruby yaml to go yaml")

func main() {
flag.Parse()
Expand Down

0 comments on commit c110ce0

Please sign in to comment.