MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / editorRun

Function editorRun

cmd/wsh/cmd/wshcmd-editor.go:33–91  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

31}
32
33func editorRun(cmd *cobra.Command, args []string) (rtnErr error) {
34 defer func() {
35 sendActivity("editor", rtnErr == nil)
36 }()
37 if len(args) == 0 {
38 OutputHelpMessage(cmd)
39 return fmt.Errorf("no arguments. wsh editor requires a file or URL as an argument argument")
40 }
41 if len(args) > 1 {
42 OutputHelpMessage(cmd)
43 return fmt.Errorf("too many arguments. wsh editor requires exactly one argument")
44 }
45 fileArg := args[0]
46 absFile, err := filepath.Abs(fileArg)
47 if err != nil {
48 return fmt.Errorf("getting absolute path: %w", err)
49 }
50 _, err = os.Stat(absFile)
51 if err == fs.ErrNotExist {
52 return fmt.Errorf("file does not exist: %q", absFile)
53 }
54 if err != nil {
55 return fmt.Errorf("getting file info: %w", err)
56 }
57
58 tabId := getTabIdFromEnv()
59 if tabId == "" {
60 return fmt.Errorf("no WAVETERM_TABID env var set")
61 }
62
63 wshCmd := wshrpc.CommandCreateBlockData{
64 TabId: tabId,
65 BlockDef: &waveobj.BlockDef{
66 Meta: map[string]any{
67 waveobj.MetaKey_View: "preview",
68 waveobj.MetaKey_File: absFile,
69 waveobj.MetaKey_Edit: true,
70 },
71 },
72 Magnified: editMagnified,
73 Focused: true,
74 }
75 if RpcContext.Conn != "" {
76 wshCmd.BlockDef.Meta[waveobj.MetaKey_Connection] = RpcContext.Conn
77 }
78 blockRef, err := wshclient.CreateBlockCommand(RpcClient, wshCmd, &wshrpc.RpcOpts{Timeout: 2000})
79 if err != nil {
80 return fmt.Errorf("running view command: %w", err)
81 }
82 doneCh := make(chan bool)
83 RpcClient.EventListener.On(wps.Event_BlockClose, func(event *wps.WaveEvent) {
84 if event.HasScope(blockRef.String()) {
85 close(doneCh)
86 }
87 })
88 wshclient.EventSubCommand(RpcClient, wps.SubscriptionRequest{Event: wps.Event_BlockClose, Scopes: []string{blockRef.String()}}, nil)
89 <-doneCh
90 return nil

Callers

nothing calls this directly

Calls 9

CreateBlockCommandFunction · 0.92
EventSubCommandFunction · 0.92
sendActivityFunction · 0.85
OutputHelpMessageFunction · 0.85
getTabIdFromEnvFunction · 0.85
StatMethod · 0.80
OnMethod · 0.80
HasScopeMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected