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

Function viewRun

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

Source from the content-addressed store, hash-verified

41}
42
43func viewRun(cmd *cobra.Command, args []string) (rtnErr error) {
44 cmdName := cmd.Name()
45 defer func() {
46 sendActivity(cmdName, rtnErr == nil)
47 }()
48 if len(args) == 0 {
49 OutputHelpMessage(cmd)
50 return fmt.Errorf("no arguments. wsh %s requires a file or URL as an argument argument", cmdName)
51 }
52 if len(args) > 1 {
53 OutputHelpMessage(cmd)
54 return fmt.Errorf("too many arguments. wsh %s requires exactly one argument", cmdName)
55 }
56 tabId := getTabIdFromEnv()
57 if tabId == "" {
58 return fmt.Errorf("no WAVETERM_TABID env var set")
59 }
60 fileArg := args[0]
61 conn := RpcContext.Conn
62 var wshCmd *wshrpc.CommandCreateBlockData
63 if strings.HasPrefix(fileArg, "http://") || strings.HasPrefix(fileArg, "https://") {
64 wshCmd = &wshrpc.CommandCreateBlockData{
65 TabId: tabId,
66 BlockDef: &waveobj.BlockDef{
67 Meta: map[string]any{
68 waveobj.MetaKey_View: "web",
69 waveobj.MetaKey_Url: fileArg,
70 },
71 },
72 Magnified: viewMagnified,
73 Focused: true,
74 }
75 } else {
76 absFile, err := filepath.Abs(fileArg)
77 if err != nil {
78 return fmt.Errorf("getting absolute path: %w", err)
79 }
80 absParent, err := filepath.Abs(filepath.Dir(fileArg))
81 if err != nil {
82 return fmt.Errorf("getting absolute path of parent dir: %w", err)
83 }
84 _, err = os.Stat(absParent)
85 if err == fs.ErrNotExist {
86 return fmt.Errorf("parent directory does not exist: %q", absParent)
87 }
88 if err != nil {
89 return fmt.Errorf("getting file info: %w", err)
90 }
91 wshCmd = &wshrpc.CommandCreateBlockData{
92 TabId: tabId,
93 BlockDef: &waveobj.BlockDef{
94 Meta: map[string]interface{}{
95 waveobj.MetaKey_View: "preview",
96 waveobj.MetaKey_File: absFile,
97 },
98 },
99 Magnified: viewMagnified,
100 Focused: true,

Callers

nothing calls this directly

Calls 6

CreateBlockCommandFunction · 0.92
sendActivityFunction · 0.85
OutputHelpMessageFunction · 0.85
getTabIdFromEnvFunction · 0.85
StatMethod · 0.80
NameMethod · 0.45

Tested by

no test coverage detected