1package boardcmd
2
3import (
4 "fmt"
5
6 "github.com/spf13/cobra"
7
8 "github.com/git-bug/git-bug/commands/cmdjson"
9 "github.com/git-bug/git-bug/commands/execenv"
10 "github.com/git-bug/git-bug/entities/board"
11)
12
13type boardShowOptions struct {
14 format string
15}
16
17func newBoardShowCommand() *cobra.Command {
18 env := execenv.NewEnv()
19 options := boardShowOptions{}
20
21 cmd := &cobra.Command{
22 Use: "show [BOARD_ID]",
23 Short: "Display a board",
24 PreRunE: execenv.LoadBackend(env),
25 RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
26 return runBoardShow(env, options, args)
27 }),
28 ValidArgsFunction: BoardCompletion(env),
29 }
30
31 flags := cmd.Flags()
32 flags.SortFlags = false
33
34 flags.StringVarP(&options.format, "format", "f", "default",
35 "Select the output formatting style. Valid values are [default,json,org-mode]")
36
37 return cmd
38}
39
40func runBoardShow(env *execenv.Env, opts boardShowOptions, args []string) error {
41 b, args, err := ResolveSelected(env.Backend, args)
42 if err != nil {
43 return err
44 }
45
46 snap := b.Snapshot()
47
48 switch opts.format {
49 case "json":
50 return showJsonFormatter(env, snap)
51 case "default":
52 return showDefaultFormatter(env, snap)
53 default:
54 return fmt.Errorf("unknown format %s", opts.format)
55 }
56}
57
58func showDefaultFormatter(env *execenv.Env, snapshot *board.Snapshot) error {
59 // // Header
60 // env.Out.Printf("%s [%s] %s\n\n",
61 // colors.Cyan(snapshot.Id().Human()),
62 // colors.Yellow(snapshot.Status),
63 // snapshot.Title,
64 // )
65 //
66 // env.Out.Printf("%s opened this issue %s\n",
67 // colors.Magenta(snapshot.Author.DisplayName()),
68 // snapshot.CreateTime.String(),
69 // )
70 //
71 // env.Out.Printf("This was last edited at %s\n\n",
72 // snapshot.EditTime().String(),
73 // )
74 //
75 // // Labels
76 // var labels = make([]string, len(snapshot.Labels))
77 // for i := range snapshot.Labels {
78 // labels[i] = string(snapshot.Labels[i])
79 // }
80 //
81 // env.Out.Printf("labels: %s\n",
82 // strings.Join(labels, ", "),
83 // )
84 //
85 // // Actors
86 // var actors = make([]string, len(snapshot.Actors))
87 // for i := range snapshot.Actors {
88 // actors[i] = snapshot.Actors[i].DisplayName()
89 // }
90 //
91 // env.Out.Printf("actors: %s\n",
92 // strings.Join(actors, ", "),
93 // )
94 //
95 // // Participants
96 // var participants = make([]string, len(snapshot.Participants))
97 // for i := range snapshot.Participants {
98 // participants[i] = snapshot.Participants[i].DisplayName()
99 // }
100 //
101 // env.Out.Printf("participants: %s\n\n",
102 // strings.Join(participants, ", "),
103 // )
104 //
105 // // Comments
106 // indent := " "
107 //
108 // for i, comment := range snapshot.Comments {
109 // var message string
110 // env.Out.Printf("%s%s #%d %s <%s>\n\n",
111 // indent,
112 // comment.CombinedId().Human(),
113 // i,
114 // comment.Author.DisplayName(),
115 // comment.Author.Email(),
116 // )
117 //
118 // if comment.Message == "" {
119 // message = colors.BlackBold(colors.WhiteBg("No description provided."))
120 // } else {
121 // message = comment.Message
122 // }
123 //
124 // env.Out.Printf("%s%s\n\n\n",
125 // indent,
126 // message,
127 // )
128 // }
129
130 return nil
131}
132
133func showJsonFormatter(env *execenv.Env, snap *board.Snapshot) error {
134 jsonBoard := cmdjson.NewBoardSnapshot(snap)
135 return env.Out.PrintJSON(jsonBoard)
136}