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

Function viewRun

pkg/cmd/event/subscription/view/view.go:64–123  ·  view source on GitHub ↗
(ctx context.Context, opts *ViewOptions)

Source from the content-addressed store, hash-verified

62}
63
64func viewRun(ctx context.Context, opts *ViewOptions) error {
65 cfg, err := opts.Config()
66 if err != nil {
67 return err
68 }
69 host, _ := cfg.Authentication().DefaultHost()
70
71 c, err := opts.EventClient(host)
72 if err != nil {
73 return err
74 }
75
76 opts.IO.StartProgressIndicator()
77 sub, err := c.GetSubscription(ctx, opts.ID)
78 opts.IO.StopProgressIndicator()
79 if err != nil {
80 if errors.Is(err, client.ErrSubscriptionNotFound) {
81 return shared.SubscriptionNotFoundError(opts.ID)
82 }
83 return fmt.Errorf("failed to get subscription: %w", err)
84 }
85
86 if opts.Exporter != nil {
87 return opts.Exporter.Write(opts.IO, sub)
88 }
89
90 out := opts.IO.Out
91 if !opts.IO.IsStdoutTTY() {
92 fmt.Fprintf(out, "id:\t%s\n", sub.ID)
93 fmt.Fprintf(out, "resource:\t%s\n", sub.ResourceURL)
94 fmt.Fprintf(out, "events:\t%s\n", strings.Join(sub.EventTypes, ","))
95 fmt.Fprintf(out, "created:\t%s\n", sub.CreatedAt.Format(time.RFC3339))
96 fmt.Fprintf(out, "expires:\t%s\n", sub.ExpiresAt.Format(time.RFC3339))
97 return nil
98 }
99
100 cs := opts.IO.ColorScheme()
101 now := opts.Now()
102 fmt.Fprintln(out, cs.Bold(sub.ID))
103 fmt.Fprintln(out, cs.Muted(fmt.Sprintf("Created %s • Expires %s",
104 text.FuzzyAgo(now, sub.CreatedAt), text.FuzzyIn(now, sub.ExpiresAt))))
105 fmt.Fprintln(out)
106 fmt.Fprintln(out, cs.Bold("Resource"))
107 fmt.Fprintln(out, sub.ResourceURL)
108 fmt.Fprintln(out)
109 fmt.Fprintln(out, cs.Bold("Events"))
110 width := 0
111 for _, name := range sub.EventTypes {
112 width = max(width, len(name))
113 }
114 for _, name := range sub.EventTypes {
115 desc := shared.EventTypeDescription(name)
116 if desc == "" {
117 fmt.Fprintf(out, "• %s\n", cs.Cyan(name))
118 continue
119 }
120 fmt.Fprintf(out, "• %s%s %s\n", cs.Cyan(name), strings.Repeat(" ", width-len(name)), cs.Muted(desc))
121 }

Callers 2

TestViewRunFunction · 0.70
NewCmdViewFunction · 0.70

Calls 15

FuzzyAgoFunction · 0.92
FuzzyInFunction · 0.92
EventTypeDescriptionFunction · 0.92
IsStdoutTTYMethod · 0.80
JoinMethod · 0.80
ColorSchemeMethod · 0.80
BoldMethod · 0.80
MutedMethod · 0.80
CyanMethod · 0.80
ConfigMethod · 0.65
DefaultHostMethod · 0.65

Tested by 1

TestViewRunFunction · 0.56