From 68385916831d7198f07291293e1210e3002af921 Mon Sep 17 00:00:00 2001 From: Jiang Xin Date: Fri, 19 Apr 2024 19:25:58 +0800 Subject: [PATCH] team: add -L to show language Signed-off-by: Jiang Xin --- cmd/team.go | 5 +++++ util/team.go | 24 +++++++++++++++--------- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/cmd/team.go b/cmd/team.go index 09a4b72..5252901 100644 --- a/cmd/team.go +++ b/cmd/team.go @@ -32,12 +32,17 @@ func (v *teamCommand) Command() *cobra.Command { "m", false, "show all users") + v.cmd.Flags().BoolP("language", + "L", + false, + "show language") v.cmd.Flags().BoolP("check", "c", false, "show all users") _ = viper.BindPFlag("team-leader", v.cmd.Flags().Lookup("leader")) _ = viper.BindPFlag("team-members", v.cmd.Flags().Lookup("members")) + _ = viper.BindPFlag("show-language", v.cmd.Flags().Lookup("language")) _ = viper.BindPFlag("team-check", v.cmd.Flags().Lookup("check")) return v.cmd } diff --git a/util/team.go b/util/team.go index aea19a7..1ef62f8 100644 --- a/util/team.go +++ b/util/team.go @@ -186,11 +186,12 @@ func ParseTeams(fileName string) ([]Team, []error) { // ShowTeams will show leader/members of a team. func ShowTeams(args ...string) bool { var ( - teams []Team - errors []error - optLeader = viper.GetBool("team-leader") - optMembers = viper.GetBool("team-members") - ret = true + teams []Team + errors []error + optLeader = viper.GetBool("team-leader") + optMembers = viper.GetBool("team-members") + optLanguage = viper.GetBool("show-language") + ret = true ) teams, errors = ParseTeams("") if len(errors) != 0 { @@ -204,15 +205,20 @@ func ShowTeams(args ...string) bool { return ret } for _, team := range teams { - if optLeader || optMembers { - fmt.Printf("%s <%s>\n", team.Leader.Name, team.Leader.Email) + prefix := "" + if optLanguage { + fmt.Printf("%s:\n", team.Language) + prefix = "\t" + } + if (optLeader || optMembers) && team.Leader.Name != "" { + fmt.Printf("%s%s <%s>\n", prefix, team.Leader.Name, team.Leader.Email) } if optMembers { for _, member := range team.Members { - fmt.Printf("%s <%s>\n", member.Name, member.Email) + fmt.Printf("%s%s <%s>\n", prefix, member.Name, member.Email) } } - if !optLeader && !optMembers { + if !optLeader && !optMembers && !optLanguage { fmt.Println(team.Language) } }