-
-
Notifications
You must be signed in to change notification settings - Fork 1k
add wsh tab commands (create, rename, focus) #3333
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
Open
doyled-it
wants to merge
3
commits into
wavetermdev:main
Choose a base branch
from
doyled-it:feat/wsh-tab-commands
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,135 @@ | ||
| // Copyright 2026, Command Line Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "strings" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "github.com/wavetermdev/waveterm/pkg/wshrpc" | ||
| "github.com/wavetermdev/waveterm/pkg/wshrpc/wshclient" | ||
| ) | ||
|
|
||
| var tabCmd = &cobra.Command{ | ||
| Use: "tab", | ||
| Short: "Manage tabs", | ||
| } | ||
|
|
||
| var tabCreateCmd = &cobra.Command{ | ||
| Use: "create [-w workspaceid] [-n name] [--no-activate]", | ||
| Short: "Create a new tab in a workspace", | ||
| Args: cobra.NoArgs, | ||
| RunE: tabCreateRun, | ||
| PreRunE: preRunSetupRpcClient, | ||
| DisableFlagsInUseLine: true, | ||
| } | ||
|
|
||
| var tabRenameCmd = &cobra.Command{ | ||
| Use: "rename [-t tabid] <name>", | ||
| Short: "Rename a tab", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: tabRenameRun, | ||
| PreRunE: preRunSetupRpcClient, | ||
| DisableFlagsInUseLine: true, | ||
| } | ||
|
|
||
| var tabFocusCmd = &cobra.Command{ | ||
| Use: "focus <tabid>", | ||
| Short: "Focus (activate) a tab", | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: tabFocusRun, | ||
| PreRunE: preRunSetupRpcClient, | ||
| DisableFlagsInUseLine: true, | ||
| } | ||
|
|
||
| var ( | ||
| tabCreateFlagWorkspaceId string | ||
| tabCreateFlagName string | ||
| tabCreateFlagNoActivate bool | ||
| tabCreateFlagMeta []string | ||
| tabRenameFlagTabId string | ||
| ) | ||
|
|
||
| func init() { | ||
| rootCmd.AddCommand(tabCmd) | ||
| tabCmd.AddCommand(tabCreateCmd) | ||
| tabCmd.AddCommand(tabRenameCmd) | ||
| tabCmd.AddCommand(tabFocusCmd) | ||
|
|
||
| tabCreateCmd.Flags().StringVarP(&tabCreateFlagWorkspaceId, "workspace", "w", "", "workspace id (defaults to the caller's workspace)") | ||
| tabCreateCmd.Flags().StringVarP(&tabCreateFlagName, "name", "n", "", "tab name (defaults to next auto-generated name)") | ||
| tabCreateCmd.Flags().BoolVar(&tabCreateFlagNoActivate, "no-activate", false, "do not switch focus to the newly created tab") | ||
| tabCreateCmd.Flags().StringArrayVar(&tabCreateFlagMeta, "meta", nil, "metadata key=value pairs (repeatable)") | ||
|
|
||
| tabRenameCmd.Flags().StringVarP(&tabRenameFlagTabId, "tab", "t", "", "tab id to rename (defaults to WAVETERM_TABID)") | ||
| } | ||
|
|
||
| func tabCreateRun(cmd *cobra.Command, args []string) (rtnErr error) { | ||
| defer func() { | ||
| sendActivity("tab:create", rtnErr == nil) | ||
| }() | ||
|
|
||
| var metaMap map[string]string | ||
| if len(tabCreateFlagMeta) > 0 { | ||
| metaMap = make(map[string]string, len(tabCreateFlagMeta)) | ||
| for _, kv := range tabCreateFlagMeta { | ||
| idx := strings.IndexByte(kv, '=') | ||
| if idx <= 0 { | ||
| return fmt.Errorf("--meta value %q must be in key=value format with a non-empty key", kv) | ||
| } | ||
| metaMap[kv[:idx]] = kv[idx+1:] | ||
| } | ||
| } | ||
| data := wshrpc.CommandCreateTabData{ | ||
| WorkspaceId: tabCreateFlagWorkspaceId, | ||
| TabName: tabCreateFlagName, | ||
| ActivateTab: !tabCreateFlagNoActivate, | ||
| Meta: metaMap, | ||
| } | ||
| tabId, err := wshclient.CreateTabCommand(RpcClient, data, &wshrpc.RpcOpts{Timeout: 5000}) | ||
| if err != nil { | ||
| return fmt.Errorf("creating tab: %w", err) | ||
| } | ||
| WriteStdout("%s", tabId) | ||
| if getIsTty() { | ||
| WriteStdout("\n") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func tabRenameRun(cmd *cobra.Command, args []string) (rtnErr error) { | ||
| defer func() { | ||
| sendActivity("tab:rename", rtnErr == nil) | ||
| }() | ||
|
|
||
| tabId := tabRenameFlagTabId | ||
| if tabId == "" { | ||
| tabId = os.Getenv("WAVETERM_TABID") | ||
| } | ||
| if tabId == "" { | ||
| return fmt.Errorf("tab id required (pass --tab or set WAVETERM_TABID)") | ||
| } | ||
| name := args[0] | ||
| err := wshclient.UpdateTabNameCommand(RpcClient, tabId, name, &wshrpc.RpcOpts{Timeout: 2000}) | ||
| if err != nil { | ||
| return fmt.Errorf("renaming tab: %w", err) | ||
| } | ||
| WriteStdout("tab renamed\n") | ||
| return nil | ||
| } | ||
|
|
||
| func tabFocusRun(cmd *cobra.Command, args []string) (rtnErr error) { | ||
| defer func() { | ||
| sendActivity("tab:focus", rtnErr == nil) | ||
| }() | ||
|
|
||
| tabId := args[0] | ||
| err := wshclient.FocusTabCommand(RpcClient, tabId, &wshrpc.RpcOpts{Timeout: 2000}) | ||
| if err != nil { | ||
| return fmt.Errorf("focusing tab: %w", err) | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,98 @@ | ||
| // Copyright 2026, Command Line Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package wshrpc | ||
|
|
||
| import ( | ||
| "reflect" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestCreateTabCommandRegistered(t *testing.T) { | ||
| decl := GenerateWshCommandDeclMap()["createtab"] | ||
| if decl == nil { | ||
| t.Fatalf("expected createtab command declaration") | ||
| } | ||
| if decl.MethodName != "CreateTabCommand" { | ||
| t.Fatalf("expected CreateTabCommand method name, got %q", decl.MethodName) | ||
| } | ||
| dataTypes := decl.GetCommandDataTypes() | ||
| if len(dataTypes) != 1 { | ||
| t.Fatalf("expected 1 command arg, got %d", len(dataTypes)) | ||
| } | ||
| if dataTypes[0] != reflect.TypeOf(CommandCreateTabData{}) { | ||
| t.Fatalf("expected CommandCreateTabData arg, got %v", dataTypes[0]) | ||
| } | ||
| if decl.DefaultResponseDataType == nil || decl.DefaultResponseDataType.Kind() != reflect.String { | ||
| t.Fatalf("expected createtab to return a string, got %v", decl.DefaultResponseDataType) | ||
| } | ||
| } | ||
|
|
||
| func TestFocusTabCommandRegistered(t *testing.T) { | ||
| decl := GenerateWshCommandDeclMap()["focustab"] | ||
| if decl == nil { | ||
| t.Fatalf("expected focustab command declaration") | ||
| } | ||
| if decl.MethodName != "FocusTabCommand" { | ||
| t.Fatalf("expected FocusTabCommand method name, got %q", decl.MethodName) | ||
| } | ||
| dataTypes := decl.GetCommandDataTypes() | ||
| if len(dataTypes) != 1 { | ||
| t.Fatalf("expected 1 command arg, got %d", len(dataTypes)) | ||
| } | ||
| if dataTypes[0].Kind() != reflect.String { | ||
| t.Fatalf("expected focustab arg to be string, got %v", dataTypes[0]) | ||
| } | ||
| } | ||
|
|
||
| func TestUpdateTabNameCommandRegistered(t *testing.T) { | ||
| decl := GenerateWshCommandDeclMap()["updatetabname"] | ||
| if decl == nil { | ||
| t.Fatalf("expected updatetabname command declaration") | ||
| } | ||
| dataTypes := decl.GetCommandDataTypes() | ||
| if len(dataTypes) != 2 { | ||
| t.Fatalf("expected 2 command args, got %d", len(dataTypes)) | ||
| } | ||
| for i, dt := range dataTypes { | ||
| if dt.Kind() != reflect.String { | ||
| t.Fatalf("expected updatetabname arg %d to be string, got %v", i, dt) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestCommandCreateTabDataJSONTags(t *testing.T) { | ||
| rtype := reflect.TypeOf(CommandCreateTabData{}) | ||
| expected := map[string]string{ | ||
| "WorkspaceId": "workspaceid,omitempty", | ||
| "TabName": "tabname,omitempty", | ||
| "ActivateTab": "activatetab,omitempty", | ||
| "Meta": "meta,omitempty", | ||
| } | ||
| for fieldName, want := range expected { | ||
| field, ok := rtype.FieldByName(fieldName) | ||
| if !ok { | ||
| t.Fatalf("field %s not found on CommandCreateTabData", fieldName) | ||
| } | ||
| got := field.Tag.Get("json") | ||
| if got != want { | ||
| t.Fatalf("field %s json tag = %q, want %q", fieldName, got, want) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestCommandCreateTabDataMetaField(t *testing.T) { | ||
| rtype := reflect.TypeOf(CommandCreateTabData{}) | ||
| field, ok := rtype.FieldByName("Meta") | ||
| if !ok { | ||
| t.Fatalf("Meta field not found on CommandCreateTabData") | ||
| } | ||
| expected := reflect.TypeOf(map[string]string{}) | ||
| if field.Type != expected { | ||
| t.Fatalf("Meta field type = %v, want %v", field.Type, expected) | ||
| } | ||
| got := field.Tag.Get("json") | ||
| if got != "meta,omitempty" { | ||
| t.Fatalf("Meta json tag = %q, want %q", got, "meta,omitempty") | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.