Refactored error output & exit
This commit is contained in:
parent
a0b33ddfd2
commit
fc2c29cf52
3 changed files with 22 additions and 15 deletions
18
z/finish.go
18
z/finish.go
|
@ -2,7 +2,6 @@ package z
|
|||
|
||||
import (
|
||||
"os"
|
||||
"log"
|
||||
"fmt"
|
||||
"time"
|
||||
"github.com/spf13/cobra"
|
||||
|
@ -17,22 +16,25 @@ var finishCmd = &cobra.Command{
|
|||
|
||||
runningEntryId, err := database.GetRunningEntryId(user)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if runningEntryId == "" {
|
||||
fmt.Printf("□ not running\n")
|
||||
os.Exit(-1)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
runningEntry, err := database.GetEntry(user, runningEntryId)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
tmpEntry, err := NewEntry(runningEntry.ID, begin, finish, project, task, user)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if begin != "" {
|
||||
|
@ -55,7 +57,8 @@ var finishCmd = &cobra.Command{
|
|||
|
||||
_, err = database.FinishEntry(user, runningEntry)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf(runningEntry.GetOutputForFinish())
|
||||
|
@ -73,6 +76,7 @@ func init() {
|
|||
var err error
|
||||
database, err = InitDatabase()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ var rootCmd = &cobra.Command{
|
|||
|
||||
func Execute() {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
15
z/track.go
15
z/track.go
|
@ -2,7 +2,6 @@ package z
|
|||
|
||||
import (
|
||||
"os"
|
||||
"log"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -16,24 +15,27 @@ var trackCmd = &cobra.Command{
|
|||
|
||||
runningEntryId, err := database.GetRunningEntryId(user)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if runningEntryId != "" {
|
||||
fmt.Printf("▷ a task is already running\n")
|
||||
os.Exit(-1)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
newEntry, err := NewEntry("", begin, finish, project, task, user)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
isRunning := newEntry.Finish.IsZero()
|
||||
|
||||
_, err = database.AddEntry(user, newEntry, isRunning)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf(newEntry.GetOutputForTrack(isRunning))
|
||||
|
@ -52,6 +54,7 @@ func init() {
|
|||
var err error
|
||||
database, err = InitDatabase()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
fmt.Printf("△ %+v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue