From 8a342848809a26e7e13933180b4df91d4a52f898 Mon Sep 17 00:00:00 2001 From: s Date: Tue, 25 Nov 2025 09:58:42 -0500 Subject: feat: add dns site check, services list, and additional twitter/x api endpoints --- internal/formatter/admin.go | 1 + internal/formatter/dns.go | 35 +++++++++++++++++++++++++++++++++++ internal/formatter/x.go | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) (limited to 'internal/formatter') diff --git a/internal/formatter/admin.go b/internal/formatter/admin.go index 914eaaa..12ffcd0 100644 --- a/internal/formatter/admin.go +++ b/internal/formatter/admin.go @@ -185,3 +185,4 @@ func FormatAccountToggled(message string, asJSON bool) (string, error) { return fmt.Sprintf("%s %s\n", Blue("ℹ"), message), nil } + diff --git a/internal/formatter/dns.go b/internal/formatter/dns.go index 6abd5b0..8e66039 100644 --- a/internal/formatter/dns.go +++ b/internal/formatter/dns.go @@ -1,6 +1,7 @@ package formatter import ( + "bytes" "encoding/json" "fmt" "strings" @@ -55,3 +56,37 @@ func FormatDNSResults(result *models.DomainResult, asJSON bool) (string, error) return sb.String(), nil } + +func FormatDNSSite(resp *models.DNSResponse, asJSON bool) (string, error) { + if asJSON { + data, err := json.MarshalIndent(resp, "", " ") + if err != nil { + return "", fmt.Errorf("failed to marshal JSON: %w", err) + } + return string(data), nil + } + + var buf bytes.Buffer + + if resp.Error != "" { + fmt.Fprintf(&buf, "%s\n", Red(fmt.Sprintf("Error: %s", resp.Error))) + return buf.String(), nil + } + + if resp.Message != "" { + fmt.Fprintf(&buf, "%s\n", Bold(Cyan(resp.Message))) + } + + if resp.Response != "" { + fmt.Fprintf(&buf, "%s\n", resp.Response) + } + + if resp.Data != nil && len(resp.Data) > 0 { + dataJSON, err := json.MarshalIndent(resp.Data, "", " ") + if err == nil { + fmt.Fprintf(&buf, "\n%s\n", string(dataJSON)) + } + } + + return buf.String(), nil +} diff --git a/internal/formatter/x.go b/internal/formatter/x.go index f701797..a79d173 100644 --- a/internal/formatter/x.go +++ b/internal/formatter/x.go @@ -377,3 +377,46 @@ func wrapText(text string, width int) []string { return lines } + +func FormatXGeneric(resp *models.XResponse, asJSON bool) (string, error) { + if asJSON { + data, err := json.MarshalIndent(resp, "", " ") + if err != nil { + return "", fmt.Errorf("failed to marshal JSON: %w", err) + } + return string(data), nil + } + + var buf bytes.Buffer + + if resp.Error != "" { + fmt.Fprintf(&buf, "%s\n", Red(fmt.Sprintf("Error: %s", resp.Error))) + return buf.String(), nil + } + + if resp.Message != "" { + fmt.Fprintf(&buf, "%s\n\n", Bold(Cyan(resp.Message))) + } + + if resp.Response != "" { + fmt.Fprintf(&buf, "%s\n\n", resp.Response) + } + + if resp.Data != nil { + dataJSON, err := json.MarshalIndent(resp.Data, "", " ") + if err == nil { + fmt.Fprintf(&buf, "%s\n", string(dataJSON)) + } + } + + if resp.Credits.Remaining > 0 || resp.Credits.Unlimited { + fmt.Fprintf(&buf, "\n%s ", Blue("Credits Remaining:")) + if resp.Credits.Unlimited { + fmt.Fprintf(&buf, "%s\n", Green("Unlimited")) + } else { + fmt.Fprintf(&buf, "%s\n", FormatCredits(int64(resp.Credits.Remaining))) + } + } + + return buf.String(), nil +} -- cgit v1.2.3