Skip to content

Commit

Permalink
refactor: change writer pkg to generator
Browse files Browse the repository at this point in the history
  • Loading branch information
matty-rose committed Oct 23, 2021
1 parent e2ef4e4 commit bdfbc0f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
8 changes: 6 additions & 2 deletions cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ THE SOFTWARE.
package cmd

import (
"os"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"github.com/matty-rose/gha-docs/pkg/generator"
"github.com/matty-rose/gha-docs/pkg/parser"
"github.com/matty-rose/gha-docs/pkg/writer"
)

// generateCmd represents the generate command
Expand All @@ -40,7 +42,9 @@ var generateCmd = &cobra.Command{
return errors.Wrap(err, "couldn't parse the action file")
}

err = writer.Write(action)
var gen generator.MarkdownGenerator
out := gen.Write(action)
_, err = os.Stdout.Write([]byte(out))
return err
},
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Copyright © 2021 Matt Rose <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package generator

import "github.com/matty-rose/gha-docs/pkg/types"

type Generator interface {
Write(action *types.CompositeAction) string
}
11 changes: 5 additions & 6 deletions pkg/writer/writer.go → pkg/generator/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
package writer
package generator

import (
"os"
"strconv"

"github.com/matty-rose/gha-docs/pkg/document"
"github.com/matty-rose/gha-docs/pkg/types"
)

func Write(action *types.CompositeAction) error {
type MarkdownGenerator struct{}

func (mdg MarkdownGenerator) Write(action *types.CompositeAction) string {
doc := document.NewMarkdownDocument()

doc.WriteHeading(action.Name, 1)
Expand Down Expand Up @@ -64,7 +65,5 @@ func Write(action *types.CompositeAction) error {
)
}

_, err := os.Stdout.Write([]byte(doc.Render() + "\n"))

return err
return doc.Render()
}

0 comments on commit bdfbc0f

Please sign in to comment.