Skip to content

Commit

Permalink
Updates emitter.LaunchProcesses to use new Default process feild
Browse files Browse the repository at this point in the history
- Makes the output more like a formatted table
  • Loading branch information
ForestEckhardt authored and sophiewigmore committed Nov 15, 2021
1 parent 41a40d9 commit 3f1daee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
19 changes: 17 additions & 2 deletions scribe/emitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,26 @@ Entries:
func (e Emitter) LaunchProcesses(processes []packit.Process, processEnvs ...map[string]packit.Environment) {
e.Process("Assigning launch processes:")

var (
typePadding int
)

for _, process := range processes {
p := fmt.Sprintf("%s: %s", process.Type, process.Command)
if len(process.Type) > typePadding {
typePadding = len([]byte(process.Type))
}
}

for _, process := range processes {
pad := typePadding + len(process.Command) - len(process.Type)
p := fmt.Sprintf("%s: %*s", process.Type, pad, process.Command)

if process.Args != nil {
p = fmt.Sprintf("%s %s", p, strings.Join(process.Args, " "))
p += " " + strings.Join(process.Args, " ")
}

if process.Default {
p += " " + "(default)"
}

e.Subprocess(p)
Expand Down
10 changes: 5 additions & 5 deletions scribe/emitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func testEmitter(t *testing.T, context spec.G, it spec.S) {
}
})


it("prints details about the selected dependency", func() {
emitter.SelectedDependency(entry, dependency, now)
Expect(buffer.String()).To(ContainLines(
Expand Down Expand Up @@ -236,6 +235,7 @@ func testEmitter(t *testing.T, context spec.G, it spec.S) {
{
Type: "web",
Command: "web-command",
Default: true,
},
{
Type: "some-other-type",
Expand All @@ -250,8 +250,8 @@ func testEmitter(t *testing.T, context spec.G, it spec.S) {

Expect(buffer.String()).To(ContainLines(
" Assigning launch processes:",
" some-type: some-command",
" web: web-command",
" some-type: some-command",
" web: web-command (default)",
" some-other-type: some-other-command some args",
"",
))
Expand Down Expand Up @@ -280,8 +280,8 @@ func testEmitter(t *testing.T, context spec.G, it spec.S) {

Expect(buffer.String()).To(ContainLines(
" Assigning launch processes:",
" some-type: some-command",
" web: web-command",
" some-type: some-command",
" web: web-command (default)",
` ANOTHER_WEB_VAR -> "another-env"`,
` WEB_VAR -> "some-env"`,
" some-other-type: some-other-command some args",
Expand Down

0 comments on commit 3f1daee

Please sign in to comment.