~emersion/public-inbox

hut: pages: Add list v2 APPLIED

Thorben Günther: 1
 pages: Add list

 4 files changed, 46 insertions(+), 0 deletions(-)
#655042 .build.yml success
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~emersion/public-inbox/patches/27593/mbox | git am -3
Learn more about email & git

[PATCH hut v2] pages: Add list Export this patch

---
v1 -> v2:
- Improved output
- Removed cursor handling for now

 doc/hut.1.scd                     |  3 +++
 pages.go                          | 25 +++++++++++++++++++++++++
 srht/pagessrht/gql.go             |  9 +++++++++
 srht/pagessrht/operations.graphql |  9 +++++++++
 4 files changed, 46 insertions(+)

diff --git a/doc/hut.1.scd b/doc/hut.1.scd
index fb4016a..3ebd5b9 100644
--- a/doc/hut.1.scd
+++ b/doc/hut.1.scd
@@ -80,6 +80,9 @@ hut is a CLI companion utility to interact with sr.ht.
	*-p, --protocol* <string>
		Protocol to use (either HTTPS or GEMINI; defaults to HTTPS)

*list*
	List registered sites.

# CONFIGURATION

Generate a new OAuth2 access token on _meta.sr.ht_.
diff --git a/pages.go b/pages.go
index 13182c9..c02ce5b 100644
--- a/pages.go
+++ b/pages.go
@@ -19,6 +19,7 @@ func newPagesCommand() *cobra.Command {
	}
	cmd.AddCommand(newPagesPublishCommand())
	cmd.AddCommand(newPagesUnpublishCommand())
	cmd.AddCommand(newPagesListCommand())
	return cmd
}

@@ -105,6 +106,30 @@ func newPagesUnpublishCommand() *cobra.Command {
	return cmd
}

func newPagesListCommand() *cobra.Command {
	run := func(cmd *cobra.Command, args []string) {
		ctx := cmd.Context()

		c := createClient("pages")

		sites, err := pagessrht.Sites(c.Client, ctx)
		if err != nil {
			log.Fatalf("failed to list sites: %v", err)
		}

		for _, site := range sites.Results {
			fmt.Printf("%s (%s)\n", site.Domain, site.Protocol)
		}
	}

	cmd := &cobra.Command{
		Use:   "list",
		Short: "List registered sites",
		Run:   run,
	}
	return cmd
}

func getProtocol(protocol string) (pagessrht.Protocol, error) {
	switch strings.ToLower(protocol) {
	case "https":
diff --git a/srht/pagessrht/gql.go b/srht/pagessrht/gql.go
index a918cb0..2c51f1c 100644
--- a/srht/pagessrht/gql.go
+++ b/srht/pagessrht/gql.go
@@ -94,3 +94,12 @@ func Unpublish(client *gqlclient.Client, ctx context.Context, domain string, pro
	err = client.Execute(ctx, op, &respData)
	return respData.Unpublish, err
}

func Sites(client *gqlclient.Client, ctx context.Context) (sites SiteCursor, err error) {
	op := gqlclient.NewOperation("query sites {\n\tsites {\n\t\tresults {\n\t\t\tdomain\n\t\t\tprotocol\n\t\t}\n\t}\n}\n")
	var respData struct {
		Sites SiteCursor
	}
	err = client.Execute(ctx, op, &respData)
	return respData.Sites, err
}
diff --git a/srht/pagessrht/operations.graphql b/srht/pagessrht/operations.graphql
index f177f3b..3b9652d 100644
--- a/srht/pagessrht/operations.graphql
+++ b/srht/pagessrht/operations.graphql
@@ -9,3 +9,12 @@ mutation unpublish($domain: String!, $protocol: Protocol!) {
        domain
    }
}

query sites {
    sites {
        results {
            domain
            protocol
        }
    }
}
--
2.34.1
hut/patches/.build.yml: SUCCESS in 43s

[pages: Add list][0] v2 from [Thorben Günther][1]

[0]: https://lists.sr.ht/~emersion/public-inbox/patches/27593
[1]: mailto:admin@xenrox.net

✓ #655042 SUCCESS hut/patches/.build.yml https://builds.sr.ht/~emersion/job/655042
Pushed, thanks!