tme

Toggl like Time Manager
git clone git://gtms.dev/tme
Log | Files | Refs

main.go (973B)


      1 package main
      2 
      3 import (
      4 	"fmt"
      5 	"os"
      6 )
      7 
      8 const (
      9 	activeFile = "active"
     10 )
     11 
     12 func main() {
     13 	rootPath := os.Getenv("TME_DIR")
     14 	if rootPath == "" {
     15 		fmt.Fprintln(os.Stderr, "TME_DIR environment variable is not set.")
     16 		os.Exit(1)
     17 	}
     18 
     19 	if _, err := os.Stat(rootPath); os.IsNotExist(err) {
     20 		fmt.Fprintf(os.Stderr, "%s does not exist\n", rootPath)
     21 		os.Exit(1)
     22 	}
     23 
     24 	args := os.Args[1:]
     25 	if len(args) == 0 {
     26 		os.Exit(0)
     27 	}
     28 
     29 	cmd := args[0]
     30 	args = args[1:] // shift
     31 
     32 	entryTime := NewTimeToday()
     33 	repository := NewFSRepository(rootPath)
     34 	command := Command{repository, args, entryTime}
     35 	if cmd == "add" {
     36 		command.Add()
     37 	} else if cmd == "start" {
     38 		command.Start()
     39 	} else if cmd == "stop" {
     40 		command.Stop()
     41 	} else if cmd == "ls" {
     42 		command.Ls()
     43 	} else if cmd == "lsr" {
     44 		command.Lsr()
     45 	} else if cmd == "rm" {
     46 		command.Remove()
     47 	} else if cmd == "mv" {
     48 		command.Move()
     49 	} else if cmd == "report" {
     50 		command.Report()
     51 	} else if cmd == "status" {
     52 		command.Status()
     53 	}
     54 }