flag 'nopadding'

This commit is contained in:
gutmet 2020-04-28 20:49:15 +02:00
parent d2cf77fb99
commit 55bf95a397

View File

@ -420,20 +420,24 @@ func getValues(descr fileDescription, binpath string) map[string]string {
return vals
}
func fmtPadding(descr fileDescription) string {
func fmtPadding(descr fileDescription, nopadding bool) (string, string, string) {
if nopadding {
return "", "", ""
}
pad := 0
for _, part := range descr.parts {
if n := len(part.name); n > pad {
pad = n
}
}
return strconv.Itoa(pad)
return strconv.Itoa(pad), " ", " "
}
func printValues(descr fileDescription, vals map[string]string) {
func printValues(descr fileDescription, vals map[string]string, nopadding bool) {
firstCol, space1, space2 := fmtPadding(descr, nopadding)
for _, part := range descr.parts {
if part.name != "" {
fmt.Printf("%"+fmtPadding(descr)+"s = %s\n", part.name, vals[part.name])
fmt.Printf("%"+firstCol+"s%s=%s%s\n", part.name, space1, space2, vals[part.name])
}
}
}
@ -446,9 +450,11 @@ func printUsage() {
func main() {
var setAssignments string
var formatAssignments string
flag.StringVar(&setAssignments, "set", "", "key=value pairs (e.g. \"key1=value1,key2=value2\")")
flag.StringVar(&formatAssignments, "fvar", "", "key=value pairs (e.g. \"key1=value1,key2=value2\")")
var nopadding bool
flag.StringVar(&setAssignments, "set", "", "set values in binary file to key=value pairs (e.g. \"key1=value1,key2=value2\")")
flag.StringVar(&formatAssignments, "fvar", "", "assign values to variables in format description with key=value pairs (e.g. \"key1=value1,key2=value2\")")
flag.BoolVar(&debug, "debug", false, "print recognized parts of the format file")
flag.BoolVar(&nopadding, "nopadding", false, "turn of column padding (useful for bash scripting")
flag.Parse()
args := flag.Args()
if len(args) != 2 {
@ -459,5 +465,5 @@ func main() {
if setAssignments != "" {
setValues(descr, args[1], readSetAssignments(descr, setAssignments))
}
printValues(descr, getValues(descr, args[1]))
printValues(descr, getValues(descr, args[1]), nopadding)
}