Skip to content

Commit cd1a299

Browse files
ethanalee-workgopherbot
authored andcommitted
cmd/ejobs: add -user option to ejobs list
- Enables filtering by username in list command. - Example: ejobs list -user=ethanalee. Change-Id: Ic945ff31ecb6dca6e331be0bfd38cd2a77fff01b Reviewed-on: https://go-review.googlesource.com/c/pkgsite-metrics/+/697835 Auto-Submit: Ethan Lee <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Neal Patel <[email protected]>
1 parent 1064180 commit cd1a299

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

cmd/ejobs/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,17 @@ var (
5454
force bool // for results
5555
errs bool // for results
5656
outfile string // for results
57+
userFilter string // for list
5758
)
5859

5960
var commands = []command{
60-
{"list", "",
61+
{"list", "[-user USERNAME]",
6162
"list jobs",
62-
doList, nil},
63+
doList,
64+
func(fs *flag.FlagSet) {
65+
fs.StringVar(&userFilter, "user", "", "filter jobs by user")
66+
},
67+
},
6368
{"show", "JOBID...",
6469
"display information about jobs in the last 7 days",
6570
doShow, nil},
@@ -208,6 +213,9 @@ func doList(ctx context.Context, _ []string) error {
208213
tw := tabwriter.NewWriter(os.Stdout, 2, 8, 1, ' ', 0)
209214
fmt.Fprintf(tw, "ID\tUser\tStart Time\tStarted\tFinished\tTotal\tCanceled\n")
210215
for _, j := range *joblist {
216+
if userFilter != "" && j.User != userFilter {
217+
continue
218+
}
211219
if j.StartedAt.After(weekBefore) {
212220
fmt.Fprintf(tw, "%s\t%s\t%s\t%d\t%d\t%d\t%t\n",
213221
j.ID(), j.User, j.StartedAt.Format(time.RFC3339),

0 commit comments

Comments
 (0)