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

Function wavepathRun

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

Source from the content-addressed store, hash-verified

29}
30
31func wavepathRun(cmd *cobra.Command, args []string) (rtnErr error) {
32 defer func() {
33 sendActivity("wavepath", rtnErr == nil)
34 }()
35
36 if len(args) == 0 {
37 OutputHelpMessage(cmd)
38 return fmt.Errorf("no arguments. wsh wavepath requires a type argument (config, data, or log)")
39 }
40 if len(args) > 1 {
41 OutputHelpMessage(cmd)
42 return fmt.Errorf("too many arguments. wsh wavepath requires exactly one argument")
43 }
44
45 pathType := args[0]
46 if pathType != "config" && pathType != "data" && pathType != "log" {
47 OutputHelpMessage(cmd)
48 return fmt.Errorf("invalid path type %q. must be one of: config, data, log", pathType)
49 }
50
51 tail, _ := cmd.Flags().GetBool("tail")
52 if tail && pathType != "log" {
53 return fmt.Errorf("--tail can only be used with the log path type")
54 }
55
56 open, _ := cmd.Flags().GetBool("open")
57 openExternal, _ := cmd.Flags().GetBool("open-external")
58
59 tabId := getTabIdFromEnv()
60 if tabId == "" {
61 return fmt.Errorf("no WAVETERM_TABID env var set")
62 }
63
64 path, err := wshclient.PathCommand(RpcClient, wshrpc.PathCommandData{
65 PathType: pathType,
66 Open: open,
67 OpenExternal: openExternal,
68 TabId: tabId,
69 }, nil)
70 if err != nil {
71 return fmt.Errorf("getting path: %w", err)
72 }
73
74 if tail && pathType == "log" {
75 err = tailLogFile(path)
76 if err != nil {
77 return fmt.Errorf("tailing log file: %w", err)
78 }
79 return nil
80 }
81
82 WriteStdout("%s\n", path)
83 return nil
84}
85
86func tailLogFile(path string) error {
87 file, err := os.Open(path)

Callers

nothing calls this directly

Calls 7

PathCommandFunction · 0.92
sendActivityFunction · 0.85
OutputHelpMessageFunction · 0.85
getTabIdFromEnvFunction · 0.85
tailLogFileFunction · 0.85
WriteStdoutFunction · 0.85
GetBoolMethod · 0.80

Tested by

no test coverage detected