cmd/wasmcloud: show raw logbundles

This commit is contained in:
Cadey Ratio 2019-12-10 22:25:41 +00:00
parent 19cd0d7f50
commit 45fcf5fb84
2 changed files with 29 additions and 7 deletions

View File

@ -9,14 +9,20 @@ import (
"log"
"net/http"
"os"
"sort"
"github.com/google/subcommands"
"within.website/x/writer"
)
type handlerLogsCmd struct{}
type handlerLogsCmd struct {
rawBundle bool
}
func (h *handlerLogsCmd) SetFlags(fs *flag.FlagSet) {
fs.BoolVar(&h.rawBundle, "raw-bundle", false, "if set, dump the entire logbundle")
}
func (handlerLogsCmd) SetFlags(fs *flag.FlagSet) {}
func (handlerLogsCmd) Name() string { return "logs" }
func (handlerLogsCmd) Synopsis() string { return "shows logs for a handler" }
func (handlerLogsCmd) Usage() string {
@ -28,7 +34,7 @@ Returns all of the logs for a handler.
`
}
func (handlerLogsCmd) Execute(ctx context.Context, fs *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
func (h handlerLogsCmd) Execute(ctx context.Context, fs *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
if fs.NArg() != 1 {
fmt.Println("usage: wasmcloud create [options] <filename>")
return subcommands.ExitUsageError
@ -66,7 +72,23 @@ func (handlerLogsCmd) Execute(ctx context.Context, fs *flag.FlagSet, _ ...interf
for _, line := range result {
wr := writer.LineSplitting(writer.PrefixWriter(line.ExecID[:5]+" | ", os.Stdout))
fmt.Fprintln(wr, line.Logs["logs.txt"])
if h.rawBundle {
var keys []string
for k := range line.Logs {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
wr.Write([]byte("-- " + k + " --"))
wr.Write([]byte(line.Logs[k]))
}
continue
}
wr.Write([]byte(line.Logs["logs.txt"]))
}
return subcommands.ExitSuccess

View File

@ -21,7 +21,7 @@ func main() {
subcommands.Register(&loginCmd{}, "api")
subcommands.Register(&whoamiCmd{}, "api")
subcommands.Register(&handlerCreateCmd{}, "handlers")
subcommands.Register(handlerLogsCmd{}, "handlers")
subcommands.Register(&handlerLogsCmd{}, "handlers")
subcommands.Register(namegenCmd{}, "utils")
subcommands.Register(&runCmd{}, "utils")
subcommands.ImportantFlag("api-server")