Lots of additions:

- fixed issue#1: break endless loop for non-codes
- added config file support
- added logo
- added unit tests
- added ci test pipeline
- added issue templates
- added binary release builder
- enhanced documentation
- made the number of columns flexible based on word size
This commit is contained in:
2024-03-20 12:36:55 +01:00
parent f6a417b04d
commit 186c95076e
30 changed files with 874 additions and 41 deletions

69
main.go
View File

@@ -1,16 +1,43 @@
/*
Copyright © 2024 Thomas von Dein
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package main
import (
"fmt"
"io"
"os"
"runtime/debug"
"log/slog"
"github.com/tlinden/yadu"
)
func main() {
os.Exit(Main(os.Stdout))
}
func TMain() int {
return Main(os.Stdout)
}
func Main(output io.Writer) int {
// parse config file and command line parameters, if any
conf, err := InitConfig(output)
if err != nil {
return Die(err)
@@ -22,25 +49,57 @@ func Main(output io.Writer) int {
return 0
}
// enable debugging, if needed. We only use log/slog for
// debugging, so there's no need to configure it outside debugging
if conf.Debug {
logLevel := &slog.LevelVar{}
// we're using a more verbose logger in debug mode
buildInfo, _ := debug.ReadBuildInfo()
opts := &yadu.Options{
Level: logLevel,
AddSource: true,
}
logLevel.Set(slog.LevelDebug)
handler := yadu.NewHandler(output, opts)
debuglogger := slog.New(handler).With(
slog.Group("program_info",
slog.Int("pid", os.Getpid()),
slog.String("go_version", buildInfo.GoVersion),
),
)
slog.SetDefault(debuglogger)
}
// just show what we have
if conf.Listshortcuts {
ListTemplates(output)
ListTemplates(conf, output)
return 0
}
// code argument is mandatory
if len(conf.Code) == 0 {
fmt.Fprintln(output, Usage)
return 1
}
if Exists(Templates, conf.Code) {
conf.Code = Templates[conf.Code]
// check if we can use a template, otherwise consider the argument
// to be FN code
if Exists(conf.Templates, conf.Code) {
slog.Debug("Argument resolves to template code",
"name", conf.Code, "code", conf.Templates[conf.Code])
conf.Code = conf.Templates[conf.Code]
}
names, err := Generate(conf.Count, conf.Code)
// all prepared, run baby run
names, err := Generate(conf)
if err != nil {
return Die(err)
}
if err = PrintColumns(names, output); err != nil {
if err = PrintColumns(conf, names, output); err != nil {
return Die(err)
}