aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgutmet <me.git@gutmet.org>2020-04-28 20:49:15 +0200
committergutmet <me.git@gutmet.org>2020-04-28 20:49:15 +0200
commit55bf95a397c36fdfa304bcce6ed5a707fb94ebf5 (patch)
tree0e85db8c88b63b18c4ac3f9164997dca1d9057c6
parentd2cf77fb993f832021d442fa144a357bb510b5a8 (diff)
downloadlaymanshex-55bf95a397c36fdfa304bcce6ed5a707fb94ebf5.tar.gz
flag 'nopadding'
-rw-r--r--laymanshex.go20
1 files changed, 13 insertions, 7 deletions
diff --git a/laymanshex.go b/laymanshex.go
index 04bffd2..ab1c646 100644
--- a/laymanshex.go
+++ b/laymanshex.go
@@ -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)
}