func printBuildList(buildList *buildapi.BuildList, w io.Writer, withNamespace, wide bool, columnLabels []string) error { sort.Sort(buildapi.ByCreationTimestamp(buildList.Items)) for _, build := range buildList.Items { if err := printBuild(&build, w, withNamespace, wide, columnLabels); err != nil { return err } } return nil }
// RunBuildLogs contains all the necessary functionality for the OpenShift cli build-logs command func RunBuildLogs(f *clientcmd.Factory, out io.Writer, cmd *cobra.Command, opts api.BuildLogOptions, args []string) error { if len(args) != 1 { // maximum time to wait for a list of builds timeout := 800 * time.Millisecond // maximum number of builds to list maxBuildListLen := 10 ch := make(chan error) go func() { // TODO fetch via API no more than maxBuildListLen builds builds, err := getBuilds(f) if err != nil { return } if len(builds) == 0 { ch <- cmdutil.UsageError(cmd, "There are no builds in the current project") return } sort.Sort(sort.Reverse(api.ByCreationTimestamp(builds))) msg := "A build name is required. Most recent builds:" for i, b := range builds { if i == maxBuildListLen { break } msg += fmt.Sprintf("\n* %s\t%s\t%s ago", b.Name, b.Status.Phase, units.HumanDuration(time.Since(b.CreationTimestamp.Time))) } ch <- cmdutil.UsageError(cmd, msg) }() select { case <-time.After(timeout): return cmdutil.UsageError(cmd, "A build name is required") case err := <-ch: return err } } namespace, _, err := f.DefaultNamespace() if err != nil { return err } c, _, err := f.Clients() if err != nil { return err } readCloser, err := c.BuildLogs(namespace).Get(args[0], opts).Stream() if err != nil { return err } defer readCloser.Close() _, err = io.Copy(out, readCloser) return err }