diff options
author | Michael Muré <batolettre@gmail.com> | 2019-04-03 21:33:53 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2019-04-03 21:33:53 +0200 |
commit | 5b0a92dea43f467f31a65a6f02e937d285cb0a71 (patch) | |
tree | 83db754796427b04d28f03c9a32c09112f84db7c | |
parent | 96d356a34d6eec18c987415aad0b2fa92304c98d (diff) | |
download | git-bug-5b0a92dea43f467f31a65a6f02e937d285cb0a71.tar.gz |
commands: add a --field flag to "git bug user" to display users details individually
-rw-r--r-- | commands/user.go | 36 | ||||
-rw-r--r-- | doc/man/git-bug-user.1 | 4 | ||||
-rw-r--r-- | doc/md/git-bug_user.md | 3 | ||||
-rw-r--r-- | misc/bash_completion/git-bug | 3 |
4 files changed, 45 insertions, 1 deletions
diff --git a/commands/user.go b/commands/user.go index ef5d4991..8cb64491 100644 --- a/commands/user.go +++ b/commands/user.go @@ -9,6 +9,10 @@ import ( "github.com/spf13/cobra" ) +var ( + userFieldsQuery string +) + func runUser(cmd *cobra.Command, args []string) error { backend, err := cache.NewRepoCache(repo) if err != nil { @@ -32,6 +36,35 @@ func runUser(cmd *cobra.Command, args []string) error { return err } + if userFieldsQuery != "" { + switch userFieldsQuery { + case "email": + fmt.Printf("%s\n", id.Email()) + case "humanId": + fmt.Printf("%s\n", id.HumanId()) + case "id": + fmt.Printf("%s\n", id.Id()) + case "lastModification": + fmt.Printf("%s\n", id.LastModification(). + Time().Format("Mon Jan 2 15:04:05 2006 +0200")) + case "lastModificationLamport": + fmt.Printf("%d\n", id.LastModificationLamport()) + case "login": + fmt.Printf("%s\n", id.Login()) + case "metadata": + for key, value := range id.ImmutableMetadata() { + fmt.Printf("%s\n%s\n", key, value) + } + case "name": + fmt.Printf("%s\n", id.Name()) + + default: + return fmt.Errorf("\nUnsupported field: %s\n", userFieldsQuery) + } + + return nil + } + fmt.Printf("Id: %s\n", id.Id()) fmt.Printf("Name: %s\n", id.Name()) fmt.Printf("Login: %s\n", id.Login()) @@ -58,4 +91,7 @@ var userCmd = &cobra.Command{ func init() { RootCmd.AddCommand(userCmd) userCmd.Flags().SortFlags = false + + userCmd.Flags().StringVarP(&userFieldsQuery, "field", "f", "", + "Select field to display. Valid values are [email,humanId,id,lastModification,lastModificationLamport,login,metadata,name]") } diff --git a/doc/man/git-bug-user.1 b/doc/man/git-bug-user.1 index 1a14868d..dc04cee8 100644 --- a/doc/man/git-bug-user.1 +++ b/doc/man/git-bug-user.1 @@ -20,6 +20,10 @@ Display or change the user identity. .SH OPTIONS .PP +\fB\-f\fP, \fB\-\-field\fP="" + Select field to display. Valid values are [email,humanId,id,lastModification,lastModificationLamport,login,metadata,name] + +.PP \fB\-h\fP, \fB\-\-help\fP[=false] help for user diff --git a/doc/md/git-bug_user.md b/doc/md/git-bug_user.md index fe81a2c0..f2c783af 100644 --- a/doc/md/git-bug_user.md +++ b/doc/md/git-bug_user.md @@ -13,7 +13,8 @@ git-bug user [<user-id>] [flags] ### Options ``` - -h, --help help for user + -f, --field string Select field to display. Valid values are [email,humanId,id,lastModification,lastModificationLamport,login,metadata,name] + -h, --help help for user ``` ### SEE ALSO diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index ec8c64ea..543136b5 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -879,6 +879,9 @@ _git-bug_user() flags_with_completion=() flags_completion=() + flags+=("--field=") + two_word_flags+=("-f") + local_nonpersistent_flags+=("--field=") must_have_one_flag=() must_have_one_noun=() |