From 0408b23d9d2471bfb6bea547ca762f6f47307bc2 Mon Sep 17 00:00:00 2001 From: probandula Date: Sun, 30 Oct 2016 09:07:25 +0100 Subject: [PATCH] fixed goreportcard stuff --- char.go | 2 +- cmd/figlet4go/figlet4go.go | 13 +++++-------- font.go | 1 + fontmanager.go | 2 +- render.go | 12 ++++++------ 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/char.go b/char.go index abf1c18..18b95bf 100644 --- a/char.go +++ b/char.go @@ -14,7 +14,7 @@ type asciiChar struct { } // Creates a new ascii character -func NewAsciiChar(font *font, char rune) (*asciiChar, error) { +func newAsciiChar(font *font, char rune) (*asciiChar, error) { // If not ascii, throw an error if char < 0 || char > 127 { return nil, errors.New("Not Ascii") diff --git a/cmd/figlet4go/figlet4go.go b/cmd/figlet4go/figlet4go.go index 8907280..8b0465f 100644 --- a/cmd/figlet4go/figlet4go.go +++ b/cmd/figlet4go/figlet4go.go @@ -1,12 +1,12 @@ package main import ( - "errors" "flag" "fmt" "github.com/fatih/color" "github.com/probandula/figlet4go" "log" + "os" "strings" ) @@ -22,10 +22,7 @@ func main() { flag.Parse() // Validate and log the error - err := validate() - if err != nil { - log.Fatal(err) - } + validate() // Create objects ascii := figlet4go.NewAsciiRender() @@ -87,9 +84,9 @@ func getColorSlice(colorStr string) []color.Attribute { // Validate if all required options are given // flag.Parse() must be called before this -func validate() error { +func validate() { if *str == "" { - return errors.New("No string given") + flag.Usage() + os.Exit(1) } - return nil } diff --git a/font.go b/font.go index b224a9d..6cff83d 100644 --- a/font.go +++ b/font.go @@ -1,4 +1,5 @@ package figlet4go + // Explanation of the .flf file header // THE HEADER LINE // diff --git a/fontmanager.go b/fontmanager.go index 4a8e9e6..2d092b1 100644 --- a/fontmanager.go +++ b/fontmanager.go @@ -66,7 +66,7 @@ func (fm *fontManager) getFont(fontName string) *font { func (fm *fontManager) loadFontList(fontPath string) error { // Walk through the path return filepath.Walk(fontPath, func(path string, info os.FileInfo, err error) error { - // Return an error if occured + // Return an error if occurred if err != nil { return err } diff --git a/render.go b/render.go index e60bfed..2356c27 100644 --- a/render.go +++ b/render.go @@ -13,7 +13,7 @@ type RenderOptions struct { FontColor []color.Attribute } -// Create new RenderOptions +// NewRenderOptions creates new RenderOptions // Sets the default font name func NewRenderOptions() *RenderOptions { return &RenderOptions{ @@ -27,25 +27,25 @@ type AsciiRender struct { fontMgr *fontManager } -// Create a new AsciiRender +// NewAsciiRender creates a new AsciiRender func NewAsciiRender() *AsciiRender { return &AsciiRender{ fontMgr: newFontManager(), } } -// Loading all *.flf font files recursively in a path +// LoadFont loads all *.flf font files recursively in a path func (ar *AsciiRender) LoadFont(fontPath string) error { return ar.fontMgr.loadFontList(fontPath) } -// Render a string with the default options +// Render renders a string with the default options // Calls the RenderOpts method with a new RenderOptions object func (ar *AsciiRender) Render(str string) (string, error) { return ar.RenderOpts(str, NewRenderOptions()) } -// Render a string with special RenderOptions +// RenderOpts renders a string with special RenderOptions // Can be called from the user (if options wished) or the above Render method // Contains the whole rendering logic func (ar *AsciiRender) RenderOpts(str string, opt *RenderOptions) (string, error) { @@ -64,7 +64,7 @@ func (ar *AsciiRender) RenderOpts(str string, opt *RenderOptions) (string, error // Foreach char create the ascii char for _, char := range str { // AsciiChar - asciiChar, err := NewAsciiChar(font, char) + asciiChar, err := newAsciiChar(font, char) if err != nil { return "", err }