fix(cmd): add error handling for user input in edit and lint commands
- Handle errors from fmt.Scanln in cmd/edit.go and cmd/lint.go to prevent crashes on input failures, providing user feedback and preserving backups. - Update .gitea/workflows/release.yml to use 'ubuntu-gitea' runner for CI consistency.
This commit is contained in:
parent
ec5c43163b
commit
cdcbd245d7
@ -11,7 +11,7 @@ permissions:
|
|||||||
jobs:
|
jobs:
|
||||||
release:
|
release:
|
||||||
name: Create Release
|
name: Create Release
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-gitea
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|||||||
@ -71,7 +71,11 @@ var editCmd = &cobra.Command{
|
|||||||
|
|
||||||
fmt.Print("\n\nApply these changes? (y/n): ")
|
fmt.Print("\n\nApply these changes? (y/n): ")
|
||||||
var confirm string
|
var confirm string
|
||||||
fmt.Scanln(&confirm)
|
if _, err := fmt.Scanln(&confirm); err != nil {
|
||||||
|
color.Red("Failed to read input: %v", err)
|
||||||
|
color.Yellow("Changes discarded. Backup saved as %s", backupPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
if confirm != "y" && confirm != "Y" {
|
if confirm != "y" && confirm != "Y" {
|
||||||
color.Yellow("Changes discarded. Backup saved as %s", backupPath)
|
color.Yellow("Changes discarded. Backup saved as %s", backupPath)
|
||||||
return
|
return
|
||||||
|
|||||||
@ -165,7 +165,11 @@ func runLint(cmd *cobra.Command, args []string) {
|
|||||||
// Ask for confirmation
|
// Ask for confirmation
|
||||||
color.Yellow("Apply these fixes? (y/N): ")
|
color.Yellow("Apply these fixes? (y/N): ")
|
||||||
var response string
|
var response string
|
||||||
fmt.Scanln(&response)
|
if _, err := fmt.Scanln(&response); err != nil {
|
||||||
|
logger.Info("failed to read user input", "file", absPath, "error", err)
|
||||||
|
color.Yellow("❌ Cancelled. Backup preserved at: %s", backupPath)
|
||||||
|
return
|
||||||
|
}
|
||||||
response = strings.ToLower(strings.TrimSpace(response))
|
response = strings.ToLower(strings.TrimSpace(response))
|
||||||
|
|
||||||
if response != "y" && response != "yes" {
|
if response != "y" && response != "yes" {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user