From 16a77d9064f1573064f8fbdbb4da5316af494d50 Mon Sep 17 00:00:00 2001 From: probandula Date: Wed, 26 Oct 2016 19:10:29 +0200 Subject: [PATCH] added cli client --- README.md | 5 ++-- cmd/figlet4go/figlet4go.go | 50 +++++++++++++++++++++++++++++++++++--- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e47e7ee..801c040 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ The default font is `standard`. These are the builtin fonts Other fonts can mainly be found on [figlet](http://www.figlet.org). You have to load them as in [this example](#other-font). ## Todo -- [ ] Cli client +- [x] Cli client - [ ] automatic the perfect char margin -- [ ] Linebreak possible? \ No newline at end of file +- [ ] Linebreak possible? +- [ ] Colors in the cli client \ No newline at end of file diff --git a/cmd/figlet4go/figlet4go.go b/cmd/figlet4go/figlet4go.go index ef8a136..5c24b7f 100644 --- a/cmd/figlet4go/figlet4go.go +++ b/cmd/figlet4go/figlet4go.go @@ -2,12 +2,56 @@ package main import ( "fmt" - _"flag" + "flag" + "log" + "errors" _"github.com/fatih/color" - _"github.com/probandula/figlet4go" + "github.com/probandula/figlet4go" ) +var ( + str *string = flag.String("str", "", "String to be converted with FIGlet") + font *string = flag.String("font", "", "Font name to use") + fontpath *string = flag.String("fontpath", "", "Font path to load fonts from") +) func main() { - fmt.Println("Hello Figlet") + // Parse the flags + flag.Parse() + + // Validate and log the error + err := validate() + if err != nil { + log.Fatal(err) + } + + // Create objects + ascii := figlet4go.NewAsciiRender() + options := figlet4go.NewRenderOptions() + + // Load fonts + if *fontpath != "" { + ascii.LoadFont(*fontpath) + } + + // Set the font + options.FontName = *font + + + // Render the string + renderStr, err := ascii.RenderOpts(*str, options) + if err != nil { + log.Fatal(err) + } + + fmt.Println(renderStr) +} + +// Validate if all required options are given +// flag.Parse() must be called before this +func validate() error { + if *str == "" { + return errors.New("No string given") + } + return nil } \ No newline at end of file