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