~emersion/hut-dev

todo ticket list: Add status filtering v1 SUPERSEDED

Thorben Günther: 1
 todo ticket list: Add status filtering

 2 files changed, 13 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/hut-dev/patches/48677/mbox | git am -3
Learn more about email & git

[PATCH] todo ticket list: Add status filtering Export this patch

---
 doc/hut.1.scd | 7 ++++++-
 todo.go       | 8 +++++++-
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/doc/hut.1.scd b/doc/hut.1.scd
index 80a49a9..89ba137 100644
--- a/doc/hut.1.scd
+++ b/doc/hut.1.scd
@@ -752,9 +752,14 @@ Options are:
	*-l*, *--label* <name>
		Name of the label (required).

*ticket list*
*ticket list* [options...]
	List tickets.

	Options are:

	*-s*, *--status* <string>
		Filter by ticket status.

*ticket show* <ID>
	Display a ticket.

diff --git a/todo.go b/todo.go
index 0c1f568..7615d42 100644
--- a/todo.go
+++ b/todo.go
@@ -280,7 +280,7 @@ func newTodoTicketCommand() *cobra.Command {
}

func newTodoTicketListCommand() *cobra.Command {
	// TODO: Filter by ticket status
	var status string
	run := func(cmd *cobra.Command, args []string) {
		ctx := cmd.Context()
		name, owner, instance, err := getTrackerName(ctx, cmd)
@@ -314,6 +314,10 @@ func newTodoTicketListCommand() *cobra.Command {
			}

			for _, ticket := range user.Tracker.Tickets.Results {
				// TODO: filter with API
				if status != "" && !strings.EqualFold(status, string(ticket.Status)) {
					continue
				}
				printTicket(p, &ticket)
			}

@@ -329,6 +333,8 @@ func newTodoTicketListCommand() *cobra.Command {
		Args:  cobra.ExactArgs(0),
		Run:   run,
	}
	cmd.Flags().StringVarP(&status, "status", "s", "", "ticket status")
	cmd.RegisterFlagCompletionFunc("status", completeTicketStatus)
	return cmd
}


base-commit: 499ef88754326222b1567261ac6b39b9f2a586ed
--
2.43.0
There are of course even more criteria that can be used to filter
tickets like submitter and labels, but I think status is the most
requested one for now.
Before implementing more, I want to work on aligning/improving the
output first. Based on that we can then omit filtering criteria from the
output. So for example if the user is filtering by submitter for one
person, that field no longer should be displayed.

My first idea would be to pass a "filter struct" to the printTicket
function, that contains all the filtering information, but that's just a
first idea.
Can we maybe parse the status with todosrht.ParseTicketStatus? To reject
invalid status flags.