Skip to content

Commit

Permalink
Add optionality to inspect-builder
Browse files Browse the repository at this point in the history
[#127]

Signed-off-by: Danny Joyce <[email protected]>
  • Loading branch information
Danny Joyce committed Apr 30, 2019
1 parent ece98db commit 9987505
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
4 changes: 2 additions & 2 deletions acceptance/testdata/inspect_builder_output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Buildpacks:

Detection Order:
Group #1:
[email protected]
[email protected]
[email protected]
Group #2:
[email protected]
Expand All @@ -39,7 +39,7 @@ Buildpacks:

Detection Order:
Group #1:
[email protected]
[email protected]
[email protected]
Group #2:
[email protected]
21 changes: 19 additions & 2 deletions commands/inspect_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,25 @@ func logDetectionOrderInfo(logger *logging.Logger, info *pack.BuilderInfo) {
logger.Info("\nDetection Order:")
for i, group := range info.Groups {
logger.Info(fmt.Sprintf(" Group #%d:", i+1))
for _, bp := range group.Buildpacks {
logger.Info(fmt.Sprintf(" %s@%s", bp.ID, bp.Version))
buf := &bytes.Buffer{}
tabWriter := new(tabwriter.Writer).Init(buf, 0, 0, 4, ' ', 0)
for i, bp := range group.Buildpacks {
var optional string
if bp.Optional {
optional = "(optional)"
}
if _, err := fmt.Fprintf(tabWriter, " %s@%s\t%s", bp.ID, bp.Version, optional); err != nil {
logger.Error(err.Error())
}
if i < len(group.Buildpacks)-1 {
if _, err := fmt.Fprint(tabWriter, "\n"); err != nil {
logger.Error(err.Error())
}
}
}
if err := tabWriter.Flush(); err != nil {
logger.Error(err.Error())
}
logger.Info(buf.String())
}
}
8 changes: 4 additions & 4 deletions commands/inspect_builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ERROR: some local error
Buildpacks: buildpacks,
Groups: []builder.GroupMetadata{
{Buildpacks: []builder.GroupBuildpack{
{ID: "test.bp.one", Version: "1.0.0"},
{ID: "test.bp.one", Version: "1.0.0", Optional: true},
{ID: "test.bp.two", Version: "2.0.0"},
}}},
}
Expand All @@ -135,7 +135,7 @@ ERROR: some local error
Buildpacks: buildpacks,
Groups: []builder.GroupMetadata{
{Buildpacks: []builder.GroupBuildpack{{ID: "test.bp.one", Version: "1.0.0"}}},
{Buildpacks: []builder.GroupBuildpack{{ID: "test.bp.two", Version: "2.0.0"}}},
{Buildpacks: []builder.GroupBuildpack{{ID: "test.bp.two", Version: "2.0.0", Optional: true}}},
},
}
mockClient.EXPECT().InspectBuilder("some/image", true).Return(localInfo, nil)
Expand Down Expand Up @@ -177,7 +177,7 @@ Buildpacks:
Detection Order:
Group #1:
[email protected]
[email protected] (optional)
[email protected]
`)

Expand All @@ -203,7 +203,7 @@ Detection Order:
Group #1:
[email protected]
Group #2:
[email protected]
[email protected] (optional)
`)
})
})
Expand Down

0 comments on commit 9987505

Please sign in to comment.