PprintCommand provides pretty printing of the given command to trace & log outputs.
( ctx context.Context, command string, args []string, p events.Publisher[docker.Event], log *logrus.Entry, )
| 70 | |
| 71 | // PprintCommand provides pretty printing of the given command to trace & log outputs. |
| 72 | func PprintCommand( |
| 73 | ctx context.Context, |
| 74 | command string, |
| 75 | args []string, |
| 76 | p events.Publisher[docker.Event], |
| 77 | log *logrus.Entry, |
| 78 | ) error { |
| 79 | toPrint := command |
| 80 | for _, arg := range args { |
| 81 | if strings.HasPrefix(arg, "--") { // print each arg on a new line |
| 82 | toPrint += " \\\n" |
| 83 | toPrint += "\t" |
| 84 | toPrint += arg |
| 85 | } else { |
| 86 | toPrint += " " |
| 87 | toPrint += arg |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | log.Trace(toPrint) |
| 92 | if err := p.Publish(ctx, docker.NewLogEvent( |
| 93 | model.LogLevelDebug, |
| 94 | toPrint, |
| 95 | )); err != nil { |
| 96 | return err |
| 97 | } |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | // CanonicalizeImage returns the canonicalized image name. |
| 102 | func CanonicalizeImage(image string) string { |
no test coverage detected