Remove os.Exit() from library code (gt-fm75)
Refactor to return errors instead of calling os.Exit() directly: - Add SilentExitError type for commands that signal status via exit code - Update mail.go runMailPeek() and runMailCheck() to return errors - Change Execute() to return int exit code instead of calling os.Exit() - Move os.Exit() call to main() where it belongs This improves testability, enables graceful shutdown, and follows Go conventions for library code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -29,11 +28,18 @@ across distributed teams of AI agents working on shared codebases.`,
|
||||
},
|
||||
}
|
||||
|
||||
// Execute runs the root command
|
||||
func Execute() {
|
||||
// Execute runs the root command and returns an exit code.
|
||||
// The caller (main) should call os.Exit with this code.
|
||||
func Execute() int {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
// Check for silent exit (scripting commands that signal status via exit code)
|
||||
if code, ok := IsSilentExit(err); ok {
|
||||
return code
|
||||
}
|
||||
// Other errors already printed by cobra
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Command group IDs - used by subcommands to organize help output
|
||||
|
||||
Reference in New Issue
Block a user