diff --git a/action/log/get.go b/action/log/get.go index 09e0641d..7c5dd0f7 100644 --- a/action/log/get.go +++ b/action/log/get.go @@ -18,10 +18,18 @@ func (c *Config) Get(client *vela.Client) error { logrus.Tracef("capturing logs for build %s/%s/%d", c.Org, c.Repo, c.Build) + // set the pagination options for list of build logs + // + // https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#ListOptions + opts := &vela.ListOptions{ + Page: c.Page, + PerPage: c.PerPage, + } + // send API call to capture a list of build logs // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#BuildService.GetLogs - logs, _, err := client.Build.GetLogs(c.Org, c.Repo, c.Build) + logs, _, err := client.Build.GetLogs(c.Org, c.Repo, c.Build, opts) if err != nil { return err } diff --git a/action/log/log.go b/action/log/log.go index 8285da76..593b4af5 100644 --- a/action/log/log.go +++ b/action/log/log.go @@ -13,5 +13,7 @@ type Config struct { Build int Service int Step int + Page int + PerPage int Output string } diff --git a/command/log/get.go b/command/log/get.go index ff55ba55..8248d371 100644 --- a/command/log/get.go +++ b/command/log/get.go @@ -56,6 +56,23 @@ var CommandGet = &cli.Command{ Aliases: []string{"op"}, Usage: "format the output in json, spew or yaml", }, + + // Pagination Flags + + &cli.IntFlag{ + EnvVars: []string{"VELA_PAGE", "LOG_PAGE"}, + Name: internal.FlagPage, + Aliases: []string{"p"}, + Usage: "print a specific page of build logs", + Value: 1, + }, + &cli.IntFlag{ + EnvVars: []string{"VELA_PER_PAGE", "LOG_PER_PAGE"}, + Name: internal.FlagPerPage, + Aliases: []string{"pp"}, + Usage: "number of build logs to print per page", + Value: 100, // server defaults to 10 + }, }, CustomHelpTemplate: fmt.Sprintf(`%s EXAMPLES: @@ -96,11 +113,13 @@ func get(c *cli.Context) error { // // https://pkg.go.dev/github.com/go-vela/cli/action/log?tab=doc#Config l := &log.Config{ - Action: internal.ActionGet, - Org: c.String(internal.FlagOrg), - Repo: c.String(internal.FlagRepo), - Build: c.Int(internal.FlagBuild), - Output: c.String(internal.FlagOutput), + Action: internal.ActionGet, + Org: c.String(internal.FlagOrg), + Repo: c.String(internal.FlagRepo), + Build: c.Int(internal.FlagBuild), + Page: c.Int(internal.FlagPage), + PerPage: c.Int(internal.FlagPerPage), + Output: c.String(internal.FlagOutput), } // validate log configuration