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:
|
||||
release:
|
||||
name: Create Release
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ubuntu-gitea
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
@ -71,7 +71,11 @@ var editCmd = &cobra.Command{
|
||||
|
||||
fmt.Print("\n\nApply these changes? (y/n): ")
|
||||
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" {
|
||||
color.Yellow("Changes discarded. Backup saved as %s", backupPath)
|
||||
return
|
||||
|
||||
@ -165,7 +165,11 @@ func runLint(cmd *cobra.Command, args []string) {
|
||||
// Ask for confirmation
|
||||
color.Yellow("Apply these fixes? (y/N): ")
|
||||
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))
|
||||
|
||||
if response != "y" && response != "yes" {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user