Skip to content

Commit

Permalink
refactor: move generator config into separate file
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Rose <[email protected]>
  • Loading branch information
matty-rose committed Nov 27, 2021
1 parent ad70c8c commit 958c89b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 21 deletions.
42 changes: 42 additions & 0 deletions pkg/generator/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
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/thediveo/enumflag"

type UsageMode enumflag.Flag

const (
Remote UsageMode = iota
Local
)

var UsageModeIDs = map[UsageMode][]string{
Remote: {"remote"},
Local: {"local"},
}

type Config struct {
Format string

ExampleUsageMode *UsageMode
}
19 changes: 0 additions & 19 deletions pkg/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ package generator

import (
"github.com/pkg/errors"
"github.com/thediveo/enumflag"

"github.com/matty-rose/gha-docs/pkg/types"
)
Expand All @@ -32,24 +31,6 @@ type Generator interface {
Generate(action *types.CompositeAction) string
}

type UsageMode enumflag.Flag

const (
Remote UsageMode = iota
Local
)

var UsageModeIDs = map[UsageMode][]string{
Remote: {"remote"},
Local: {"local"},
}

type Config struct {
Format string

ExampleUsageMode *UsageMode
}

func New(config Config) (Generator, error) {
switch config.Format {
case "markdown":
Expand Down
3 changes: 1 addition & 2 deletions pkg/generator/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import (
func TestInvalidFormat(t *testing.T) {
t.Parallel()

var mode generator.UsageMode = generator.Remote

mode := generator.Remote
config := generator.Config{Format: "invalid", ExampleUsageMode: &mode}
g, err := generator.New(config)

Expand Down

0 comments on commit 958c89b

Please sign in to comment.