mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11:25 +01:00
feat(repo): show repository columns, state and README
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>
This commit is contained in:
10 files changed
+456
-152
No files matched your search
+50
-49
@@ -4,69 +4,70 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"gitea.dev/tea/internal/clierr"
|
||||
"gitea.dev/tea/internal/services"
|
||||
"gitea.dev/tea/internal/terminal"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func validateRepositoryKind(kind string) error {
|
||||
switch kind {
|
||||
case "", "fork", "source", "mirror":
|
||||
return nil
|
||||
default:
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--type must be fork, source, or mirror"))
|
||||
}
|
||||
}
|
||||
|
||||
func (a *application) searchCommand() *cobra.Command {
|
||||
group := &cobra.Command{Use: "search", Short: "Search within one selected Gitea instance"}
|
||||
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 repository names, descriptions or topics", 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 err := validateRepositoryKind(opts.Kind); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := oneOf("sort", opts.Sort, "alpha", "created", "updated", "size", "id"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := oneOf("order", opts.Order, "asc", "desc"); 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
|
||||
}
|
||||
items, err := (services.Repositories{Client: target.client}).Search(cmd.Context(), opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return writeList(a, cmd, items, func(item services.Repository) []terminal.Cell {
|
||||
return terminal.Row(item.FullName, item.Description, item.URL)
|
||||
})
|
||||
}}
|
||||
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", "", "Repository owner")
|
||||
flags.StringVar(&opts.Kind, "type", "", "Repository kind: fork, source, mirror")
|
||||
flags.StringVar(&opts.Sort, "sort", "alpha", "Sort by alpha, created, updated, size, id")
|
||||
flags.StringVar(&opts.Order, "order", "asc", "Sort order: asc, desc")
|
||||
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
|
||||
}
|
||||
Reference in new issue
Block a user