From 95a9747ccc9791d03fdbdf2d7c94bca3571e769b Mon Sep 17 00:00:00 2001 From: Ali Hesari Date: Sun, 20 Sep 2026 03:54:01 +0200 Subject: [PATCH] feat(ads): list the ad networks the deployment knows `fopost ads networks` prints the API's registry with what each network supports, so a second network shows up without a CLI change. Tracks the Go SDK branch until it is released. --- README.md | 2 +- go.mod | 2 +- go.sum | 2 ++ internal/cmd/ads.go | 50 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 53 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a8792cc..cedd016 100644 --- a/README.md +++ b/README.md @@ -216,7 +216,7 @@ fopost labels list · create · delete fopost analytics overview · top-posts · time-series fopost automations list · get · toggle · trigger · runs fopost webhooks list · create · test · delete -fopost ads tree · pause · resume · insights · leads +fopost ads networks · tree · pause · resume · insights · leads fopost completion bash · zsh · fish · powershell fopost version ``` diff --git a/go.mod b/go.mod index efaecb8..806d516 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/fopost/fopost-cli go 1.22 require ( - github.com/fopost/fopost-go v0.2.1-0.20260919224127-0a4908e7b1fc + github.com/fopost/fopost-go v0.2.1-0.20260920012830-b5821a03fe6c github.com/spf13/cobra v1.10.2 golang.org/x/term v0.27.0 ) diff --git a/go.sum b/go.sum index 66c7c85..789c47c 100644 --- a/go.sum +++ b/go.sum @@ -1,6 +1,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= github.com/fopost/fopost-go v0.2.1-0.20260919224127-0a4908e7b1fc h1:XzQsDXpqdmHo0fbAs07vVyESqW2fFC1WdNAPjHTssG8= github.com/fopost/fopost-go v0.2.1-0.20260919224127-0a4908e7b1fc/go.mod h1:Qz+7UCYTBnDEeZqB3VMrePxmYLVR9rFvx3+QWcKND8Q= +github.com/fopost/fopost-go v0.2.1-0.20260920012830-b5821a03fe6c h1:ibZpYpABab8UvioId3DNQMRzRsCVXJJ19imHoeg1C1Q= +github.com/fopost/fopost-go v0.2.1-0.20260920012830-b5821a03fe6c/go.mod h1:Qz+7UCYTBnDEeZqB3VMrePxmYLVR9rFvx3+QWcKND8Q= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= diff --git a/internal/cmd/ads.go b/internal/cmd/ads.go index 9bb8426..d594895 100644 --- a/internal/cmd/ads.go +++ b/internal/cmd/ads.go @@ -2,6 +2,7 @@ package cmd import ( "fmt" + "sort" "strings" fopost "github.com/fopost/fopost-go" @@ -15,9 +16,10 @@ func init() { register(newAdsCmd) } func newAdsCmd(state *State) *cobra.Command { cmd := &cobra.Command{ Use: "ads", - Short: "Inspect Meta campaigns, change their status, and read insights and leads", + Short: "Inspect campaigns, change their status, and read insights and leads", } cmd.AddCommand( + newAdsNetworksCmd(state), newAdsTreeCmd(state), newAdsStatusCmd(state, "pause", fopost.AdStatusPaused), newAdsStatusCmd(state, "resume", fopost.AdStatusActive), @@ -27,6 +29,52 @@ func newAdsCmd(state *State) *cobra.Command { return cmd } +func newAdsNetworksCmd(state *State) *cobra.Command { + return &cobra.Command{ + Use: "networks", + Short: "List the ad networks this deployment knows and what each one supports", + Long: "Lists every ad network in the API's registry. A network reported as not " + + "configured is listed but cannot be connected yet.", + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, _ []string) error { + client, err := state.Client() + if err != nil { + return err + } + providers, err := client.Ads.Providers(cmd.Context()) + if err != nil { + return err + } + printer := state.Printer() + return printer.Value(providers, func() { + rows := make([][]string, 0, len(providers)) + for _, provider := range providers { + rows = append(rows, []string{ + provider.ID, + output.Truncate(provider.Name, 24), + boolLabel(provider.Configured, "yes", "no"), + output.Truncate(strings.Join(provider.ConnectMethods, ", "), 20), + output.Truncate(strings.Join(capabilityNames(provider.Capabilities), ", "), 48), + }) + } + printer.Table([]string{"id", "name", "configured", "logins", "supports"}, rows) + }) + }, + } +} + +// The capabilities a network answers true for, sorted so the table is stable. +func capabilityNames(capabilities map[string]bool) []string { + names := make([]string, 0, len(capabilities)) + for name, supported := range capabilities { + if supported { + names = append(names, name) + } + } + sort.Strings(names) + return names +} + func minorAmount(minor *int) string { if minor == nil { return "-"