Skip to content

Commit

Permalink
Melhorando o output do comando resolve #21
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasres committed Oct 16, 2021
1 parent c6451a0 commit 3341a05
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
20 changes: 20 additions & 0 deletions ADR-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# ADR-2: gambeta muito doida kkkj


## Status

What is the status, such as proposed, accepted, rejected, deprecated, superseded, etc.?

## Context

What is the issue that we're seeing that is motivating this decision or change?

## Decision

What is the change that we're proposing and/or doing?

## Consequences

What becomes easier or more difficult to do because of this change?

1 change: 1 addition & 0 deletions internal/output/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import "github.com/lucasres/adr-gen/internal/engine"

type OutputBase interface {
Write(path string, hits map[string]engine.ADRHit) error
BuildOutput(engine.ADRHit) (string, error)
}
42 changes: 41 additions & 1 deletion internal/output/file.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
package output

import (
"bytes"
"html/template"
"path/filepath"

"github.com/lucasres/adr-gen/internal/engine"
"github.com/lucasres/adr-gen/internal/file"
)

type FileOutput struct{}

func (o *FileOutput) BuildOutput(hit engine.ADRHit) (string, error) {
templateContent := `
# {{.ID}}: {{.Description}}
## Status
What is the status, such as proposed, accepted, rejected, deprecated, superseded, etc.?
## Context
What is the issue that we're seeing that is motivating this decision or change?
## Decision
What is the change that we're proposing and/or doing?
## Consequences
What becomes easier or more difficult to do because of this change?
`

tmplt := template.Must(template.New("template").Parse(templateContent))

var out bytes.Buffer

tmplt.Execute(&out, hit)

return out.String(), nil
}

func (o *FileOutput) Write(path string, hits map[string]engine.ADRHit) error {
w := file.NewLocalWrite()

for _, hit := range hits {
err := w.Write(path+hit.ID, hit.Description)
content, err := o.BuildOutput(hit)

if err != nil {
return err
}

err = w.Write(filepath.Join(path, hit.ID+".md"), content)

if err != nil {
return err
Expand Down

0 comments on commit 3341a05

Please sign in to comment.