Rich Enhanced Shell History - Contextual shell history for zsh and bash
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
resh/cmd/control/cmd/debug.go

69 lines
1.7 KiB

package cmd
import (
"fmt"
"io/ioutil"
"os/user"
"path/filepath"
"github.com/curusarn/resh/cmd/control/status"
"github.com/spf13/cobra"
)
var debugCmd = &cobra.Command{
Use: "debug",
Short: "debug utils for resh",
Long: "Reloads resh rc files. Shows logs and output from last runs of resh",
}
var debugReloadCmd = &cobra.Command{
Use: "reload",
Short: "reload resh rc files",
Long: "Reload resh rc files",
Run: func(cmd *cobra.Command, args []string) {
exitCode = status.ReloadRcFiles
},
}
var debugInspectCmd = &cobra.Command{
Use: "inspect",
Short: "inspect session history",
Run: func(cmd *cobra.Command, args []string) {
exitCode = status.InspectSessionHistory
},
}
var debugOutputCmd = &cobra.Command{
Use: "output",
Short: "shows output from last runs of resh",
Long: "Shows output from last runs of resh",
Run: func(cmd *cobra.Command, args []string) {
files := []string{
"daemon_last_run_out.txt",
"collect_last_run_out.txt",
"postcollect_last_run_out.txt",
"session_init_last_run_out.txt",
"arrow_up_last_run_out.txt",
"arrow_down_last_run_out.txt",
}
usr, _ := user.Current()
dir := usr.HomeDir
reshdir := filepath.Join(dir, ".resh")
for _, fpath := range files {
fpath := filepath.Join(reshdir, fpath)
debugReadFile(fpath)
}
exitCode = status.Success
},
}
func debugReadFile(path string) {
fmt.Println("============================================================")
fmt.Println(" filepath:", path)
fmt.Println("============================================================")
dat, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println("ERROR while reading file:", err)
}
fmt.Println(string(dat))
}