Skip to content

Commit f05f475

Browse files
authored
Merge pull request #111 from gat786/feat/set-title
feat: allowing user to set title along with the start command
2 parents 25846cf + 717379f commit f05f475

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

api/plays.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,16 @@ func (c *Client) ListPlays(ctx context.Context, listPlaysQueryParams ListPlaysQu
364364
return plays, c.GetInto(ctx, "/plays", query, nil, &plays)
365365
}
366366

367+
func (c *Client) SetPlayTitle(ctx context.Context, id string, title string) (*Play, error) {
368+
body, err := toJSONBody(map[string]any{"action": "set_title", "title": title})
369+
if err != nil {
370+
return nil, err
371+
}
372+
373+
var p Play
374+
return &p, c.PostInto(ctx, "/plays/"+id+"/actions", nil, nil, body, &p)
375+
}
376+
367377
func (c *Client) StopPlay(ctx context.Context, id string) (*Play, error) {
368378
body, err := toJSONBody(map[string]any{"action": "stop"})
369379
if err != nil {

cmd/playground/start.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type startOptions struct {
2626
playground string
2727
machine string
2828
user string
29+
title string
2930

3031
file string
3132
open bool
@@ -110,6 +111,12 @@ func newStartCommand(cli labcli.CLI) *cobra.Command {
110111
"",
111112
`SSH user (default: the machine's default login user)`,
112113
)
114+
flags.StringVar(
115+
&opts.title,
116+
"title",
117+
"",
118+
`Title string which once set can be used to restart, stop and ssh into`,
119+
)
113120
flags.BoolVarP(
114121
&opts.open,
115122
"open",
@@ -252,6 +259,17 @@ func runStartPlayground(ctx context.Context, cli labcli.CLI, opts *startOptions)
252259

253260
cli.PrintAux("New %s playground started with ID %s\n", opts.playground, play.ID)
254261

262+
// set a title, this should be a non-failure causing request by default
263+
if opts.title != "" {
264+
var playResponse *api.Play
265+
playResponse, err = cli.Client().SetPlayTitle(ctx, play.ID, opts.title)
266+
if err != nil {
267+
cli.PrintAux(fmt.Sprintf("Unable to set title: %s, exception: %s\n", opts.title, err.Error()))
268+
} else {
269+
cli.PrintAux(fmt.Sprintf("Title set: %s\n", playResponse.Title))
270+
}
271+
}
272+
255273
if opts.open {
256274
browser.OpenWithFallbackMessage(cli, play.PageURL)
257275
}

0 commit comments

Comments
 (0)