diff --git a/core/commands/active.go b/core/commands/active.go index 3a3249bca..532e8bbfc 100644 --- a/core/commands/active.go +++ b/core/commands/active.go @@ -20,6 +20,9 @@ Lists running and recently run commands. Run: func(req cmds.Request, res cmds.Response) { res.SetOutput(req.InvocContext().ReqLog.Report()) }, + Options: []cmds.Option{ + cmds.BoolOption("v", "verbose", "print more verbose output"), + }, Marshalers: map[cmds.EncodingType]cmds.Marshaler{ cmds.Text: func(res cmds.Response) (io.Reader, error) { out, ok := res.Output().(*[]*cmds.ReqLogEntry) @@ -29,14 +32,33 @@ Lists running and recently run commands. } buf := new(bytes.Buffer) + verbose, _, _ := res.Request().Option("v").Bool() + w := tabwriter.NewWriter(buf, 4, 4, 2, ' ', 0) - fmt.Fprintln(w, "Command\tActive\tStartTime\tRunTime") + fmt.Fprint(w, "Command\t") + if verbose { + fmt.Fprint(w, "Arguments\tOptions\t") + } + fmt.Fprintln(w, "Active\tStartTime\tRunTime") + for _, req := range *out { - if req.Active { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "true", req.StartTime, time.Now().Sub(req.StartTime)) - } else { - fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", req.Command, "false", req.StartTime, req.EndTime.Sub(req.StartTime)) + fmt.Fprintf(w, "%s\t", req.Command) + if verbose { + fmt.Fprintf(w, "%v\t[", req.Args) + for k, v := range req.Options { + fmt.Fprintf(w, "%s=%v,", k, v) + } + fmt.Fprintf(w, "]\t") } + + var live time.Duration + if req.Active { + live = time.Now().Sub(req.StartTime) + } else { + live = req.EndTime.Sub(req.StartTime) + } + t := req.StartTime.Format(time.Stamp) + fmt.Fprintf(w, "%t\t%s\t%s\n", req.Active, t, live) } w.Flush()