MCPcopy Create free account
hub / github.com/cli/cli / ExportData

Method ExportData

pkg/cmd/discussion/client/types.go:34–119  ·  view source on GitHub ↗

ExportData returns a map of the requested fields for JSON output. Because domain types carry no JSON struct tags, each field is mapped explicitly rather than using reflection.

(fields []string)

Source from the content-addressed store, hash-verified

32// Because domain types carry no JSON struct tags, each field is mapped
33// explicitly rather than using reflection.
34func (d Discussion) ExportData(fields []string) map[string]interface{} {
35 data := map[string]interface{}{}
36 for _, f := range fields {
37 switch f {
38 case "id":
39 data[f] = d.ID
40 case "number":
41 data[f] = d.Number
42 case "title":
43 data[f] = d.Title
44 case "body":
45 data[f] = d.Body
46 case "url":
47 data[f] = d.URL
48 case "closed":
49 data[f] = d.Closed
50 case "state":
51 if d.Closed {
52 data[f] = "CLOSED"
53 } else {
54 data[f] = "OPEN"
55 }
56 case "stateReason":
57 data[f] = d.StateReason
58 case "author":
59 data[f] = d.Author.Export()
60 case "category":
61 data[f] = d.Category.Export()
62 case "labels":
63 labels := make([]interface{}, len(d.Labels))
64 for i, l := range d.Labels {
65 labels[i] = l.Export()
66 }
67 data[f] = labels
68 case "answered":
69 data[f] = d.Answered
70 case "answerChosenAt":
71 if d.AnswerChosenAt.IsZero() {
72 data[f] = nil
73 } else {
74 data[f] = d.AnswerChosenAt
75 }
76 case "answerChosenBy":
77 if d.AnswerChosenBy == nil {
78 data[f] = nil
79 } else {
80 data[f] = d.AnswerChosenBy.Export()
81 }
82 case "comments":
83 comments := make([]interface{}, len(d.Comments.Comments))
84 for i, c := range d.Comments.Comments {
85 comments[i] = c.Export()
86 }
87 m := map[string]interface{}{
88 "totalCount": d.Comments.TotalCount,
89 "nodes": comments,
90 }
91 if d.Comments.Cursor != "" {

Callers

nothing calls this directly

Calls 1

ExportMethod · 0.45

Tested by

no test coverage detected