From 73bd1ffd10387d26dda4801eab9e1261a529a3fb Mon Sep 17 00:00:00 2001 From: tamnd <1218621+tamnd@users.noreply.github.com> Date: Mon, 15 Jun 2026 04:14:54 +0700 Subject: [PATCH] Add ask, show, and jobs story list commands Wire AskStories, ShowStories, and JobStories through the kit domain: three new OpMeta registrations and their handler functions, mirroring the existing top/new/best pattern. All seven list+single ops now live under the hackernews binary. --- hackernews/domain.go | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/hackernews/domain.go b/hackernews/domain.go index f023704..35aef82 100644 --- a/hackernews/domain.go +++ b/hackernews/domain.go @@ -62,6 +62,27 @@ func (Domain) Register(app *kit.App) { Args: []kit.Arg{{Name: "limit", Help: "max stories", Optional: true}}, }, bestStories) + kit.Handle(app, kit.OpMeta{ + Name: "ask", + Group: "stories", + Summary: "List Ask HN stories", + Args: []kit.Arg{{Name: "limit", Help: "max stories", Optional: true}}, + }, askStories) + + kit.Handle(app, kit.OpMeta{ + Name: "show", + Group: "stories", + Summary: "List Show HN stories", + Args: []kit.Arg{{Name: "limit", Help: "max stories", Optional: true}}, + }, showStories) + + kit.Handle(app, kit.OpMeta{ + Name: "jobs", + Group: "stories", + Summary: "List HN job posts", + Args: []kit.Arg{{Name: "limit", Help: "max stories", Optional: true}}, + }, jobStories) + kit.Handle(app, kit.OpMeta{ Name: "item", Group: "read", @@ -159,6 +180,45 @@ func bestStories(ctx context.Context, in storiesInput, emit func(Item) error) er return nil } +func askStories(ctx context.Context, in storiesInput, emit func(Item) error) error { + items, err := in.Client.AskStories(ctx, in.Limit) + if err != nil { + return err + } + for _, it := range items { + if err := emit(it); err != nil { + return err + } + } + return nil +} + +func showStories(ctx context.Context, in storiesInput, emit func(Item) error) error { + items, err := in.Client.ShowStories(ctx, in.Limit) + if err != nil { + return err + } + for _, it := range items { + if err := emit(it); err != nil { + return err + } + } + return nil +} + +func jobStories(ctx context.Context, in storiesInput, emit func(Item) error) error { + items, err := in.Client.JobStories(ctx, in.Limit) + if err != nil { + return err + } + for _, it := range items { + if err := emit(it); err != nil { + return err + } + } + return nil +} + func getItem(ctx context.Context, in itemInput, emit func(*Item) error) error { it, err := in.Client.GetItem(ctx, in.ID) if err != nil {