From e4d66f7a28a145810280519bd242a523544a72f6 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Mon, 16 Dec 2019 23:40:32 +0800 Subject: [PATCH] feat: add size for gitt --- cmd/git_cmd.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cmd/git_cmd.go b/cmd/git_cmd.go index a3c0d11..9f22519 100644 --- a/cmd/git_cmd.go +++ b/cmd/git_cmd.go @@ -21,6 +21,12 @@ var gitCmd *cobra.Command = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { message := BuildCommitMessage() isFullMessage := cmd.Flag("basic").Value.String() == "true" + size := cmd.Flag("size").Value.String() + + intSize, err := strconv.Atoi(size) + if err != nil { + intSize = 20 + } if cmd.Flag("basic").Value.String() == "true" { table := tablewriter.NewWriter(os.Stdout) @@ -40,8 +46,8 @@ var gitCmd *cobra.Command = &cobra.Command{ teamSummary := GetTeamSummary(message) table.SetHeader([]string{"EntityName", "RevsCount", "AuthorCount"}) - if len(teamSummary) > 20 && isFullMessage { - teamSummary = teamSummary[:20] + if len(teamSummary) > intSize && isFullMessage { + teamSummary = teamSummary[:intSize] } for _, v := range teamSummary { table.Append([]string{v.EntityName, strconv.Itoa(v.RevsCount), strconv.Itoa(v.AuthorCount)}) @@ -55,8 +61,8 @@ var gitCmd *cobra.Command = &cobra.Command{ age := CalculateCodeAge(message) table.SetHeader([]string{"File", "Month"}) - if len(age) > 20 && isFullMessage { - age = age[:20] + if len(age) > intSize && isFullMessage { + age = age[:intSize] } for _, v := range age { table.Append([]string{v.File, v.Month}) @@ -70,8 +76,8 @@ var gitCmd *cobra.Command = &cobra.Command{ authors := GetTopAuthors(message) table.SetHeader([]string{"Author", "CommitCount", "LineCount"}) - if len(authors) > 20 && isFullMessage { - authors = authors[:20] + if len(authors) > intSize && isFullMessage { + authors = authors[:intSize] } for _, v := range authors { table.Append([]string{v.Name, strconv.Itoa(v.CommitCount), strconv.Itoa(v.LineCount)}) @@ -101,5 +107,6 @@ func init() { gitCmd.PersistentFlags().BoolP("age", "a", false, "Code Age") gitCmd.PersistentFlags().BoolP("top", "o", false, "Top Authors") gitCmd.PersistentFlags().BoolP("full", "f", false, "full") + gitCmd.PersistentFlags().IntP("size", "s", 20, "full") gitCmd.PersistentFlags().StringVar(&relatedConfig, "r", "", "related") } -- GitLab