diff --git a/cmd/cmd.go b/cmd/cmd.go index 67c5f27..d532940 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -36,10 +36,6 @@ func run(cmd *cobra.Command, args []string) error { return err } - if conf.Completion != "" { - return completion(cmd, conf.Completion) - } - slog.Info("Domain Watch", "version", cobrax.GetVersion(cmd), "commit", cobrax.GetCommit(cmd)) integrations, err := integration.Setup(cmd.Context(), conf) diff --git a/cmd/completion.go b/cmd/completion.go deleted file mode 100644 index f77c84a..0000000 --- a/cmd/completion.go +++ /dev/null @@ -1,25 +0,0 @@ -package cmd - -import ( - "errors" - "fmt" - - "github.com/spf13/cobra" -) - -var ErrInvalidShell = errors.New("invalid shell") - -func completion(cmd *cobra.Command, shell string) error { - switch shell { - case "bash": - return cmd.Root().GenBashCompletion(cmd.OutOrStdout()) - case "zsh": - return cmd.Root().GenZshCompletion(cmd.OutOrStdout()) - case "fish": - return cmd.Root().GenFishCompletion(cmd.OutOrStdout(), true) - case "powershell": - return cmd.Root().GenPowerShellCompletionWithDesc(cmd.OutOrStdout()) - default: - return fmt.Errorf("%w: %s", ErrInvalidShell, shell) - } -} diff --git a/docs/domain-watch.md b/docs/domain-watch.md index 7c3ac89..6cc51cd 100644 --- a/docs/domain-watch.md +++ b/docs/domain-watch.md @@ -9,7 +9,7 @@ domain-watch [flags] domain... ### Options ``` - --completion string Output command-line completion code for the specified shell. Can be 'bash', 'zsh', 'fish', or 'powershell'. + --completion string Generate the autocompletion script for the specified shell (one of bash, zsh, fish, powershell) --domains strings List of domains to watch -e, --every duration Enable cron mode and configure update interval --gotify-token string Gotify app token diff --git a/go.mod b/go.mod index 8fa9981..eebfb69 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gabe565.com/domain-watch go 1.23.3 require ( - gabe565.com/utils v0.0.0-20241114234101-e128cd3269b5 + gabe565.com/utils v0.0.0-20241116061915-abe2278ecd5c github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/dmarkham/enumer v1.5.10 github.com/go-telegram/bot v1.10.1 diff --git a/go.sum b/go.sum index 378153c..18f6793 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -gabe565.com/utils v0.0.0-20241114234101-e128cd3269b5 h1:uqtftvk1FMAsFPAT9ICLLntGsZHmrghgIGBClVCsVHk= -gabe565.com/utils v0.0.0-20241114234101-e128cd3269b5/go.mod h1:1WioSVukwGZYG4Q0LJBnRhgYyVljmW2Izl+RW36ALUc= +gabe565.com/utils v0.0.0-20241116061915-abe2278ecd5c h1:1rmGsS/Sbm85ZELLkfOtXJ99v3YHdmqvkhMDLteLUug= +gabe565.com/utils v0.0.0-20241116061915-abe2278ecd5c/go.mod h1:1WioSVukwGZYG4Q0LJBnRhgYyVljmW2Izl+RW36ALUc= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de h1:FxWPpzIjnTlhPwqqXc4/vE0f7GvRjuAsbW+HOIe8KnA= github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de/go.mod h1:DCaWoUhZrYW9p1lxo/cm8EmUOOzAPSEZNGF2DK1dJgw= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= diff --git a/internal/config/completion.go b/internal/config/completion.go index 520e61d..3d4ab72 100644 --- a/internal/config/completion.go +++ b/internal/config/completion.go @@ -9,10 +9,6 @@ import ( ) func RegisterCompletions(cmd *cobra.Command) { - must.Must(cmd.RegisterFlagCompletionFunc(FlagCompletion, func(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) { - return []string{"bash", "zsh", "fish", "powershell"}, cobra.ShellCompDirectiveNoFileComp - })) - must.Must(cmd.RegisterFlagCompletionFunc(FlagDomains, cobra.NoFileCompletions)) must.Must(cmd.RegisterFlagCompletionFunc(FlagEvery, cobra.NoFileCompletions)) must.Must(cmd.RegisterFlagCompletionFunc(FlagSleep, cobra.NoFileCompletions)) diff --git a/internal/config/config.go b/internal/config/config.go index 4f700e1..f61f614 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -7,8 +7,6 @@ import ( ) type Config struct { - Completion string - Domains []string Every time.Duration Sleep time.Duration diff --git a/internal/config/flags.go b/internal/config/flags.go index 036a0ed..45df042 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -3,12 +3,12 @@ package config import ( "strings" + "gabe565.com/utils/cobrax" + "gabe565.com/utils/must" "github.com/spf13/cobra" ) const ( - FlagCompletion = "completion" - FlagDomains = "domains" FlagEvery = "every" FlagSleep = "sleep" @@ -29,7 +29,7 @@ const ( func (c *Config) RegisterFlags(cmd *cobra.Command) { fs := cmd.Flags() - fs.StringVar(&c.Completion, FlagCompletion, c.Completion, "Output command-line completion code for the specified shell. Can be 'bash', 'zsh', 'fish', or 'powershell'.") + must.Must(cobrax.RegisterCompletionFlag(cmd)) fs.StringSliceVar(&c.Domains, FlagDomains, c.Domains, "List of domains to watch") fs.DurationVarP(&c.Every, FlagEvery, "e", c.Every, "Enable cron mode and configure update interval")