Skip to content

Commit 4ca775c

Browse files
authored
feat: add a wsh launch command (#1947)
This creates a new command `wsh launch` that will launch a widget that has been defined in the widgets.json file.
1 parent d36bd38 commit 4ca775c

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

cmd/wsh/cmd/wshcmd-launch.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2025, Command Line Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/spf13/cobra"
10+
"github.com/wavetermdev/waveterm/pkg/wshrpc"
11+
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
12+
)
13+
14+
var magnifyBlock bool
15+
16+
var launchCmd = &cobra.Command{
17+
Use: "launch",
18+
Short: "launch a widget by its ID",
19+
Args: cobra.ExactArgs(1),
20+
RunE: launchRun,
21+
PreRunE: preRunSetupRpcClient,
22+
}
23+
24+
func init() {
25+
launchCmd.Flags().BoolVarP(&magnifyBlock, "magnify", "m", false, "start the widget in magnified mode")
26+
rootCmd.AddCommand(launchCmd)
27+
}
28+
29+
func launchRun(cmd *cobra.Command, args []string) (rtnErr error) {
30+
defer func() {
31+
sendActivity("launch", rtnErr == nil)
32+
}()
33+
34+
widgetId := args[0]
35+
36+
// Get the full configuration
37+
config, err := wshclient.GetFullConfigCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000})
38+
if err != nil {
39+
return fmt.Errorf("getting configuration: %w", err)
40+
}
41+
42+
// Look for widget in both widgets and defaultwidgets
43+
widget, ok := config.Widgets[widgetId]
44+
if !ok {
45+
widget, ok = config.DefaultWidgets[widgetId]
46+
if !ok {
47+
return fmt.Errorf("widget %q not found in configuration", widgetId)
48+
}
49+
}
50+
51+
// Create block data from widget config
52+
createBlockData := wshrpc.CommandCreateBlockData{
53+
BlockDef: &widget.BlockDef,
54+
Magnified: magnifyBlock || widget.Magnified,
55+
}
56+
57+
// Create the block
58+
oref, err := wshclient.CreateBlockCommand(RpcClient, createBlockData, nil)
59+
if err != nil {
60+
return fmt.Errorf("creating widget block: %w", err)
61+
}
62+
63+
WriteStdout("launched widget %q: %s\n", widgetId, oref)
64+
return nil
65+
}

docs/docs/wsh-reference.mdx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,38 @@ wsh file ls wavefile://client/ | grep ".json$"
668668
669669
---
670670
671+
## launch
672+
673+
The `wsh launch` command allows you to open pre-configured widgets directly from your terminal.
674+
675+
```sh
676+
wsh launch [flags] widget-id
677+
```
678+
679+
The command will search for the specified widget ID in both user-defined widgets and default widgets, then create a new block using the widget's configuration.
680+
681+
Flags:
682+
683+
- `-m, --magnify` - open the widget in magnified mode, overriding the widget's default magnification setting
684+
685+
Examples:
686+
687+
```sh
688+
# Launch a widget with its default settings
689+
wsh launch my-custom-widget
690+
691+
# Launch a widget in magnified mode
692+
wsh launch -m system-monitor
693+
```
694+
695+
The widget's configuration determines the initial block settings, including the view type, metadata, and default magnification state. The `-m` flag can be used to override the widget's default magnification setting.
696+
697+
:::tip
698+
Widget configurations can be customized in your `widgets.json` configuration file, which you can edit using `wsh editconfig widgets.json`
699+
:::
700+
701+
---
702+
671703
## getvar/setvar
672704
673705
Wave Terminal provides commands for managing persistent variables at different scopes (block, tab, workspace, or client-wide).

0 commit comments

Comments
 (0)