2022-10-16 12:58:13 +00:00
|
|
|
// Copyright 2022 Woodpecker Authors
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
package pipeline
|
2022-10-16 12:58:13 +00:00
|
|
|
|
|
|
|
import (
|
2024-05-02 06:43:46 +00:00
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
|
2024-07-17 23:26:35 +00:00
|
|
|
"github.com/urfave/cli/v3"
|
2024-05-02 06:43:46 +00:00
|
|
|
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/cli/output"
|
2024-11-28 17:25:49 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/cli/pipeline/deploy"
|
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/cli/pipeline/log"
|
2024-05-02 06:43:46 +00:00
|
|
|
"go.woodpecker-ci.org/woodpecker/v2/woodpecker-go/woodpecker"
|
2022-10-16 12:58:13 +00:00
|
|
|
)
|
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
// Command exports the pipeline command set.
|
|
|
|
var Command = &cli.Command{
|
2023-10-19 16:05:41 +00:00
|
|
|
Name: "pipeline",
|
|
|
|
Usage: "manage pipelines",
|
2024-07-17 23:26:35 +00:00
|
|
|
Commands: []*cli.Command{
|
2024-11-18 18:40:45 +00:00
|
|
|
buildPipelineListCmd(),
|
2022-10-18 01:24:12 +00:00
|
|
|
pipelineLastCmd,
|
|
|
|
pipelineLogsCmd,
|
|
|
|
pipelineInfoCmd,
|
|
|
|
pipelineStopCmd,
|
|
|
|
pipelineStartCmd,
|
|
|
|
pipelineApproveCmd,
|
|
|
|
pipelineDeclineCmd,
|
|
|
|
pipelineQueueCmd,
|
|
|
|
pipelineKillCmd,
|
|
|
|
pipelinePsCmd,
|
|
|
|
pipelineCreateCmd,
|
2024-11-28 17:25:49 +00:00
|
|
|
log.Command,
|
|
|
|
deploy.Command,
|
2022-10-16 12:58:13 +00:00
|
|
|
},
|
|
|
|
}
|
2024-05-02 06:43:46 +00:00
|
|
|
|
2024-07-17 23:26:35 +00:00
|
|
|
func pipelineOutput(c *cli.Command, resources []woodpecker.Pipeline, fd ...io.Writer) error {
|
2024-05-24 20:35:04 +00:00
|
|
|
outFmt, outOpt := output.ParseOutputOptions(c.String("output"))
|
2024-05-02 06:43:46 +00:00
|
|
|
noHeader := c.Bool("output-no-headers")
|
|
|
|
|
|
|
|
var out io.Writer
|
|
|
|
switch len(fd) {
|
|
|
|
case 0:
|
|
|
|
out = os.Stdout
|
|
|
|
case 1:
|
|
|
|
out = fd[0]
|
|
|
|
default:
|
|
|
|
out = os.Stdout
|
|
|
|
}
|
|
|
|
|
2024-05-24 20:35:04 +00:00
|
|
|
switch outFmt {
|
2024-05-02 06:43:46 +00:00
|
|
|
case "go-template":
|
2024-05-24 20:35:04 +00:00
|
|
|
if len(outOpt) < 1 {
|
2024-05-02 06:43:46 +00:00
|
|
|
return fmt.Errorf("%w: missing template", output.ErrOutputOptionRequired)
|
|
|
|
}
|
|
|
|
|
2024-05-24 20:35:04 +00:00
|
|
|
tmpl, err := template.New("_").Parse(outOpt[0] + "\n")
|
2024-05-02 06:43:46 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := tmpl.Execute(out, resources); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
case "table":
|
|
|
|
fallthrough
|
|
|
|
default:
|
|
|
|
table := output.NewTable(out)
|
2024-07-03 13:58:51 +00:00
|
|
|
cols := []string{"Number", "Status", "Event", "Branch", "Message", "Author"}
|
2024-05-02 06:43:46 +00:00
|
|
|
|
2024-05-24 20:35:04 +00:00
|
|
|
if len(outOpt) > 0 {
|
|
|
|
cols = outOpt
|
2024-05-02 06:43:46 +00:00
|
|
|
}
|
|
|
|
if !noHeader {
|
|
|
|
table.WriteHeader(cols)
|
|
|
|
}
|
|
|
|
for _, resource := range resources {
|
|
|
|
if err := table.Write(cols, resource); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
table.Flush()
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|