景好勇win11 4 months ago
parent
commit
9689f097d2
1 changed files with 52 additions and 0 deletions
  1. 52 0
      script/bin/mylog.ps1

+ 52 - 0
script/bin/mylog.ps1

@@ -0,0 +1,52 @@
+# 交互式命令行模式
+function Interactive-Mode {
+    while ($true) {
+        Write-Host "`r请输入命令 (c: 清空日志, p: 打印日志, l: 查看日志, t: 实时查看日志, m: 复制错误信息, q: 退出): " -NoNewline
+        $cmd = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown").Character
+        Write-Host # 换行
+
+        switch ($cmd) {
+            'c' {
+                Clear-Content -Path "storage\logs\laravel.log"
+                Write-Host "日志已清空。"
+            }
+            'p' {
+                $errors = Get-Content "storage\logs\laravel.log" | Select-String "ERROR"
+                if ($errors) {
+                    Write-Host
+                    Get-Content "storage\logs\laravel.log" | Select-String "ERROR"
+                    Write-Host
+                } else {
+                    Write-Host "未发现错误信息。"
+                }
+            }
+            'l' {
+                Get-Content "storage\logs\laravel.log" | Out-Host -Paging
+            }
+            't' {
+                Get-Content "storage\logs\laravel.log" -Wait -Tail 1000
+            }
+            'q' {
+                Write-Host "退出程序"
+                exit
+            }
+            'm' {
+                $errors = Get-Content "storage\logs\laravel.log" | Select-String "ERROR"
+                if ($errors) {
+                    $firstError = Get-Content "storage\logs\laravel.log" | Select-String "ERROR" | Select-Object -First 1
+                    $clipboardText = "$firstError`n`n上面是错误日志,请帮我修复这个bug,并始终用中文语言回答。"
+                    Set-Clipboard -Value $clipboardText
+                    Write-Host "已复制错误信息到剪贴板,你可以问AI助手,Ta会给你解决错误。"
+                } else {
+                    Write-Host "未发现错误信息。"
+                }
+            }
+            default {
+                Write-Host "无效命令。使用 'c' 清空日志, 'p' 打印日志, 'l' 查看日志, 't' 实时查看日志, 'm' 复制错误信息, 'q' 退出。"
+            }
+        }
+    }
+}
+
+# 运行交互式模式
+Interactive-Mode