feat(milestone): milestone tables, views, forms and one selection model

milestone view printed the list row, and milestone list hid the due date
and progress. milestone list now shows ID TITLE [STATE] DUE PROGRESS, open
milestones first and by due date; milestone view shows the state, due
date, progress, description and the milestone's web page (also --web).

Every milestone command addresses milestones by title or ID. Mutations
report ✓ lines: milestone create also prints the new milestone's URL and
takes the title as an argument; close and reopen skip milestones already
in that state; delete names the milestone in its confirmation; milestone
issue add and remove report one line such as "✓ Added #1, #2 to
milestone "v1.0" in alice/x". milestone issue list uses the issue table.
milestone edit without flags on a terminal opens the milestone form with
the current values, and every milestone command completes milestone
titles and has help text with examples.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-12 00:17:02 +02:00
1 parent 2ba02cf915
commit c161a63eb6
14 files changed
+606 -257

No files matched your search

+26 -9
View File
@@ -5,6 +5,7 @@ package app
import (
"errors"
"fmt"
"slices"
"strings"
@@ -13,13 +14,20 @@ import (
"github.com/spf13/cobra"
)
func (a *application) milestoneStateCommand(verb string, service func(*cobra.Command) (services.Milestones, error)) *cobra.Command {
// milestoneStateCommand closes or reopens milestones, reporting those already in that state instead
// of changing them.
func (a *application) milestoneStateCommand(verb string, service milestoneService) *cobra.Command {
var byName bool
cmd := &cobra.Command{Use: verb + " <milestone>...", Short: titleCase(verb) + " one or more milestones", Args: usageArgs(cobra.MinimumNArgs(1)), RunE: func(cmd *cobra.Command, args []string) error {
state, past := "closed", "Closed"
if verb == "reopen" {
state, past = "open", "Reopened"
}
cmd := &cobra.Command{Use: verb + " <milestone>...", Short: titleCase(verb) + " milestones", Example: fmt.Sprintf(`$ tea milestone %[1]s v1.0
$ tea milestone %[1]s v1.0 v1.1`, verb), Annotations: map[string]string{"tea.arguments": milestoneArguments}, Args: usageArgs(cobra.MinimumNArgs(1)), RunE: func(cmd *cobra.Command, args []string) error {
if slices.ContainsFunc(args, func(arg string) bool { return strings.TrimSpace(arg) == "" }) {
return clierr.Wrap(clierr.Usage, errors.New("milestone title or ID cannot be empty"))
}
milestones, err := service(cmd)
milestones, t, err := service(cmd)
if err != nil {
return err
}
@@ -32,14 +40,23 @@ func (a *application) milestoneStateCommand(verb string, service func(*cobra.Com
return clierr.Wrap(clierr.Usage, errors.New("milestone "+args[i]+" is selected more than once"))
}
}
state := "closed"
if verb == "reopen" {
state = "open"
results, failures := applyBatch(cmd, selected, func(milestone services.Milestone) string { return "milestone " + milestone.Title }, func(milestone services.Milestone) (services.Milestone, error) {
if milestone.State == state {
a.warn(cmd, "%s is already %s", titleCase(milestoneName(t, milestone)), state)
return milestone, nil
}
item, err := milestones.Edit(cmd.Context(), milestone.ID, services.MilestoneOptions{State: &state})
if err == nil {
a.done(cmd, "%s %s", past, milestoneName(t, item))
}
return item, err
}, func(services.Milestone) {})
if a.options.json != "" {
failures = append(failures, writeBatchJSON(a, cmd, len(selected), results))
}
return batch(a, cmd, selected, func(milestone services.Milestone) string { return "milestone " + milestone.Title }, func(milestone services.Milestone) (services.Milestone, error) {
return milestones.Edit(cmd.Context(), milestone.ID, services.MilestoneOptions{State: &state})
}, milestoneRow)
return errors.Join(failures...)
}}
cmd.Flags().BoolVar(&byName, "by-name", false, "Match numeric arguments as milestone titles rather than IDs")
cmd.ValidArgsFunction = a.completeMilestoneArgs(true)
return cmd
}