Allow to set verbosity of output (Closes #26)

This commit is contained in:
2025-01-28 21:02:12 +01:00
parent 2bdcdcb1dd
commit cced4f04b2
14 changed files with 89 additions and 33 deletions

View File

@ -2,7 +2,7 @@ package flags
import (
"flag"
"log"
"fmt"
"os"
"runtime"
"strings"
@ -25,13 +25,14 @@ func (flags *Flags) ParseFlags() {
flag.IntVar(&flags.Controller.Split, "split", 1, "Split the tasks in n parts. This depends on the availability of the first row.")
flag.IntVar(&flags.Controller.Part, "part", 1, "Process part x in n parts. Cannot be lower than 1, or higher than specified in split.")
flag.StringVar(&flags.Controller.Output, "output", "human", "Type of output. 'human' for human readable. 'flat' for flat as stored in memory output. 'json' for JSON output.")
flag.StringVar(&flags.Controller.Print, "print", "short", "'short': normal output;'long': normal output with timestamps; 'silent': Only print the results;")
// Parse the flags
flag.Parse()
// Process any changes to the CPU usage.
if flags.Controller.NumCPUs <= 0 {
log.Printf("ERROR: Number of CPU cores must be 1 or higher.\n\n")
fmt.Printf("ERROR: Number of CPU cores must be 1 or higher.\n\n")
flags.printUsage()
os.Exit(1)
}
@ -42,7 +43,7 @@ func (flags *Flags) ParseFlags() {
// Process rows
if flags.Controller.Row1 == "000000000" || flags.Controller.Row2 == "000000000" || flags.Controller.Row3 == "000000000" || flags.Controller.Row4 == "000000000" || flags.Controller.Row5 == "000000000" || flags.Controller.Row6 == "000000000" || flags.Controller.Row7 == "000000000" || flags.Controller.Row8 == "000000000" || flags.Controller.Row9 == "000000000" {
log.Printf("ERROR: All parameters must be entered.\n\n")
fmt.Printf("ERROR: All parameters must be entered.\n\n")
flags.printUsage()
os.Exit(1)
}
@ -61,14 +62,14 @@ func (flags *Flags) ParseFlags() {
// Process workload splitting
// Ensure split and part are 1 or higher
if flags.Controller.Split <= 0 || flags.Controller.Part <= 0 {
log.Printf("ERROR: '-split' and '-part' need to be 1 or higher.\n")
fmt.Printf("ERROR: '-split' and '-part' need to be 1 or higher.\n")
flags.printUsage()
os.Exit(1)
}
// Ensure part is between 1 and split
if flags.Controller.Part > flags.Controller.Split {
log.Printf("ERROR: '-part' cannot be bigger than `-split`.\n")
fmt.Printf("ERROR: '-part' cannot be bigger than `-split`.\n")
flags.printUsage()
os.Exit(1)
}
@ -76,7 +77,15 @@ func (flags *Flags) ParseFlags() {
// Process output selection
flags.Controller.Output = strings.ToLower(flags.Controller.Output)
if flags.Controller.Output != "human" && flags.Controller.Output != "flat" && flags.Controller.Output != "json" {
log.Printf("ERROR: Invalid output, can only be 'human' or 'flat'.\n")
fmt.Printf("ERROR: Invalid output, can only be 'human' or 'flat' or 'json'.\n")
flags.printUsage()
os.Exit(1)
}
// Process print selection
flags.Controller.Print = strings.ToLower(flags.Controller.Print)
if flags.Controller.Print != "short" && flags.Controller.Print != "long" && flags.Controller.Print != "silent" {
fmt.Printf("ERROR: Invalid Print, can only be 'short' or 'long' or 'silent'.\n")
flags.printUsage()
os.Exit(1)
}

View File

@ -1,7 +1,7 @@
package flags
import (
"log"
"fmt"
"os"
)
@ -18,7 +18,7 @@ func (flags *Flags) validateRow(name string, row string) {
// 1. Make sure the row is 9 in length
if len(row) != 9 {
log.Printf("ERROR: Invalid length of %s (%s), must be 9 numbers\n\n", name, row)
fmt.Printf("ERROR: Invalid length of %s (%s), must be 9 numbers\n\n", name, row)
flags.printUsage()
os.Exit(1)
}
@ -29,7 +29,7 @@ func (flags *Flags) validateRow(name string, row string) {
}
if !found {
log.Printf("ERROR: Invalid character of %s (%s), must be 9 numbers\n\n", name, row)
fmt.Printf("ERROR: Invalid character of %s (%s), must be 9 numbers\n\n", name, row)
flags.printUsage()
os.Exit(1)
}
@ -46,7 +46,7 @@ func (flags *Flags) validateRow(name string, row string) {
}
if double {
log.Printf("ERROR: Double character of %s (%s), numbers between 1 and 9 may only be entered once\n\n", name, row)
fmt.Printf("ERROR: Double character of %s (%s), numbers between 1 and 9 may only be entered once\n\n", name, row)
flags.printUsage()
os.Exit(1)
}