(cmd *cobra.Command, args []string)
| 31 | } |
| 32 | |
| 33 | func 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 |
nothing calls this directly
no test coverage detected