Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For multiline commands, only use the first line and "..." as the label #321

Merged
merged 2 commits into from
Apr 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion actions/run_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ import (
"github.com/go-debos/debos"
)

const (
maxLabelLength = 40
)

type RunAction struct {
debos.BaseAction `yaml:",inline"`
Chroot bool
Expand Down Expand Up @@ -113,7 +117,23 @@ func (run *RunAction) doRun(context debos.DebosContext) error {
label = path.Base(run.Script)
} else {
cmdline = []string{run.Command}
label = run.Command

// Remove leading and trailing spaces and — importantly — newlines
// before splitting, so that single-line scripts split into an array
// of a single string only.
commands := strings.Split(strings.TrimSpace(run.Command), "\n")
obbardc marked this conversation as resolved.
Show resolved Hide resolved
label = commands[0]

// Make it clear a long or a multi-line command is being run
if len(label) > maxLabelLength {
label = label[:maxLabelLength]

label = strings.TrimSpace(label)

label += "..."
} else if len(commands) > 1 {
label += "..."
obbardc marked this conversation as resolved.
Show resolved Hide resolved
}
}

if run.Label != "" {
Expand Down