Skip to content

Commit 2c17f63

Browse files
committed
Render single repo
1 parent 1e362c3 commit 2c17f63

File tree

7 files changed

+61
-17
lines changed

7 files changed

+61
-17
lines changed

cmd/export.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ func export(data []stat.Data, tp string) error {
5555
if err != nil {
5656
return err
5757
}
58-
t := createTable(list, false)
58+
t := createTable(list, false, true)
59+
// solve garbled characters
60+
buffer.WriteString("\xEF\xBB\xBF")
5961
buffer.WriteString(t.RenderCSV())
6062
default:
6163
return fmt.Errorf("invalid type %q", tp)

cmd/pretty.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package cmd
2525
type style string
2626

2727
const (
28-
styleJSON style = "json"
29-
styleYAML style = "yaml"
30-
styleTable style = "table"
28+
styleJSON style = "json"
29+
styleYAML style = "yaml"
30+
styleTermUI style = "ui"
3131
)

cmd/render.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func render(printStyle style, list ...stat.Data) error {
5555
return renderDetail(list[0], data[0])
5656
}
5757

58-
t := createTable(data, true)
58+
t := createTable(data, true, false)
5959
t.SetStyle(table.StyleLight)
6060
prettyText = t.Render()
6161
}
@@ -75,9 +75,19 @@ func convert2ViperList(list []stat.Data) ([]*viper.Viper, error) {
7575
return data, nil
7676
}
7777

78-
func createTable(data []*viper.Viper, emoji bool) table.Writer {
78+
func createTable(data []*viper.Viper, emoji bool, exportCSV bool) table.Writer {
7979
t := table.NewWriter()
80-
t.AppendHeader(createRow("metrics", "fullName", false, data...))
80+
t.AppendHeader(createRow("name", "fullName", false, data...))
81+
if exportCSV {
82+
t.AppendRows([]table.Row{
83+
createRow("description", "description", false, data...),
84+
createRow("tags", "tags", false, data...),
85+
createRow("latestMonthStargazers", "latestMonthStargazers.data", false, data...),
86+
createRow("latestWeekForks", "latestWeekForks.data", false, data...),
87+
createRow("latestWeekCommits", "latestWeekCommits.data", false, data...),
88+
createRow("latestWeekIssues", "latestWeekIssues.data", false, data...),
89+
})
90+
}
8191
t.AppendRows([]table.Row{
8292
createRow("homepage", "homepage", emoji, data...),
8393
createRow("language", "language", emoji, data...),
@@ -147,7 +157,13 @@ func createRow(title string, field string, emoji bool, data ...*viper.Viper) tab
147157
return ret
148158
}
149159

150-
// const barWidth = 3
160+
func createCSVRow(title string, field string, data ...*viper.Viper) []string {
161+
ret := []string{title}
162+
for _, e := range data {
163+
ret = append(ret, fmt.Sprintf("%v", e.Get(field)))
164+
}
165+
return ret
166+
}
151167

152168
func renderDetail(st stat.Data, data *viper.Viper) error {
153169
if err := ui.Init(); err != nil {

cmd/root.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const codeFailure = 1
3838
var (
3939
githubAccessToken string
4040
jsonStyle bool
41-
tableStyle bool
41+
termUIStyle bool
4242
yamlStyle bool
4343

4444
rootCmd = &cobra.Command{
@@ -50,15 +50,16 @@ var (
5050
return err
5151
}
5252

53-
printStyle := styleTable
53+
printStyle := styleTermUI
5454
if jsonStyle {
5555
printStyle = styleJSON
5656
} else if yamlStyle {
5757
printStyle = styleYAML
5858
}
5959

60-
data, err := getData(printStyle == styleTable && len(outputFile) == 0 && len(args) > 1,
61-
args...)
60+
// Only rendering color when print to terminal and there are more than 1 repositories
61+
renderColor := printStyle == styleTermUI && len(outputFile) == 0 && len(args) > 1
62+
data, err := getData(renderColor, args...)
6263
if err != nil {
6364
return err
6465
}
@@ -83,7 +84,7 @@ func getExportType(outputFile string, printStyle style) string {
8384
case "csv":
8485
return exportTPCSV
8586
default:
86-
if printStyle != styleTable {
87+
if printStyle != styleTermUI {
8788
return string(printStyle)
8889
}
8990
return exportTPJSON
@@ -93,11 +94,11 @@ func getExportType(outputFile string, printStyle style) string {
9394
func init() {
9495
rootCmd.PersistentFlags().StringVarP(&githubAccessToken, "token", "t", "",
9596
"github access token")
96-
rootCmd.PersistentFlags().BoolVar(&tableStyle, "table", true,
97-
"print with table style(default)")
97+
rootCmd.PersistentFlags().BoolVar(&termUIStyle, "ui", true, "print with term ui style(default)")
9898
rootCmd.PersistentFlags().BoolVar(&jsonStyle, "json", false, "print with json style")
9999
rootCmd.PersistentFlags().BoolVar(&yamlStyle, "yaml", false, "print with yaml style")
100100
rootCmd.PersistentFlags().StringVarP(&outputFile, "file", "f", "", "output to a specified file")
101+
rootCmd.Version = version
101102
}
102103

103104
func Execute() {

cmd/version.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2022 anqiansong
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
package cmd
24+
25+
const version = "1.0.0"

pkg/stat/overview.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ type (
6565
}
6666

6767
Chart struct {
68-
Data []float64
69-
Labels []string
68+
Data []float64 `json:"data"`
69+
Labels []string `json:"labels"`
7070
}
7171
)
7272

resource/repo-detail.png

306 KB
Loading

0 commit comments

Comments
 (0)