added cli client

This commit is contained in:
probandula
2016-10-26 19:10:29 +02:00
parent 5b1157ab12
commit 16a77d9064
2 changed files with 50 additions and 5 deletions

View File

@@ -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?
- [ ] Linebreak possible?
- [ ] Colors in the cli client

View File

@@ -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
}