From bf97c6e273ff419f22b4da0e9ff9a22bfccc0d12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 2 Mar 2021 20:07:04 +0100 Subject: [PATCH] Add template functions, documentation, tests --- pkg/cmd/api/api.go | 48 ++++++++---------- pkg/cmd/api/api_test.go | 39 +++++++++++++++ pkg/cmd/api/template.go | 96 ++++++++++++++++++++++++++++++++++++ pkg/cmd/api/template_test.go | 60 ++++++++++++++++++++++ 4 files changed, 216 insertions(+), 27 deletions(-) create mode 100644 pkg/cmd/api/template.go create mode 100644 pkg/cmd/api/template_test.go diff --git a/pkg/cmd/api/api.go b/pkg/cmd/api/api.go index ac49d715b..7d7f23a92 100644 --- a/pkg/cmd/api/api.go +++ b/pkg/cmd/api/api.go @@ -7,7 +7,6 @@ import ( "fmt" "io" "io/ioutil" - "math" "net/http" "os" "regexp" @@ -25,7 +24,6 @@ import ( "github.com/cli/cli/pkg/cmdutil" "github.com/cli/cli/pkg/iostreams" "github.com/cli/cli/pkg/jsoncolor" - "github.com/mgutz/ansi" "github.com/spf13/cobra" ) @@ -98,6 +96,17 @@ func NewCmdApi(f *cmdutil.Factory, runF func(*ApiOptions) error) *cobra.Command there are no more pages of results. For GraphQL requests, this requires that the original query accepts an %[1]s$endCursor: String%[1]s variable and that it fetches the %[1]spageInfo{ hasNextPage, endCursor }%[1]s set of fields from a collection. + + With %[1]s--template%[1]s, the provided Go template is rendered using the JSON data as input. + For the syntax of Go templates, see: https://golang.org/pkg/text/template/ + + The following functions are available in templates: + - %[1]scolor