unified output (#14) (#40)

This commit is contained in:
root360-AndreasUlm
2019-09-15 08:38:18 +00:00
committed by Gitea
parent 1d233402fd
commit 7c024bcd69
24 changed files with 2866 additions and 12 deletions

View File

@@ -5,14 +5,16 @@
package cmd
import (
"fmt"
"log"
"strconv"
"code.gitea.io/sdk/gitea"
"github.com/urfave/cli"
)
var output string
// CmdPulls represents to login a gitea server.
var CmdPulls = cli.Command{
Name: "pulls",
@@ -28,6 +30,11 @@ var CmdPulls = cli.Command{
Name: "repo, r",
Usage: "Indicate one repository, optional when inside a gitea repository",
},
cli.StringFlag{
Name: "output, o",
Usage: outputUsage,
Destination: &output,
},
},
}
@@ -43,8 +50,17 @@ func runPulls(ctx *cli.Context) error {
log.Fatal(err)
}
headers := []string{
"Index",
"Name",
"Updated",
"Title",
}
var values [][]string
if len(prs) == 0 {
fmt.Println("No pull requests left")
Output(output, headers, values)
return nil
}
@@ -56,8 +72,17 @@ func runPulls(ctx *cli.Context) error {
if len(name) == 0 {
name = pr.Poster.UserName
}
fmt.Printf("#%d\t%s\t%s\t%s\n", pr.Index, name, pr.Updated.Format("2006-01-02 15:04:05"), pr.Title)
values = append(
values,
[]string{
strconv.FormatInt(pr.Index, 10),
name,
pr.Updated.Format("2006-01-02 15:04:05"),
pr.Title,
},
)
}
Output(output, headers, values)
return nil
}