Skip to content

Commit

Permalink
Minor discern enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
peterebden committed Aug 14, 2024
1 parent 743cbb7 commit e25fa01
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions discern/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var opts = struct {
After cli.Action `short:"a" long:"after" required:"true" description:"'After' action hash"`
} `command:"diff" description:"Show differences between two actions"`
Show struct {
NoInputs bool `long:"no_inputs" description:"Don't list input files"`
Args struct {

Check failure on line 39 in discern/main.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofmt`-ed with `-s` (gofmt)
Actions []cli.Action `positional-arg-name:"action" required:"true" description:"Hashes of actions to display"`
} `positional-args:"true"`
Expand Down Expand Up @@ -212,8 +213,10 @@ func show(client *client.Client) {
command := &pb.Command{}
mustGetProto(client, a.ToProto(), action)
mustGetProto(client, action.CommandDigest, command)
log.Notice("Inputs:")
showDir(client, action.InputRootDigest, "")
if !opts.Show.NoInputs {
log.Notice("Inputs:")
showDir(client, action.InputRootDigest, "")
}
if ar, err := client.CheckActionCache(context.Background(), &pb.Digest{Hash: a.Hash, SizeBytes: int64(a.Size)}); err != nil {
log.Error("Error retrieving action result: %s", err)
} else if ar == nil {
Expand All @@ -222,6 +225,8 @@ func show(client *client.Client) {
log.Notice("Outputs:")
log.Notice("[%s/%08d] Action result", a.Hash, a.Size)
showActionResult(client, ar)
showOutput(client, ar, ar.StdoutDigest, "Standard output")
showOutput(client, ar, ar.StdoutDigest, "Standard error")
}
}
}
Expand Down Expand Up @@ -296,6 +301,19 @@ func showActionResult(client *client.Client, ar *pb.ActionResult) {
}
}

func showOutput(client *client.Client, ar *pb.ActionResult, dg *pb.Digest, name string) {
if dg == nil {
return
}
log.Notice("%s [%s/%08d]:", name, dg.Hash, dg.SizeBytes)
b, _, err := client.ReadBlob(context.Background(), digest.NewFromProtoUnvalidated(dg))
if err != nil {
log.Errorf("Failed to fetch blob: %s", err)
return
}
fmt.Println(string(b))
}

func topn() error {
actions, err := gc.Sizes(opts.Storage.Storage, opts.Storage.InstanceName, "", opts.Storage.TLS, opts.TopN.N)
if err != nil {
Expand Down

0 comments on commit e25fa01

Please sign in to comment.