diff --git a/cmd/monako/main.go b/cmd/monako/main.go index 6779356..6a90c5b 100644 --- a/cmd/monako/main.go +++ b/cmd/monako/main.go @@ -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) { @@ -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") @@ -41,7 +38,6 @@ func parseCommandLine() (cliSettings compose.CommandLineSettings) { MenuConfigFilePath: *menuconfigfilepath, ContentWorkingDir: *workingdir, BaseURL: *baseURL, - Trace: *trace, ShowVersion: *showVersion, FailOnHugoError: *failOnHugoError, OnlyCompose: *onlyCompose, @@ -68,10 +64,6 @@ func main() { os.Exit(0) } - if cliSettings.Trace { - helpers.Trace() - } - config := compose.Init(cliSettings) if !cliSettings.OnlyRender { err := config.Compose() diff --git a/cmd/monako/main_test.go b/cmd/monako/main_test.go index bc5a2b4..51f28dc 100644 --- a/cmd/monako/main_test.go +++ b/cmd/monako/main_test.go @@ -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) { @@ -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" { @@ -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 } diff --git a/go.mod b/go.mod index 99a591e..e7bed83 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index e0cbfcb..796e37b 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/pkg/compose/config.go b/pkg/compose/config.go index 951aabd..4049e11 100644 --- a/pkg/compose/config.go +++ b/pkg/compose/config.go @@ -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" ) @@ -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 @@ -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 (".") diff --git a/pkg/compose/config_test.go b/pkg/compose/config_test.go index 5b38505..64ec1cf 100644 --- a/pkg/compose/config_test.go +++ b/pkg/compose/config_test.go @@ -284,7 +284,6 @@ func TestInit(t *testing.T) { BaseURL: commandLineBaseURL, ContentWorkingDir: localFolder, FailOnHugoError: true, - Trace: true, }) assert.NotNil(t, config) diff --git a/pkg/compose/file.go b/pkg/compose/file.go index 0569c5b..7cf71e7 100644 --- a/pkg/compose/file.go +++ b/pkg/compose/file.go @@ -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" @@ -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" @@ -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)) @@ -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") @@ -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() @@ -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 } diff --git a/pkg/compose/hugo.go b/pkg/compose/hugo.go index da543fa..a42269b 100644 --- a/pkg/compose/hugo.go +++ b/pkg/compose/hugo.go @@ -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" diff --git a/pkg/compose/origin.go b/pkg/compose/origin.go index 0b074eb..276aec8 100644 --- a/pkg/compose/origin.go +++ b/pkg/compose/origin.go @@ -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" @@ -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() @@ -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 @@ -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 diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go new file mode 100644 index 0000000..ccf887f --- /dev/null +++ b/pkg/errors/errors.go @@ -0,0 +1,7 @@ +package errors + +import "fmt" + +func Wrap(err error, message string) error { + return fmt.Errorf("error: %s, err: %v", message, err) +} diff --git a/pkg/helpers/util.go b/pkg/helpers/util.go index 1d82ee0..500f931 100644 --- a/pkg/helpers/util.go +++ b/pkg/helpers/util.go @@ -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 @@ -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) -} diff --git a/pkg/helpers/util_test.go b/pkg/helpers/util_test.go index 6d8f860..3db1123 100644 --- a/pkg/helpers/util_test.go +++ b/pkg/helpers/util_test.go @@ -5,7 +5,6 @@ package helpers import ( "testing" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/assert" ) @@ -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) -}