mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
repo list and search repo printed bare names. They now render a table with NAME, DESCRIPTION, INFO (public or private, fork, mirror, template, archived, empty) and UPDATED under "Showing N of M repositories ...", an empty-state message on stderr, and tab-separated rows with the URL when piped. --type, --sort and --order complete and validate their values. repo view shows the visibility and kind badges, stars, forks, open issues and pull requests, the parent of a fork, the source of a mirror, the default branch and the clone URLs, followed by the README of the default branch (or --branch), rendered on a terminal. The repository JSON gains empty, stars_count, forks_count, open_issues_count, open_pr_count, topics and updated_at. Signed-off-by: bircni <bircni@icloud.com>
74 lines
2.8 KiB
Go
74 lines
2.8 KiB
Go
// Copyright 2026 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package app
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"gitea.dev/tea/internal/services"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func (a *application) searchCommand() *cobra.Command {
|
|
group := &cobra.Command{
|
|
Use: "search",
|
|
Short: "Search within one selected Gitea instance",
|
|
Long: `Search the repositories, issues and pull requests of the selected Gitea instance that your
|
|
account can see.`,
|
|
}
|
|
var opts services.RepositorySearchOptions
|
|
var private, archived bool
|
|
command := &cobra.Command{
|
|
Use: "repo [<query>...]",
|
|
Short: "Search repositories",
|
|
Long: "Search the names and descriptions of repositories, or their topics with --topic.",
|
|
Example: `# Search repositories about a CLI
|
|
$ tea search repo command line
|
|
|
|
# Search the archived repositories of an organization
|
|
$ tea search repo --owner acme --archived
|
|
|
|
# Search by topic, most recently updated first
|
|
$ tea search repo go --topic --sort updated --order desc`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := a.rejectRepoFlag(cmd, func(owner string) string { return "tea search repo --owner " + owner }); err != nil {
|
|
return err
|
|
}
|
|
if cmd.Flags().Changed("private") {
|
|
opts.Private = &private
|
|
}
|
|
if cmd.Flags().Changed("archived") {
|
|
opts.Archived = &archived
|
|
}
|
|
opts.Query = strings.Join(args, " ")
|
|
target, err := a.resolve(cmd.Context(), false)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
result, err := (services.Repositories{Client: target.client}).Search(cmd.Context(), opts)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
what := "repositories"
|
|
if opts.Query != "" {
|
|
what += " matching " + opts.Query
|
|
}
|
|
spec := listSpec[services.Repository]{Columns: repositoryColumns, Row: repositoryRow, Context: what, Empty: "no " + what}
|
|
return writeTable(a, cmd, result.Items, spec, listPage{Number: opts.Page, More: result.More, Total: result.Total, Counted: result.Counted})
|
|
},
|
|
}
|
|
flags := command.Flags()
|
|
pageFlags(command, &opts.Limit, &opts.Page)
|
|
flags.StringVar(&opts.Owner, "owner", "", "Only repositories of this user or organization")
|
|
enumFlag(command, &opts.Kind, "type", "", "", "Only repositories of this kind", "fork", "source", "mirror")
|
|
enumFlag(command, &opts.Sort, "sort", "", "alpha", "Sort by", "alpha", "created", "updated", "size", "id")
|
|
enumFlag(command, &opts.Order, "order", "", "asc", "Sort order", "asc", "desc")
|
|
flags.BoolVar(&opts.Topic, "topic", false, "Match repository topics")
|
|
flags.BoolVar(&private, "private", false, "Only private repositories (use =false for public)")
|
|
flags.BoolVar(&archived, "archived", false, "Only archived repositories (use =false for active)")
|
|
_ = command.RegisterFlagCompletionFunc("owner", a.completeOrgs())
|
|
group.AddCommand(command, a.discussionSearchCommand(false), a.discussionSearchCommand(true))
|
|
return group
|
|
}
|