-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
d36bd38
commit 4ca775c
Showing
2 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters