mirror of
https://github.com/kopia/kopia.git
synced 2025-12-23 22:57:50 -05:00
* feat(cli): support for defining notification profiles via CLI
Profile management:
```
$ kopia notification profile configure email \
--profile-name=X \
--smtp-server=smtp.gmail.com \
--smtp-port=587 \
--smtp-username=X \
--smtp-password=X \
--mail-from=X \
--mail-to=X \
--format=html|txt \
[--send-test-notification]
$ kopia notification profile configure pushover --profile-name=X \
--user-key=X \
--app-token=X \
--format=html|txt \
[--send-test-notification]
$ kopia notification profile configure webhook --profile-name=X \
--endpooint=http://some-address:port/path \
--method=POST|PUT \
--format=html|txt \
[--send-test-notification]
$ kopia notification profile test --profile-name=X
$ kopia notification profile delete --profile-name=X
$ kopia notification profile list
```
Template management:
```
$ kopia notification template show X
$ kopia notification template set X \
--from-stdin | --from-file=X | --editor
$ kopia notification template remove X
$ kopia notification template list
```
Implements #1958
* additional refactoring for testability, various naming tweaks
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/alecthomas/kingpin/v2"
|
|
|
|
"github.com/kopia/kopia/notification/notifytemplate"
|
|
"github.com/kopia/kopia/repo"
|
|
)
|
|
|
|
type commandNotificationTemplate struct {
|
|
list commandNotificationTemplateList
|
|
show commandNotificationTemplateShow
|
|
set commandNotificationTemplateSet
|
|
remove commandNotificationTemplateRemove
|
|
}
|
|
|
|
type notificationTemplateNameArg struct {
|
|
templateName string
|
|
}
|
|
|
|
func (c *notificationTemplateNameArg) setup(svc appServices, cmd *kingpin.CmdClause) {
|
|
cmd.Arg("template", "Template name").Required().HintAction(svc.repositoryHintAction(c.listNotificationTemplates)).StringVar(&c.templateName)
|
|
}
|
|
|
|
func (c *notificationTemplateNameArg) listNotificationTemplates(ctx context.Context, rep repo.Repository) []string {
|
|
infos, _ := notifytemplate.ListTemplates(ctx, rep, c.templateName)
|
|
|
|
var hints []string
|
|
|
|
for _, ti := range infos {
|
|
hints = append(hints, ti.Name)
|
|
}
|
|
|
|
return hints
|
|
}
|
|
|
|
func (c *commandNotificationTemplate) setup(svc appServices, parent commandParent) {
|
|
cmd := parent.Command("template", "Manage templates")
|
|
c.list.setup(svc, cmd)
|
|
c.set.setup(svc, cmd)
|
|
c.show.setup(svc, cmd)
|
|
c.remove.setup(svc, cmd)
|
|
}
|