on main help sign in
chore(events): add events for the CLI session series of commands (#2408)
a1fc44bChristian Rocha
internal/cmd/session.go+16
@@ -17,6 +17,7 @@ import (
17 "github.com/charmbracelet/colorprofile"
17 "github.com/charmbracelet/colorprofile"
18 "github.com/charmbracelet/crush/internal/config"
18 "github.com/charmbracelet/crush/internal/config"
19 "github.com/charmbracelet/crush/internal/db"
19 "github.com/charmbracelet/crush/internal/db"
20+ "github.com/charmbracelet/crush/internal/event"
20 "github.com/charmbracelet/crush/internal/message"
21 "github.com/charmbracelet/crush/internal/message"
21 "github.com/charmbracelet/crush/internal/session"
22 "github.com/charmbracelet/crush/internal/session"
22 "github.com/charmbracelet/crush/internal/ui/chat"
23 "github.com/charmbracelet/crush/internal/ui/chat"
@@ -126,6 +127,9 @@ func sessionSetup(cmd *cobra.Command) (context.Context, *sessionServices, func()
126}
127}
127
128
128func runSessionList(cmd *cobra.Command, _ []string) error {
129func runSessionList(cmd *cobra.Command, _ []string) error {
130+ event.SetNonInteractive(true)
131+ event.SessionListed(sessionListJSON)
132+
129 ctx, svc, cleanup, err := sessionSetup(cmd)
133 ctx, svc, cleanup, err := sessionSetup(cmd)
130 if err != nil {
134 if err != nil {
131 return err
135 return err
@@ -249,6 +253,9 @@ func resolveSessionID(ctx context.Context, svc session.Service, id string) (sess
249}
253}
250
254
251func runSessionShow(cmd *cobra.Command, args []string) error {
255func runSessionShow(cmd *cobra.Command, args []string) error {
256+ event.SetNonInteractive(true)
257+ event.SessionShown(sessionShowJSON)
258+
252 ctx, svc, cleanup, err := sessionSetup(cmd)
259 ctx, svc, cleanup, err := sessionSetup(cmd)
253 if err != nil {
260 if err != nil {
254 return err
261 return err
@@ -273,6 +280,9 @@ func runSessionShow(cmd *cobra.Command, args []string) error {
273}
280}
274
281
275func runSessionDelete(cmd *cobra.Command, args []string) error {
282func runSessionDelete(cmd *cobra.Command, args []string) error {
283+ event.SetNonInteractive(true)
284+ event.SessionDeletedCommand(sessionDeleteJSON)
285+
276 ctx, svc, cleanup, err := sessionSetup(cmd)
286 ctx, svc, cleanup, err := sessionSetup(cmd)
277 if err != nil {
287 if err != nil {
278 return err
288 return err
@@ -305,6 +315,9 @@ func runSessionDelete(cmd *cobra.Command, args []string) error {
305}
315}
306
316
307func runSessionRename(cmd *cobra.Command, args []string) error {
317func runSessionRename(cmd *cobra.Command, args []string) error {
318+ event.SetNonInteractive(true)
319+ event.SessionRenamed(sessionRenameJSON)
320+
308 ctx, svc, cleanup, err := sessionSetup(cmd)
321 ctx, svc, cleanup, err := sessionSetup(cmd)
309 if err != nil {
322 if err != nil {
310 return err
323 return err
@@ -338,6 +351,9 @@ func runSessionRename(cmd *cobra.Command, args []string) error {
338}
351}
339
352
340func runSessionLast(cmd *cobra.Command, _ []string) error {
353func runSessionLast(cmd *cobra.Command, _ []string) error {
354+ event.SetNonInteractive(true)
355+ event.SessionLastShown(sessionLastJSON)
356+
341 ctx, svc, cleanup, err := sessionSetup(cmd)
357 ctx, svc, cleanup, err := sessionSetup(cmd)
342 if err != nil {
358 if err != nil {
343 return err
359 return err
internal/event/all.go+20
@@ -61,3 +61,23 @@ func TokensUsed(props ...any) {
61func StatsViewed() {
61func StatsViewed() {
62 send("stats viewed")
62 send("stats viewed")
63}
63}
64+
65+func SessionListed(json bool) {
66+ send("session listed", "json", json)
67+}
68+
69+func SessionShown(json bool) {
70+ send("session shown", "json", json)
71+}
72+
73+func SessionLastShown(json bool) {
74+ send("session last shown", "json", json)
75+}
76+
77+func SessionDeletedCommand(json bool) {
78+ send("session deleted", "json", json)
79+}
80+
81+func SessionRenamed(json bool) {
82+ send("session renamed", "json", json)
83+}