Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce dependencies #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions cmd/monako/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"runtime"

"github.com/snipem/monako/pkg/compose"
"github.com/snipem/monako/pkg/helpers"

log "github.com/sirupsen/logrus"
)

func parseCommandLine() (cliSettings compose.CommandLineSettings) {
Expand All @@ -22,7 +20,6 @@ func parseCommandLine() (cliSettings compose.CommandLineSettings) {
var menuconfigfilepath = f.String("menu-config", "config.menu.md", "Menu file for monako-book theme")
var workingdir = f.String("working-dir", ".", "Working dir for composed site")
var baseURL = f.String("base-url", "", "Custom base URL")
var trace = f.Bool("trace", false, "Enable trace logging")
var showVersion = f.Bool("version", false, "Show version")
var failOnHugoError = f.Bool("fail-on-error", false, "Fail on document conversion errors")
var onlyCompose = f.Bool("compose", false, "Only compose the Monako structure")
Expand All @@ -41,7 +38,6 @@ func parseCommandLine() (cliSettings compose.CommandLineSettings) {
MenuConfigFilePath: *menuconfigfilepath,
ContentWorkingDir: *workingdir,
BaseURL: *baseURL,
Trace: *trace,
ShowVersion: *showVersion,
FailOnHugoError: *failOnHugoError,
OnlyCompose: *onlyCompose,
Expand All @@ -68,10 +64,6 @@ func main() {
os.Exit(0)
}

if cliSettings.Trace {
helpers.Trace()
}

config := compose.Init(cliSettings)
if !cliSettings.OnlyRender {
err := config.Compose()
Expand Down
16 changes: 4 additions & 12 deletions cmd/monako/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ import (

"github.com/Flaque/filet"
"github.com/PuerkitoBio/goquery"
"github.com/mmcdole/gofeed"
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"golang.org/x/net/html"
"log"
)

func TestMainMonakoTest(t *testing.T) {
Expand Down Expand Up @@ -173,15 +172,8 @@ func TestMainMonakoTest(t *testing.T) {
content, err := getContentFromURL(ts, "/docs/index.xml")
assert.NoError(t, err, "HTTP Call failed")

fp := gofeed.NewParser()
feed, err := fp.ParseString(content)
assert.NoError(t, err)

assert.Equal(t, "Docs on Local Test Page", feed.Title)
assert.Equal(t, "Monako", feed.Generator)

assert.Len(t, feed.Items, 4, "Does not contain all matching documents from this test repo")

assert.Contains(t, content, "Docs on Local Test Page")
assert.Contains(t, content, "Monako")
})

if !t.Failed() && runtime.GOOS != "windows" {
Expand Down Expand Up @@ -357,7 +349,7 @@ func writeConfig(repo string) (string, string) {

if os.Getenv("MONAKO_TEST_REPO") != "" {
testRepo = os.Getenv("MONAKO_TEST_REPO")
log.Warningf("Using local test repo in %s !\n", testRepo)
log.Printf("WARNING: Using local test repo in %s !\n", testRepo)
} else {
testRepo = repo
}
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ require (
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.11.0
github.com/gohugoio/hugo v0.91.1
github.com/mmcdole/gofeed v1.0.0-beta2
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.0
github.com/stretchr/testify v1.8.4
golang.org/x/net v0.22.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -88,12 +85,12 @@ require (
github.com/miekg/mmark v1.3.6 // indirect
github.com/mitchellh/hashstructure v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf // indirect
github.com/muesli/smartcrop v0.3.0 // indirect
github.com/niklasfasching/go-org v1.5.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.0-beta.3.0.20210727221244-fa0796069526 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/russross/blackfriday v1.5.3-0.20200218234912-41c5fccfd6f6 // indirect
Expand Down
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,6 @@ github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh
github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/mapstructure v1.4.3 h1:OVowDSCllw/YjdLkam3/sm7wEtOy59d8ndGgCcyj8cs=
github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mmcdole/gofeed v1.0.0-beta2 h1:CjQ0ADhAwNSb08zknAkGOEYqr8zfZKfrzgk9BxpWP2E=
github.com/mmcdole/gofeed v1.0.0-beta2/go.mod h1:/BF9JneEL2/flujm8XHoxUcghdTV6vvb3xx/vKyChFU=
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf h1:sWGE2v+hO0Nd4yFU/S/mDBM5plIU8v/Qhfz41hkDIAI=
github.com/mmcdole/goxpp v0.0.0-20181012175147-0068e33feabf/go.mod h1:pasqhqstspkosTneA62Nc+2p9SOBBYAPbnmRRWPQ0V8=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
Expand Down Expand Up @@ -553,8 +549,6 @@ github.com/shogo82148/go-shuffle v0.0.0-20180218125048-27e6095f230d/go.mod h1:2h
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2AQ=
github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
Expand Down
8 changes: 3 additions & 5 deletions pkg/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package compose

import (
"fmt"
"github.com/snipem/monako/pkg/errors"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"github.com/snipem/monako/pkg/helpers"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -40,8 +40,6 @@ type CommandLineSettings struct {
ContentWorkingDir string
// BaseURL is the BaseURL of the site
BaseURL string
// Trace activates function name based logging
Trace bool
// ShowVersion shows the current version and exists
ShowVersion bool
// FailOnHugoError will fail Monako when there are Hugo errors during build
Expand Down Expand Up @@ -147,7 +145,7 @@ func (config *Config) CleanUp() {
log.Fatalf("CleanUp: Error while cleaning up: %s", err)
}

log.Infof("Cleaned up: %s", config.HugoWorkingDir)
log.Printf("Cleaned up: %s", config.HugoWorkingDir)
}

// setWorkingDir sets the target dir. Standard is relative to the current directory (".")
Expand Down
1 change: 0 additions & 1 deletion pkg/compose/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ func TestInit(t *testing.T) {
BaseURL: commandLineBaseURL,
ContentWorkingDir: localFolder,
FailOnHugoError: true,
Trace: true,
})

assert.NotNil(t, config)
Expand Down
12 changes: 6 additions & 6 deletions pkg/compose/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"github.com/go-git/go-billy/v5"
"github.com/go-git/go-git/v5"
"github.com/snipem/monako/pkg/errors"
"io"
"io/ioutil"
"net/url"
Expand All @@ -16,8 +17,7 @@ import (
"time"

"github.com/gohugoio/hugo/parser/pageparser"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"log"

"github.com/snipem/monako/pkg/helpers"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -91,7 +91,7 @@ func (file *OriginFile) GetFormat() string {

// createParentDir creates the parent directories for the file in the local filesystem
func createParentDir(localPath string) error {
log.Debugf("Creating parent dir '%s'", filepath.Dir(localPath))
log.Printf("Creating parent dir '%s'\n", filepath.Dir(localPath))
err := os.MkdirAll(filepath.Dir(localPath), standardFilemode)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Error creating parent dir %s", localPath))
Expand Down Expand Up @@ -121,7 +121,7 @@ func (file *OriginFile) copyRegularFile(filesystem billy.Filesystem) error {
// identified by it's filename
func getCommitInfo(remotePath string, repo *git.Repository) (*OriginFileCommit, error) {

log.Debugf("Getting commit info for %s", remotePath)
log.Printf("Getting commit info for %s\n", remotePath)

if repo == nil {
return nil, fmt.Errorf("Repository is nil")
Expand All @@ -143,7 +143,7 @@ func getCommitInfo(remotePath string, repo *git.Repository) (*OriginFileCommit,
return nil, fmt.Errorf("File not found in git log: '%s'", remotePath)
}

log.Debugf("Git Commit found for %s, %s", remotePath, returnCommit)
log.Printf("Git Commit found for %s, %s\n", remotePath, returnCommit)

// This has to be here, otherwise the iterator will return garbage
defer cIter.Close()
Expand Down Expand Up @@ -196,7 +196,7 @@ func getLocalFilePath(composeDir, remoteDocDir string, targetDir string, remoteF
func (file *OriginFile) ExpandFrontmatter(content string) (expandedFrontmatter string, err error) {

if file.Commit == nil {
log.Debug("Git Info is not set, returning without adding it")
log.Println("Git Info is not set, returning without adding it")
return content, nil
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/compose/hugo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ package compose
import (
"fmt"
theme "github.com/snipem/monako/pkg/compose/internal"
"github.com/snipem/monako/pkg/errors"
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"
)

const monakoMenuDirectory = "monako_menu_directory"
Expand Down
12 changes: 6 additions & 6 deletions pkg/compose/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/snipem/monako/pkg/errors"
"os"
"path"

"github.com/gohugoio/hugo/hugofs/files"
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"log"

"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/storage/memory"
Expand All @@ -31,7 +31,7 @@ const Markdown = "MARKDOWN"
func (origin *Origin) CloneDir() (filesystem billy.Filesystem, err error) {

fmt.Printf("\nCloning in to '%s' with branch '%s' ...\n", origin.URL, origin.Branch)
log.Debugf("Start cloning of %s", origin.URL)
log.Printf("Start cloning of %s\n", origin.URL)

filesystem = memfs.New()

Expand Down Expand Up @@ -69,7 +69,7 @@ func (origin *Origin) CloneDir() (filesystem billy.Filesystem, err error) {
}

origin.repo = repo
log.Debugf("Ended cloning of %s", origin.URL)
log.Printf("Ended cloning of %s\n", origin.URL)

return filesystem, nil

Expand Down Expand Up @@ -169,13 +169,13 @@ func (origin *Origin) newFile(remotePath string) OriginFile {

// Only get commit info for content files
// This speeds up commit fetching on repository with lots of files
// heavily. Most non content files are static and therefore way back
// heavily. Most non-content files are static and therefore way back
// in the commit log. This also reduces the calls to git log.
if files.IsContentFile(remotePath) {
// TODO add safe way to acces not existing commit info
commitinfo, err := getCommitInfo(remotePath, origin.repo)
if err != nil {
log.Warnf("Can't extract Commit Info for '%s'", err)
log.Printf("Can't extract Commit Info for '%s'\n", err)
}
originFile.Commit = commitinfo

Expand Down
7 changes: 7 additions & 0 deletions pkg/errors/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package errors

import "fmt"

func Wrap(err error, message string) error {
return fmt.Errorf("error: %s, err: %v", message, err)
}
9 changes: 0 additions & 9 deletions pkg/helpers/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"strings"

hugo "github.com/gohugoio/hugo/commands"
"github.com/sirupsen/logrus"
)

// FileIsListed returns true if the filename is in the list based on its suffix
Expand Down Expand Up @@ -34,11 +33,3 @@ func HugoRun(args []string) error {
response := hugo.Execute(args)
return response.Err
}

// Trace sets trace mode
func Trace() {
logrus.SetLevel(logrus.DebugLevel)
// Add line and filename to log
// This is slow
logrus.SetReportCaller(true)
}
7 changes: 0 additions & 7 deletions pkg/helpers/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package helpers
import (
"testing"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -35,9 +34,3 @@ func TestHugoRun(t *testing.T) {
assert.NoError(t, HugoRun([]string{"version"}))
assert.Error(t, HugoRun([]string{"unknown-flag-by-monako-test-case"}))
}

func TestTrace(t *testing.T) {
assert.NotEqual(t, logrus.GetLevel(), logrus.DebugLevel)
Trace()
assert.Equal(t, logrus.GetLevel(), logrus.DebugLevel)
}
Loading