summaryrefslogtreecommitdiffstats
path: root/cmd/email.go
blob: f4306ec7f51d3bbee78224c638ae05e40e6e8513 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package cmd

import (
	"git.db.org.ai/dborg/internal/formatter"
	"github.com/spf13/cobra"
)

var emailCmd = &cobra.Command{
	Use:   "email",
	Short: "Email verification commands",
	Long:  `Verify email addresses and check deliverability`,
}

var verifyEmailCmd = &cobra.Command{
	Use:   "verify [email]",
	Short: "Verify email address",
	Long:  `Performs comprehensive email verification including format validation, MX records check, SMTP verification, and disposable/webmail detection`,
	Args:  cobra.ExactArgs(1),
	RunE:  runVerifyEmail,
}

func init() {
	rootCmd.AddCommand(emailCmd)
	emailCmd.AddCommand(verifyEmailCmd)
}

func runVerifyEmail(cmd *cobra.Command, args []string) error {
	email := args[0]

	c, err := newClient()
	if err != nil {
		return err
	}

	response, err := c.VerifyEmail(email)
	if err != nil {
		return err
	}

	if err := checkError(response.Error); err != nil {
		return err
	}

	return formatter.FormatEmailResults(response, IsJSONOutput())
}