Skip to content

Commit

Permalink
✨ Add flag groups
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Jun 6, 2023
1 parent c63b827 commit 2244aa9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.20

require (
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/go-openapi/runtime v0.17.2
github.com/go-telegram-bot-api/telegram-bot-api/v5 v5.5.1
github.com/gotify/go-api-client/v2 v2.0.4
github.com/likexian/whois v1.15.0
Expand All @@ -26,7 +27,6 @@ require (
github.com/go-openapi/jsonpointer v0.17.0 // indirect
github.com/go-openapi/jsonreference v0.17.0 // indirect
github.com/go-openapi/loads v0.17.0 // indirect
github.com/go-openapi/runtime v0.17.2 // indirect
github.com/go-openapi/spec v0.17.0 // indirect
github.com/go-openapi/strfmt v0.17.0 // indirect
github.com/go-openapi/swag v0.17.0 // indirect
Expand Down
11 changes: 8 additions & 3 deletions internal/integration/gotify.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"net/url"

"github.com/gabe565/domain-watch/internal/util"
"github.com/go-openapi/runtime"
"github.com/gotify/go-api-client/v2/auth"
"github.com/gotify/go-api-client/v2/client"
"github.com/gotify/go-api-client/v2/client/message"
Expand All @@ -18,7 +19,7 @@ import (

type Gotify struct {
URL *url.URL
token string
auth runtime.ClientAuthInfoWriter
client *client.GotifyREST
}

Expand All @@ -39,6 +40,8 @@ func (g *Gotify) Flags(cmd *cobra.Command) error {
panic(err)
}

cmd.MarkFlagsRequiredTogether("gotify-url", "gotify-token")

return nil
}

Expand All @@ -53,9 +56,11 @@ func (g *Gotify) Setup() error {
return err
}

if g.token = viper.GetString("gotify.token"); g.token == "" {
token := viper.GetString("gotify.token")
if token == "" {
return fmt.Errorf("gotify %w: chat ID", util.ErrNotConfigured)
}
g.auth = auth.TokenAuth(token)

return g.Login(serverUrl)
}
Expand Down Expand Up @@ -90,6 +95,6 @@ func (g *Gotify) Send(text string) error {
},
}

_, err := g.client.Message.CreateMessage(payload, auth.TokenAuth(g.token))
_, err := g.client.Message.CreateMessage(payload, g.auth)
return err
}
2 changes: 2 additions & 0 deletions internal/integration/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func (t *Telegram) Flags(cmd *cobra.Command) error {
panic(err)
}

cmd.MarkFlagsRequiredTogether("telegram-token", "telegram-chat")

return nil
}

Expand Down

0 comments on commit 2244aa9

Please sign in to comment.