Use cli error handling

master
Carlo Strub 7 years ago
parent d47bc76dc4
commit 754eac57b1

@ -3,7 +3,6 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"log"
"os" "os"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -18,7 +17,7 @@ func main() {
// Get working directory // Get working directory
wd, err := os.Getwd() wd, err := os.Getwd()
if err != nil { if err != nil {
log.Fatal(err) panic(err)
} }
var maildir, database *string var maildir, database *string
@ -27,11 +26,10 @@ func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "Sisyphus" app.Name = "Sisyphus"
app.Usage = "Intelligent Junk and Spam Mail Handler" app.Usage = "Intelligent Junk and Spam Mail Handler"
app.UsageText = `This application applies artificial intelligence to app.UsageText = `Sisyphus applies artificial intelligence to filter
filter Junk mail in an unobtrusive way. Both, classification and Junk mail in an unobtrusive way. Both, classification and learning
learning operate directly on the Maildir of a user in a fully operate directly on the Maildir of a user in a fully transparent mode,
transparent mode, without any need for configuration or active without any need for configuration or active operation.`
operation.`
app.HelpName = "Intelligent Junk and Spam Mail Handler" app.HelpName = "Intelligent Junk and Spam Mail Handler"
app.Version = "0.0.0" app.Version = "0.0.0"
app.Authors = []cli.Author{ app.Authors = []cli.Author{
@ -72,7 +70,7 @@ func main() {
// Load the Maildir // Load the Maildir
mails, err := Index(*maildir) mails, err := Index(*maildir)
if err != nil { if err != nil {
log.Fatalf("load Maildir content: %s", err) return cli.NewExitError(err, 66)
} }
fmt.Println(mails) fmt.Println(mails)
@ -80,7 +78,7 @@ func main() {
// Open the database // Open the database
db, err := openDB(*database) db, err := openDB(*database)
if err != nil { if err != nil {
log.Fatalf("open database: %s", err) return cli.NewExitError(err, 66)
} }
defer db.Close() defer db.Close()

Loading…
Cancel
Save