cli: Refactor out log to the top level

Remove some cruft at the same time.
This commit is contained in:
James Shubin
2024-03-22 00:54:31 -04:00
parent b8a3c39984
commit 3e180eafb4
6 changed files with 51 additions and 58 deletions

View File

@@ -40,6 +40,7 @@ import (
func Hello(program, version string, flags Flags) {
var start = time.Now().UnixNano()
// TODO: Move these log package initialization steps to the top main.go?
logFlags := log.LstdFlags
if flags.Debug {
logFlags = logFlags + log.Lshortfile
@@ -55,5 +56,5 @@ func Hello(program, version string, flags Flags) {
fmt.Println(fmt.Sprintf("This is: %s, version: %s", program, version))
fmt.Println("Copyright (C) 2013-2024+ James Shubin and the project contributors")
fmt.Println("Written by James Shubin <james@shubin.ca> and the project contributors")
log.Printf("main: start: %v", start)
flags.Logf("main: start: %v", start)
}

View File

@@ -54,10 +54,9 @@ func CliParseError(err error) error {
}
// Flags are some constant flags which are used throughout the program.
// TODO: Unify this with Debug and Logf ?
type Flags struct {
Debug bool // add additional log messages
Verbose bool // add extra log message output
Debug bool // add additional log messages
Logf func(format string, v ...interface{})
}
// Data is a struct of values that we usually pass to the main CLI function.