Files
kopia/cli/command_notification_profile.go
Jarek Kowalski c1757a0c67 feat(general): misc notifications improvements (#4319)
* feat(general): various notifications improvements

* added API to test notification profiles
* added --http-header to webhook notification configuration
* refactored configuration to always apply defaults before persisting options in the repository
* added 'notification profile show --profile-name=X' command

* more tests

* more test coverage

* report notification code coverage
2024-12-29 09:50:20 -08:00

54 lines
1.3 KiB
Go

package cli
import (
"context"
"strings"
"github.com/alecthomas/kingpin/v2"
"github.com/kopia/kopia/notification/notifyprofile"
"github.com/kopia/kopia/repo"
)
type commandNotificationProfile struct {
config commandNotificationProfileConfigure
list commandNotificationProfileList
delete commandNotificationProfileDelete
test commandNotificationProfileTest
show commandNotificationProfileShow
}
func (c *commandNotificationProfile) setup(svc appServices, parent commandParent) {
cmd := parent.Command("profile", "Manage notification profiles")
c.config.setup(svc, cmd)
c.delete.setup(svc, cmd)
c.test.setup(svc, cmd)
c.list.setup(svc, cmd)
c.show.setup(svc, cmd)
}
type notificationProfileFlag struct {
profileName string
}
func (c *notificationProfileFlag) setup(svc appServices, cmd *kingpin.CmdClause) {
cmd.Flag("profile-name", "Profile name").Required().HintAction(svc.repositoryHintAction(c.listNotificationProfiles)).StringVar(&c.profileName)
}
func (c *notificationProfileFlag) listNotificationProfiles(ctx context.Context, rep repo.Repository) []string {
profiles, err := notifyprofile.ListProfiles(ctx, rep)
if err != nil {
return nil
}
var hints []string
for _, ti := range profiles {
if strings.HasPrefix(ti.ProfileName, c.profileName) {
hints = append(hints, ti.ProfileName)
}
}
return hints
}