summaryrefslogtreecommitdiffstats
path: root/cmd/skiptrace.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/skiptrace.go')
-rw-r--r--cmd/skiptrace.go111
1 files changed, 89 insertions, 22 deletions
diff --git a/cmd/skiptrace.go b/cmd/skiptrace.go
index 0f89ed6..d8c439a 100644
--- a/cmd/skiptrace.go
+++ b/cmd/skiptrace.go
@@ -2,11 +2,11 @@ package cmd
import (
"fmt"
- "strconv"
"git.db.org.ai/dborg/internal/client"
"git.db.org.ai/dborg/internal/formatter"
"git.db.org.ai/dborg/internal/models"
+ "git.db.org.ai/dborg/internal/tui"
"github.com/spf13/cobra"
)
@@ -19,6 +19,14 @@ Note: All skiptrace commands require a premium API key. If you receive a 403 err
contact support to upgrade your account for premium access.`,
}
+var skiptraceWizardCmd = &cobra.Command{
+ Use: "wizard",
+ Short: "Interactive wizard to search for a person and generate a report",
+ Long: `Launch an interactive wizard with a form to enter search criteria,
+then select from results in a table view to generate a detailed report.`,
+ RunE: runSkiptraceWizard,
+}
+
var skiptracePeopleCmd = &cobra.Command{
Use: "people",
Short: "Search for people by name",
@@ -26,14 +34,6 @@ var skiptracePeopleCmd = &cobra.Command{
RunE: runSkiptracePeople,
}
-var skiptraceReportCmd = &cobra.Command{
- Use: "report [sx_key] [selection]",
- Short: "Get detailed report for selected person",
- Long: `Retrieve detailed report for a person from previous search results using sx_key and selection number`,
- Args: cobra.ExactArgs(2),
- RunE: runSkiptraceReport,
-}
-
var skiptracePhoneCmd = &cobra.Command{
Use: "phone [phone_number]",
Short: "Search for phone number",
@@ -50,12 +50,21 @@ var skiptraceEmailCmd = &cobra.Command{
RunE: runSkiptraceEmail,
}
+var skiptraceReportCmd = &cobra.Command{
+ Use: "report [sx_key] [selection]",
+ Short: "Get a person report by sx_key and selection number",
+ Long: `Generate a detailed report for a person using the sx_key from a people search and selection number`,
+ Args: cobra.ExactArgs(2),
+ RunE: runSkiptraceReport,
+}
+
func init() {
rootCmd.AddCommand(skiptraceCmd)
skiptraceCmd.AddCommand(skiptracePeopleCmd)
- skiptraceCmd.AddCommand(skiptraceReportCmd)
skiptraceCmd.AddCommand(skiptracePhoneCmd)
skiptraceCmd.AddCommand(skiptraceEmailCmd)
+ skiptraceCmd.AddCommand(skiptraceWizardCmd)
+ skiptraceCmd.AddCommand(skiptraceReportCmd)
skiptracePeopleCmd.Flags().StringP("first-name", "f", "", "First name (required)")
skiptracePeopleCmd.Flags().StringP("last-name", "l", "", "Last name (required)")
@@ -64,6 +73,8 @@ func init() {
skiptracePeopleCmd.Flags().StringP("age", "a", "", "Age")
skiptracePeopleCmd.MarkFlagRequired("first-name")
skiptracePeopleCmd.MarkFlagRequired("last-name")
+
+ skiptraceWizardCmd.Flags().BoolP("json", "j", false, "Output raw JSON instead of formatted display")
}
func getSkiptraceClient(cmd *cobra.Command) (*client.Client, error) {
@@ -100,19 +111,13 @@ func runSkiptracePeople(cmd *cobra.Command, args []string) error {
return nil
}
-func runSkiptraceReport(cmd *cobra.Command, args []string) error {
+func runSkiptracePhone(cmd *cobra.Command, args []string) error {
c, err := getSkiptraceClient(cmd)
if err != nil {
return err
}
- sxKey := args[0]
- selection, err := strconv.Atoi(args[1])
- if err != nil {
- return fmt.Errorf("invalid selection number: %s", args[1])
- }
-
- response, err := c.GetPersonReport(sxKey, selection)
+ response, err := c.SearchPhone(args[0])
if err != nil {
return err
}
@@ -129,13 +134,13 @@ func runSkiptraceReport(cmd *cobra.Command, args []string) error {
return nil
}
-func runSkiptracePhone(cmd *cobra.Command, args []string) error {
+func runSkiptraceEmail(cmd *cobra.Command, args []string) error {
c, err := getSkiptraceClient(cmd)
if err != nil {
return err
}
- response, err := c.SearchPhone(args[0])
+ response, err := c.SearchEmail(args[0])
if err != nil {
return err
}
@@ -152,13 +157,23 @@ func runSkiptracePhone(cmd *cobra.Command, args []string) error {
return nil
}
-func runSkiptraceEmail(cmd *cobra.Command, args []string) error {
+func runSkiptraceReport(cmd *cobra.Command, args []string) error {
c, err := getSkiptraceClient(cmd)
if err != nil {
return err
}
- response, err := c.SearchEmail(args[0])
+ sxKey := args[0]
+ selection := 0
+ if _, err := fmt.Sscanf(args[1], "%d", &selection); err != nil {
+ return fmt.Errorf("invalid selection number: %s", args[1])
+ }
+
+ if selection <= 0 {
+ return fmt.Errorf("selection must be a positive integer")
+ }
+
+ response, err := c.GetPersonReport(sxKey, selection)
if err != nil {
return err
}
@@ -174,3 +189,55 @@ func runSkiptraceEmail(cmd *cobra.Command, args []string) error {
printOutput(output)
return nil
}
+
+func runSkiptraceWizard(cmd *cobra.Command, args []string) error {
+ c, err := getSkiptraceClient(cmd)
+ if err != nil {
+ return err
+ }
+
+ jsonOutput, _ := cmd.Flags().GetBool("json")
+
+ searchFn := func(firstName, lastName, city, state, age string) (map[string]interface{}, string, error) {
+ params := &models.SkiptraceParams{
+ FirstName: firstName,
+ LastName: lastName,
+ City: city,
+ State: state,
+ Age: age,
+ }
+
+ response, err := c.SearchPeople(params)
+ if err != nil {
+ return nil, "", err
+ }
+
+ if response.Error != "" {
+ return nil, "", fmt.Errorf("%s", response.Error)
+ }
+
+ sxKey := response.SXKey
+ if sxKey == "" {
+ if key, ok := response.Data["sx_key"].(string); ok {
+ sxKey = key
+ }
+ }
+
+ return response.Data, sxKey, nil
+ }
+
+ reportFn := func(sxKey string, selection int) (map[string]interface{}, error) {
+ response, err := c.GetPersonReport(sxKey, selection)
+ if err != nil {
+ return nil, err
+ }
+
+ if response.Error != "" {
+ return nil, fmt.Errorf("%s", response.Error)
+ }
+
+ return response.Data, nil
+ }
+
+ return tui.RunSkiptraceWizard(searchFn, reportFn, jsonOutput)
+}