aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2017-06-03 16:36:34 +0200
committerTeddy Wing2017-06-03 16:38:22 +0200
commit73d5fa6c6233331c54d9b7a74407f2d17294e233 (patch)
treed2351a737bb3fa4eaba6deb11bb1cfa6370bc482
parent703fb697dd64a5f79e319b3ef0e323d6eb1c30a0 (diff)
downloadtimetasker-73d5fa6c6233331c54d9b7a74407f2d17294e233.tar.bz2
main.go: Fail if an unrecognised project alias is passed
If the user specifies a project alias that doesn't exist in their config.toml file, we should fail early and message the user about it.
-rw-r--r--main.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/main.go b/main.go
index b9a91cf..625f075 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,9 @@ package main
import (
"io/ioutil"
+ "fmt"
"log"
+ "os"
"time"
"github.com/teddywing/timetasker/timetask"
@@ -46,9 +48,15 @@ func main() {
kingpin.Parse()
// Submit time entry
+ project, ok := config.Projects[*project_alias]
+ if !ok {
+ fmt.Printf("Project '%s' not found\n", *project_alias)
+ os.Exit(1)
+ }
+
time_entry := timetask.NewTimeEntry(
config.Profile,
- config.Projects[*project_alias],
+ project,
time.Now(),
*time_spent,
*description,