diff options
Diffstat (limited to 'cmd/geo.go')
| -rw-r--r-- | cmd/geo.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/cmd/geo.go b/cmd/geo.go new file mode 100644 index 0000000..6c7caf9 --- /dev/null +++ b/cmd/geo.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "git.db.org.ai/dborg/internal/formatter" + "git.db.org.ai/dborg/internal/models" + "github.com/spf13/cobra" +) + +var geoCmd = &cobra.Command{ + Use: "geo", + Short: "Search for address information", + Long: `Returns address information including residents, property details, and demographics (costs 1 credit)`, + RunE: runGeoSearch, +} + +func init() { + rootCmd.AddCommand(geoCmd) + geoCmd.Flags().StringP("street", "s", "", "Street address") + geoCmd.Flags().StringP("city", "c", "", "City") + geoCmd.Flags().StringP("state", "t", "", "State (2-letter code)") + geoCmd.Flags().StringP("zip", "z", "", "ZIP code") + geoCmd.MarkFlagRequired("street") + geoCmd.MarkFlagRequired("city") + geoCmd.MarkFlagRequired("state") + geoCmd.MarkFlagRequired("zip") +} + +func runGeoSearch(cmd *cobra.Command, args []string) error { + c, err := newClient() + if err != nil { + return err + } + + params := &models.GeoSearchParams{} + params.Street, _ = cmd.Flags().GetString("street") + params.City, _ = cmd.Flags().GetString("city") + params.State, _ = cmd.Flags().GetString("state") + params.Zip, _ = cmd.Flags().GetString("zip") + + response, err := c.SearchGeo(params) + if err != nil { + return err + } + + return formatter.FormatGeoResults(*response, IsJSONOutput()) +} |
