mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
fix: logging error distorts ui & clear stale cmds
Signed-off-by: cpendery <cpendery@vt.edu>
This commit is contained in:
@@ -47,3 +47,13 @@ func ReadResult() string {
|
||||
}
|
||||
return string(content)
|
||||
}
|
||||
|
||||
func ClearResult() {
|
||||
path, err := xdg.CacheFile(cacheFilePath)
|
||||
if err != nil {
|
||||
slog.Error("failed to load cache file", slog.String("error", err.Error()))
|
||||
}
|
||||
if err := os.Truncate(path, 0); err != nil {
|
||||
slog.Error("failed to clear cache file", slog.String("error", err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
+8
-1
@@ -1,6 +1,8 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
"log/slog"
|
||||
"os"
|
||||
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
@@ -20,6 +22,7 @@ more productive
|
||||
|
||||
complete documentation is available at https://github.com/cpendery/clac`,
|
||||
SilenceUsage: true,
|
||||
Args: cobra.ArbitraryArgs,
|
||||
RunE: rootExec,
|
||||
}
|
||||
outputCmd bool
|
||||
@@ -28,7 +31,7 @@ complete documentation is available at https://github.com/cpendery/clac`,
|
||||
|
||||
func init() {
|
||||
rootCmd.Flags().BoolVarP(&outputCmd, "output-cmd", "o", false, "outputs the last cmd from a clac execution")
|
||||
rootCmd.Flags().BoolVarP(&outputCmd, "logging", "l", false, "enable logging to the `clac.log` file")
|
||||
rootCmd.Flags().BoolVarP(&enableLogging, "logging", "l", false, "enable logging to the `clac.log` file")
|
||||
}
|
||||
|
||||
func rootExec(cmd *cobra.Command, args []string) error {
|
||||
@@ -37,12 +40,16 @@ func rootExec(cmd *cobra.Command, args []string) error {
|
||||
_, err := os.Stdout.WriteString(result)
|
||||
return err
|
||||
}
|
||||
autocomplete.ClearResult()
|
||||
|
||||
if enableLogging {
|
||||
f, err := tea.LogToFile("clac.log", "debug")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
} else {
|
||||
slog.SetDefault(slog.New(slog.NewTextHandler(io.Discard, nil)))
|
||||
}
|
||||
|
||||
startingInput := ""
|
||||
|
||||
Reference in New Issue
Block a user