aboutsummaryrefslogtreecommitdiffstats
path: root/commands/user_ls.go
diff options
context:
space:
mode:
authorvince <vincetiu8@gmail.com>2020-06-23 17:51:42 +0800
committervince <vincetiu8@gmail.com>2020-06-23 17:51:42 +0800
commitfc3f6540b8fc941be76d01da49fcd43890ee7376 (patch)
tree4b8d1671dd490db91fac1fc9dde04f356c69d609 /commands/user_ls.go
parentcd8352edde7f4a26cb6b4dd922b05aa0bb23a70b (diff)
downloadgit-bug-fc3f6540b8fc941be76d01da49fcd43890ee7376.tar.gz
Add org-mode formatting option
This adds an option to the formatting flag on the ls, show and user ls commands that allows the user to specify the format of the output in org-mode. This will be useful for emacs users to read it in the editor.
Diffstat (limited to 'commands/user_ls.go')
-rw-r--r--commands/user_ls.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/commands/user_ls.go b/commands/user_ls.go
index 9d0eebf1..353bc101 100644
--- a/commands/user_ls.go
+++ b/commands/user_ls.go
@@ -22,6 +22,8 @@ func runUserLs(_ *cobra.Command, _ []string) error {
interrupt.RegisterCleaner(backend.Close)
switch userLsOutputFormat {
+ case "org-mode":
+ return userLsOrgmodeFormatter(backend)
case "json":
return userLsJsonFormatter(backend)
case "plain":
@@ -93,6 +95,22 @@ func userLsJsonFormatter(backend *cache.RepoCache) error {
return nil
}
+func userLsOrgmodeFormatter(backend *cache.RepoCache) error {
+ for _, id := range backend.AllIdentityIds() {
+ i, err := backend.ResolveIdentityExcerpt(id)
+ if err != nil {
+ return err
+ }
+
+ fmt.Printf("* %s %s\n",
+ i.Id.Human(),
+ i.DisplayName(),
+ )
+ }
+
+ return nil
+}
+
var userLsCmd = &cobra.Command{
Use: "ls",
Short: "List identities.",
@@ -104,5 +122,5 @@ func init() {
userCmd.AddCommand(userLsCmd)
userLsCmd.Flags().SortFlags = false
userLsCmd.Flags().StringVarP(&userLsOutputFormat, "format", "f", "default",
- "Select the output formatting style. Valid values are [default,plain,json]")
+ "Select the output formatting style. Valid values are [default,plain,json,org-mode]")
}