Add tea issues --fields, allow printing labels (#312)

generalize list printing with dynamic fields

refactor print.IssuesList to use tableFromItems()

preparatory refactor

print.IssuesList: allow printing labels

move formatters to formatters.go

expose more printable fields on issue

add generic flags.FieldsFlag

add fields flag to tea issues, tea ms issues

validate provided fields

add strict username, or formatted user fields

change default fields

tea issues -> replace updated with labels
tea ms issues -> replace author with labels, reorder

Validate provided fields

Co-authored-by: Norwin Roosen <git@nroo.de>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/312
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-by: 6543 <6543@obermui.de>
Co-Authored-By: Norwin <noerw@noreply.gitea.io>
Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
authored and 6543 committed 2020-12-21 23:41:07 +08:00
1 parent 8bb5c15745
commit 9efee7bf99
16 files changed
+343 -222

No files matched your search

-17
View File
@@ -6,28 +6,11 @@ package repos
import (
"fmt"
"strings"
"code.gitea.io/tea/modules/print"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli/v2"
)
// printFieldsFlag provides a selection of fields to print
var printFieldsFlag = cli.StringFlag{
Name: "fields",
Aliases: []string{"f"},
Usage: fmt.Sprintf(`Comma-separated list of fields to print. Available values:
%s
`, strings.Join(print.RepoFields, ",")),
Value: "owner,name,type,ssh",
}
func getFields(ctx *cli.Context) []string {
return strings.Split(ctx.String("fields"), ",")
}
var typeFilterFlag = cli.StringFlag{
Name: "type",
Aliases: []string{"T"},
+9 -2
View File
@@ -27,7 +27,9 @@ var CmdReposListFlags = append([]cli.Flag{
Required: false,
Usage: "List your starred repos instead",
},
&printFieldsFlag,
flags.FieldsFlag(print.RepoFields, []string{
"owner", "name", "type", "ssh",
}),
&typeFilterFlag,
&flags.PaginationPageFlag,
&flags.PaginationLimitFlag,
@@ -80,7 +82,12 @@ func RunReposList(cmd *cli.Context) error {
reposFiltered = filterReposByType(rps, typeFilter)
}
print.ReposList(reposFiltered, ctx.Output, getFields(cmd))
fields, err := flags.GetFields(cmd, print.RepoFields)
if err != nil {
return err
}
print.ReposList(reposFiltered, ctx.Output, fields)
return nil
}
+8 -2
View File
@@ -50,7 +50,9 @@ var CmdReposSearch = cli.Command{
Required: false,
Usage: "Filter archived repos (true|false)",
},
&printFieldsFlag,
flags.FieldsFlag(print.RepoFields, []string{
"owner", "name", "type", "ssh",
}),
&flags.PaginationPageFlag,
&flags.PaginationLimitFlag,
}, flags.LoginOutputFlags...),
@@ -123,6 +125,10 @@ func runReposSearch(cmd *cli.Context) error {
return err
}
print.ReposList(rps, ctx.Output, getFields(cmd))
fields, err := flags.GetFields(cmd, nil)
if err != nil {
return err
}
print.ReposList(rps, ctx.Output, fields)
return nil
}