mirror of
https://gitea.com/gitea/tea.git
synced 2024-12-18 07:05:11 +01:00
5b28a05eb7
- [x] enhance notification listing - add `--states` and `--type` filters - toggle per-user or per-repo listing via `--mine` flag - print more fields - [x] add subcommands to mark notifications as read, unread, pinned, unpinned. operates on - all notifications matching the `--state` and `--mine` filter flags, or - a notification specified by ID. - [ ] ~~add a `--fields` flag for notifications listing.~~ *not in this PR* - [ ] ~~interactive mode~~ *not in this PR*. this would go well together with #324 fixes #243, fixes #155 based on initial work in #283 and #386, but opening a new PR for @6543 to review as I changed quite a lot --- ### ⚠️ breaking ⚠️ - `tea notifications --all` has moved to `tea notifications --mine` - `tea notifications` now only works with the context of a remote repo. To run this outside of a local git dir, run either `tea n --mine` or `tea n --repo <my/repo>` --- Co-authored-by: Karl Heinz Marbaise <kama@soebes.de> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Norwin Roosen <git@nroo.de> Reviewed-on: https://gitea.com/gitea/tea/pulls/389 Reviewed-by: 6543 <6543@obermui.de> Reviewed-by: Alexey 〒erentyev <axifive@noreply.gitea.io> Co-authored-by: Norwin <noerw@noreply.gitea.io> Co-committed-by: Norwin <noerw@noreply.gitea.io>
50 lines
1.3 KiB
Go
50 lines
1.3 KiB
Go
// Copyright 2021 The Gitea Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package flags
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"code.gitea.io/tea/modules/utils"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
// CsvFlag is a wrapper around cli.StringFlag, with an added GetValues() method
|
|
// to retrieve comma separated string values as a slice.
|
|
type CsvFlag struct {
|
|
cli.StringFlag
|
|
AvailableFields []string
|
|
}
|
|
|
|
// NewCsvFlag creates a CsvFlag, while setting its usage string and default values
|
|
func NewCsvFlag(name, usage string, aliases, availableValues, defaults []string) *CsvFlag {
|
|
return &CsvFlag{
|
|
AvailableFields: availableValues,
|
|
StringFlag: cli.StringFlag{
|
|
Name: name,
|
|
Aliases: aliases,
|
|
Value: strings.Join(defaults, ","),
|
|
Usage: fmt.Sprintf(`Comma-separated list of %s. Available values:
|
|
%s
|
|
`, usage, strings.Join(availableValues, ",")),
|
|
},
|
|
}
|
|
}
|
|
|
|
// GetValues returns the value of the flag, parsed as a commaseparated list
|
|
func (f CsvFlag) GetValues(ctx *cli.Context) ([]string, error) {
|
|
val := ctx.String(f.Name)
|
|
selection := strings.Split(val, ",")
|
|
if f.AvailableFields != nil && val != "" {
|
|
for _, field := range selection {
|
|
if !utils.Contains(f.AvailableFields, field) {
|
|
return nil, fmt.Errorf("Invalid field '%s'", field)
|
|
}
|
|
}
|
|
}
|
|
return selection, nil
|
|
}
|