From e25fa0183ea1406183c0729b22fdb15efb1fb8b9 Mon Sep 17 00:00:00 2001 From: Peter Ebden Date: Wed, 14 Aug 2024 16:40:54 +0100 Subject: [PATCH] Minor discern enhancements --- discern/main.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/discern/main.go b/discern/main.go index 7fa38972..f273ad9e 100644 --- a/discern/main.go +++ b/discern/main.go @@ -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 { Actions []cli.Action `positional-arg-name:"action" required:"true" description:"Hashes of actions to display"` } `positional-args:"true"` @@ -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 { @@ -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") } } } @@ -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 {