forked from projectatomic/atomic-enterprise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildlogs.go
49 lines (36 loc) · 1.03 KB
/
buildlogs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package cmd
import (
"fmt"
"io"
"github.com/spf13/cobra"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
)
const buildLogsLongDesc = `Retrieve logs from the containers where the build occured
NOTE: This command may be moved in the future.
Examples:
# Stream logs from container to stdout
$ %[1]s build-logs 566bed879d2d
`
func NewCmdBuildLogs(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "build-logs <build>",
Short: "Show container logs from the build container",
Long: fmt.Sprintf(buildLogsLongDesc, fullName),
Run: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
usageError(cmd, "<build> is a required argument")
}
namespace, err := f.DefaultNamespace(cmd)
checkErr(err)
c, _, err := f.Clients(cmd)
checkErr(err)
request := c.BuildLogs(namespace).Redirect(args[0])
readCloser, err := request.Stream()
checkErr(err)
defer readCloser.Close()
_, err = io.Copy(out, readCloser)
checkErr(err)
},
}
return cmd
}