未验证 提交 f79754a1 编写于 作者: P Phodal Huang

refactor: use intvarp as parameter parse

上级 fbefa1ba
...@@ -10,23 +10,23 @@ import ( ...@@ -10,23 +10,23 @@ import (
"strconv" "strconv"
) )
type GitCmdConfig struct {
Size int
}
var ( var (
relatedConfig string relatedConfig string
gitCmdConfig GitCmdConfig
) )
var gitCmd *cobra.Command = &cobra.Command{ var gitCmd *cobra.Command = &cobra.Command{
Use: "ga", Use: "git",
Short: "git analysis", Short: "git analysis",
Long: ``, Long: ``,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
message := BuildCommitMessage() message := BuildCommitMessage()
isFullMessage := cmd.Flag("basic").Value.String() == "true" isFullMessage := cmd.Flag("basic").Value.String() == "true"
size := cmd.Flag("size").Value.String() size := gitCmdConfig.Size
intSize, err := strconv.Atoi(size)
if err != nil {
intSize = 20
}
if cmd.Flag("basic").Value.String() == "true" { if cmd.Flag("basic").Value.String() == "true" {
table := tablewriter.NewWriter(os.Stdout) table := tablewriter.NewWriter(os.Stdout)
...@@ -46,8 +46,8 @@ var gitCmd *cobra.Command = &cobra.Command{ ...@@ -46,8 +46,8 @@ var gitCmd *cobra.Command = &cobra.Command{
teamSummary := GetTeamSummary(message) teamSummary := GetTeamSummary(message)
table.SetHeader([]string{"EntityName", "RevsCount", "AuthorCount"}) table.SetHeader([]string{"EntityName", "RevsCount", "AuthorCount"})
if len(teamSummary) > intSize && isFullMessage { if len(teamSummary) > size && isFullMessage {
teamSummary = teamSummary[:intSize] teamSummary = teamSummary[:size]
} }
for _, v := range teamSummary { for _, v := range teamSummary {
table.Append([]string{v.EntityName, strconv.Itoa(v.RevsCount), strconv.Itoa(v.AuthorCount)}) table.Append([]string{v.EntityName, strconv.Itoa(v.RevsCount), strconv.Itoa(v.AuthorCount)})
...@@ -61,8 +61,8 @@ var gitCmd *cobra.Command = &cobra.Command{ ...@@ -61,8 +61,8 @@ var gitCmd *cobra.Command = &cobra.Command{
age := CalculateCodeAge(message) age := CalculateCodeAge(message)
table.SetHeader([]string{"File", "Month"}) table.SetHeader([]string{"File", "Month"})
if len(age) > intSize && isFullMessage { if len(age) > size && isFullMessage {
age = age[:intSize] age = age[:size]
} }
for _, v := range age { for _, v := range age {
table.Append([]string{v.File, v.Month}) table.Append([]string{v.File, v.Month})
...@@ -76,8 +76,8 @@ var gitCmd *cobra.Command = &cobra.Command{ ...@@ -76,8 +76,8 @@ var gitCmd *cobra.Command = &cobra.Command{
authors := GetTopAuthors(message) authors := GetTopAuthors(message)
table.SetHeader([]string{"Author", "CommitCount", "LineCount"}) table.SetHeader([]string{"Author", "CommitCount", "LineCount"})
if len(authors) > intSize && isFullMessage { if len(authors) > size && isFullMessage {
authors = authors[:intSize] authors = authors[:size]
} }
for _, v := range authors { for _, v := range authors {
table.Append([]string{v.Name, strconv.Itoa(v.CommitCount), strconv.Itoa(v.LineCount)}) table.Append([]string{v.Name, strconv.Itoa(v.CommitCount), strconv.Itoa(v.LineCount)})
...@@ -107,6 +107,6 @@ func init() { ...@@ -107,6 +107,6 @@ func init() {
gitCmd.PersistentFlags().BoolP("age", "a", false, "Code Age") gitCmd.PersistentFlags().BoolP("age", "a", false, "Code Age")
gitCmd.PersistentFlags().BoolP("top", "o", false, "Top Authors") gitCmd.PersistentFlags().BoolP("top", "o", false, "Top Authors")
gitCmd.PersistentFlags().BoolP("full", "f", false, "full") gitCmd.PersistentFlags().BoolP("full", "f", false, "full")
gitCmd.PersistentFlags().IntP("size", "s", 20, "full") gitCmd.PersistentFlags().IntVarP(&gitCmdConfig.Size, "size", "s", 20, "full")
gitCmd.PersistentFlags().StringVar(&relatedConfig, "r", "", "related") gitCmd.PersistentFlags().StringVar(&relatedConfig, "r", "", "related")
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册