Skip to content

Commit

Permalink
Move Retriever func to sysl (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChloePlanet committed Jun 15, 2021
1 parent 724c9c0 commit 653267b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 45 deletions.
9 changes: 4 additions & 5 deletions go.mod
Expand Up @@ -7,21 +7,20 @@ require (
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38
github.com/anz-bank/gop v0.19.0
github.com/anz-bank/gop v0.20.0
github.com/anz-bank/pkg v0.0.25
github.com/anz-bank/protoc-gen-sysl v0.0.28
github.com/anz-bank/sysl v0.352.0
github.com/arr-ai/arrai v0.233.0 // indirect
github.com/anz-bank/sysl v0.393.0
github.com/getkin/kin-openapi v0.18.0 // indirect
github.com/ghodss/yaml v1.0.0
github.com/gohugoio/hugo v0.74.1
github.com/huandu/xstrings v1.3.2 // indirect
github.com/iancoleman/strcase v0.1.1
github.com/iancoleman/strcase v0.1.3
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/pkg/errors v0.9.1
github.com/radovskyb/watcher v1.0.7
github.com/sirupsen/logrus v1.6.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/afero v1.4.0
github.com/stretchr/testify v1.6.1
github.com/yuin/goldmark v1.2.1
Expand Down
25 changes: 17 additions & 8 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 21 additions & 32 deletions main.go
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"log"
"net/http"
"os"
"path"
Expand All @@ -12,8 +11,7 @@ import (
"github.com/anz-bank/sysl-catalog/pkg/catalog"
"github.com/anz-bank/sysl-catalog/pkg/watcher"

"github.com/anz-bank/gop/pkg/cli"
"github.com/anz-bank/sysl/pkg/env"
"github.com/anz-bank/sysl/pkg/mod"
"github.com/anz-bank/sysl/pkg/parse"
"github.com/anz-bank/sysl/pkg/sysl"
"github.com/gohugoio/hugo/livereload"
Expand All @@ -24,21 +22,21 @@ import (
)

var (
run = kingpin.Command("run", "Run the generator")
input = run.Arg("input", "Input sysl file to generate documentation for").Required().String()
plantUMLoption = run.Flag("plantuml", "Plantuml service to use").String()
port = run.Flag("port", "Port to serve on").Short('p').Default(":6900").String()
outputType = run.Flag("type", "Type of output").HintOptions("html", "markdown").Default("markdown").String()
outputDir = run.Flag("output", "OutputDir directory to generate to").Short('o').String()
verbose = run.Flag("verbose", "Verbose logs").Short('v').Bool()
templates = run.Flag("templates", "Custom templates to use, separated by a comma, or 'mermaid' or 'plantuml' for defaults").String()
outputFileName = run.Flag("outputFileName", "Output file name for pages; {{.Title}}").Default("").String()
server = run.Flag("serve", "Start a http server and preview documentation").Bool()
noCSS = run.Flag("noCSS", "Disable adding css to served html").Bool()
disableLiveReload = run.Flag("disableLiveReload", "Disable live reload").Default("false").Bool()
mod = kingpin.Command("mod", "sysl modules")
cmd = mod.Arg("cmd", "get or update").String()
repo = mod.Arg("repo", "repo to get").String()
runCmd = kingpin.Command("run", "Run the generator")
input = runCmd.Arg("input", "Input sysl file to generate documentation for").Required().String()
plantUMLoption = runCmd.Flag("plantuml", "Plantuml service to use").String()
port = runCmd.Flag("port", "Port to serve on").Short('p').Default(":6900").String()
outputType = runCmd.Flag("type", "Type of output").HintOptions("html", "markdown").Default("markdown").String()
outputDir = runCmd.Flag("output", "OutputDir directory to generate to").Short('o').String()
verbose = runCmd.Flag("verbose", "Verbose logs").Short('v').Bool()
templates = runCmd.Flag("templates", "Custom templates to use, separated by a comma, or 'mermaid' or 'plantuml' for defaults").String()
outputFileName = runCmd.Flag("outputFileName", "Output file name for pages; {{.Title}}").Default("").String()
server = runCmd.Flag("serve", "Start a http server and preview documentation").Bool()
noCSS = runCmd.Flag("noCSS", "Disable adding css to served html").Bool()
disableLiveReload = runCmd.Flag("disableLiveReload", "Disable live reload").Default("false").Bool()
modCmd = kingpin.Command("mod", "sysl modules")
cmd = modCmd.Arg("cmd", "get or update").String()
repo = modCmd.Arg("repo", "repo to get").String()
)

func main() {
Expand All @@ -47,8 +45,10 @@ func main() {
logger := setupLogger()
plantUMLService := plantUMLService()
fs := afero.NewOsFs()
var retr cli.Retriever
retr, _ = Retriever(afero.NewOsFs())
retr, err := mod.Retriever(afero.NewOsFs())
if err != nil {
logger.Fatal(err)
}
if *cmd != "" {
if err := retr.Command(*cmd, *repo); err != nil {
logrus.Error(err)
Expand Down Expand Up @@ -155,7 +155,7 @@ func setupLogger() *logrus.Logger {
func parseSyslFile(root string, filename string, fs afero.Fs, logger *logrus.Logger) (*sysl.Module, error) {
logger.Info("Parsing...")
start := time.Now()
retr, err := Retriever(fs)
retr, err := mod.Retriever(fs)
if err != nil {
return nil, err
}
Expand All @@ -167,14 +167,3 @@ func parseSyslFile(root string, filename string, fs afero.Fs, logger *logrus.Log
logger.Info("Done, time elapsed: ", elapsed)
return m, err
}

/* TODO: Move this into anz-bank/sysl/pkg/mod */
func Retriever(fs afero.Fs) (cli.Retriever, error) {
tokenmap, _ := cli.NewTokenMap(env.SYSL_TOKENS.String(), "GIT_CREDENTIALS")
var cache, proxy string
if moduleFlag := env.SYSL_MODULES.Value(); moduleFlag != "" && moduleFlag != "false" && moduleFlag != "off" {
cache = env.SYSL_CACHE.Value()
proxy = env.SYSL_PROXY.Value()
}
return cli.Moduler(fs, "sysl_modules.yaml", cache, proxy, tokenmap, "", "", log.Printf), nil
}

0 comments on commit 653267b

Please sign in to comment.