system_setup_tool/cmd/history_cmd.go

29 lines
622 B
Go

package cmd
import (
"fmt"
"log/slog"
"os"
"path/filepath"
"github.com/spf13/cobra"
)
var historyCmd = &cobra.Command{
Use: "history",
Short: "show command history",
Long: "Shows history of the last 2000 commands",
Run: func(cmd *cobra.Command, args []string) {
dirname, err := os.UserConfigDir()
if err != nil {
slog.Error(fmt.Sprintf("getting user config dir: %v\n", err))
}
historyFile := filepath.Join(dirname, "sst", "sst_history")
content, err := os.ReadFile(historyFile)
if err != nil {
fmt.Println("error reading history: ", err)
return
}
fmt.Println(string(content))
},
}