Skip to content

Commit

Permalink
No bug: Add /m30 string modifier
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars T Hansen committed Dec 4, 2024
1 parent b432463 commit 99cc2e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
6 changes: 6 additions & 0 deletions code/sonalyze/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ Summary of print modifiers:

duration/sec -> 12345

Strings are normally printed in their full length but can be limited to
a maximum of 30 characters by /m30:

JobName -> supercalifragilisticexpialidocious
JobName/m30 -> supercalifragilisticexpialidoc

## Available field names

By running a command with `-fmt help`, extensive help is provided on all
Expand Down
5 changes: 5 additions & 0 deletions code/sonalyze/table/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ func FormatString(val string, ctx PrintMods) string {
if (ctx&PrintModNoDefaults) != 0 && val == "" {
return "*skip*"
}
if (ctx & PrintModMax30) != 0 {
if len(val) > 30 {
return val[:30]
}
}
return val
}

Expand Down
4 changes: 3 additions & 1 deletion code/sonalyze/table/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ type PrintMods = int

const (
// These apply per-field according to modifiers
// TODO: These are currently unimplemented.
PrintModSec = (1 << iota) // timestamps are printed as seconds since epoch
PrintModIso // timestamps are printed as Iso timestamps
PrintModMax30

// These are for the output format and are applied to all fields
PrintModFixed // fixed format
Expand Down Expand Up @@ -133,6 +133,8 @@ func addField(
if before, after, found := strings.Cut(fieldName, "/"); found {
var m PrintMods
switch after {
case "m30":
m = PrintModMax30
case "sec":
m = PrintModSec
case "iso":
Expand Down

0 comments on commit 99cc2e8

Please sign in to comment.