mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-24 09:20:31 +00:00
d22821afc1
* Complete forges overview + add `logs` command to CLI * Update 10-overview.md Co-authored-by: 6543 <6543@obermui.de>
53 lines
895 B
Go
53 lines
895 B
Go
package build
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
|
|
"github.com/woodpecker-ci/woodpecker/cli/common"
|
|
"github.com/woodpecker-ci/woodpecker/cli/internal"
|
|
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
var buildLogsCmd = &cli.Command{
|
|
Name: "logs",
|
|
Usage: "show build logs",
|
|
ArgsUsage: "<repo/name> [build] [job]",
|
|
Action: buildLogs,
|
|
Flags: common.GlobalFlags,
|
|
}
|
|
|
|
func buildLogs(c *cli.Context) error {
|
|
repo := c.Args().First()
|
|
owner, name, err := internal.ParseRepo(repo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
number, err := strconv.Atoi(c.Args().Get(1))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
job, err := strconv.Atoi(c.Args().Get(2))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
client, err := internal.NewClient(c)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
logs, err := client.BuildLogs(owner, name, number, job)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
for _, log := range logs {
|
|
fmt.Print(log.Output)
|
|
}
|
|
|
|
return nil
|
|
}
|