Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a wsh launch command #1947

Merged
merged 1 commit into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions cmd/wsh/cmd/wshcmd-launch.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2025, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

package cmd

import (
"fmt"

"github.com/spf13/cobra"
"github.com/wavetermdev/waveterm/pkg/wshrpc"
"github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient"
)

var magnifyBlock bool

var launchCmd = &cobra.Command{
Use: "launch",
Short: "launch a widget by its ID",
Args: cobra.ExactArgs(1),
RunE: launchRun,
PreRunE: preRunSetupRpcClient,
}

func init() {
launchCmd.Flags().BoolVarP(&magnifyBlock, "magnify", "m", false, "start the widget in magnified mode")
rootCmd.AddCommand(launchCmd)
}

func launchRun(cmd *cobra.Command, args []string) (rtnErr error) {
defer func() {
sendActivity("launch", rtnErr == nil)
}()

widgetId := args[0]

// Get the full configuration
config, err := wshclient.GetFullConfigCommand(RpcClient, &wshrpc.RpcOpts{Timeout: 2000})
if err != nil {
return fmt.Errorf("getting configuration: %w", err)
}

// Look for widget in both widgets and defaultwidgets
widget, ok := config.Widgets[widgetId]
if !ok {
widget, ok = config.DefaultWidgets[widgetId]
if !ok {
return fmt.Errorf("widget %q not found in configuration", widgetId)
}
}

// Create block data from widget config
createBlockData := wshrpc.CommandCreateBlockData{
BlockDef: &widget.BlockDef,
Magnified: magnifyBlock || widget.Magnified,
}

// Create the block
oref, err := wshclient.CreateBlockCommand(RpcClient, createBlockData, nil)
if err != nil {
return fmt.Errorf("creating widget block: %w", err)
}

WriteStdout("launched widget %q: %s\n", widgetId, oref)
return nil
}
32 changes: 32 additions & 0 deletions docs/docs/wsh-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,38 @@ wsh file ls wavefile://client/ | grep ".json$"

---

## launch

The `wsh launch` command allows you to open pre-configured widgets directly from your terminal.

```sh
wsh launch [flags] widget-id
```

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.

Flags:

- `-m, --magnify` - open the widget in magnified mode, overriding the widget's default magnification setting

Examples:

```sh
# Launch a widget with its default settings
wsh launch my-custom-widget

# Launch a widget in magnified mode
wsh launch -m system-monitor
```

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.

:::tip
Widget configurations can be customized in your `widgets.json` configuration file, which you can edit using `wsh editconfig widgets.json`
:::

---

## getvar/setvar

Wave Terminal provides commands for managing persistent variables at different scopes (block, tab, workspace, or client-wide).
Expand Down
Loading