package main import ( "fmt" "flag" "path/filepath" _ "log" //"bufio" "os" //"strings" _ "os/exec" "github.com/fatih/color" ) //var svar string var starttime,stoptime string var projectid, edittaskid, editprojectid, editcustomerid int var deltask int var addcustomer bool var newproject, newtask, stoptask, allproj, allbills, runinter, test, newconfig bool var billcount int //var red, green, yellow, cyan color //var boldRed, boldGreen color func title(frame bool) { bR := color.New(color.FgRed, color.Bold).SprintFunc() bHiR := color.New(color.FgHiRed, color.Bold).SprintFunc() bHiY := color.New(color.FgHiYellow, color.Bold).SprintFunc() bHiG := color.New(color.FgHiGreen, color.Bold).SprintFunc() bHiC := color.New(color.FgHiCyan, color.Bold).SprintFunc() bHiB := color.New(color.FgHiBlue, color.Bold).SprintFunc() bHiM := color.New(color.FgHiMagenta, color.Bold).SprintFunc() bM := color.New(color.FgMagenta, color.Bold).SprintFunc() line := "___" if frame { fmt.Printf("%s%s%s%s%s%s%s%s\n\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line)) } fmt.Println(" ",bR("L"),bHiR("A"),bHiY("B"),bHiG("O"),bHiC("R"),bHiB("A"),bHiM("V"),bM("I")) if frame { fmt.Printf("%s%s%s%s%s%s%s%s\n",bR(line),bHiR(line),bHiY(line),bHiG(line),bHiC(line),bHiB(line),bHiM(line),bM(line)) fmt.Println("(c) 2018 - n@gotsche.at\n") } } func init() { //red := color.New(color.FgRed).SprintFunc //green := color.New(color.FgGreen) //yellow := color.New(color.FgYellow) //use of package color without selectorcyan := color.New(color.FgCyan) //boldGreen := color.New(color.FgGreen, color.Bold) //boldRed := color.New(color.FgRed, color.Bold) flag.BoolVar(&test, "test", false, "Test Some Functions") flag.BoolVar(&newconfig, "config", false, "View and Edit Configuration") flag.BoolVar(&addcustomer, "add", false, "Adds a new Customer") flag.BoolVar(&allproj, "all", false, "Show all Projects") flag.BoolVar(&allbills, "allbills", false, "Show all Bills") flag.IntVar(&billcount, "showbills", 0, "How Many of Previous bills should be shown") flag.BoolVar(&runinter, "run", false, "Run in Interactive mode") flag.BoolVar(&newtask, "startnow", false, "Start a new Task in current project") flag.IntVar(&deltask, "deletetask", 0, "Specify which Task to delete") flag.IntVar(&edittaskid, "edittask", 0, "Specify which Task to edit") flag.IntVar(&editprojectid, "editproject", 0, "Specify which project to edit") flag.IntVar(&editcustomerid, "editcustomer", 0, "Specify which customer to edit") flag.IntVar(&projectid, "project", 0, "Specify which project to track") flag.BoolVar(&stoptask, "stopnow", false, "Stop the currently open task") flag.StringVar(&starttime, "start", "now", "Start a new Task in current project\nFormat: 'YYYY-MM-DD HH:MM' or 'HH:MM'") flag.StringVar(&stoptime, "stop", "now", "Stop to Track the current Task\nFormat: 'YYYY-MM-DD HH:MM' or 'HH:MM'") flag.BoolVar(&newproject, "new", false, "Create a new project") //flag.StringVar(&svar, "svar", "bar", "A String Var") // CUSTOMIZE USAGE flag.Usage = func() { fmt.Fprintf(os.Stderr, "Usage of %s Version 0.1.4:\n %s [Options] [Database]\n\n [Database] - must have .db fileextension, only one allowed\n\n [Options]:\n", os.Args[0],os.Args[0]) flag.PrintDefaults() } flag.Parse() } func stdOut() { showLastProject() getClosedTasks(0) showOpenTask() } func main() { boldRed := color.New(color.FgRed, color.Bold).SprintFunc() //fmt.Println("Laboravi Started") dbname := "./.mytimes.db" if flag.NFlag() > 0 { title(true) }else{ title(false) //fmt.Println("Laboravi Started") } initConf() dbname = config.Database if len(flag.Args())>0 { aar := flag.Args() var uar []string haveone := false for _,car := range aar { if filepath.Ext(car) == ".db" { if haveone { fmt.Println("Only One DB Allowed! Will ignore",car) } else { dbname=car haveone=true } }else{ uar = append(uar,car) } } if len(uar)>0 { fmt.Println("Unknown Commands: ",boldRed(uar)) } } initDB(dbname) getLastProject() //getProjects() getOpenTask() if test { fmt.Println("Nothing to test") //tmpltest() //newBill(1) //c := []int{2,3} //a,b := getUnfinishedList(c) //fmt.Println(a,b) os.Exit(0) } if allproj { allProjects() } if allbills { showLastBills(0) } else if (billcount>0) { showLastBills(billcount) } if runinter { interact() } if newconfig { editConf() } if newproject { newProject() os.Exit(0) } else if addcustomer { addCustomer() os.Exit(0) } else if newtask { showLastProject() newTask(projectid) stdOut() //showLastProject() //getClosedTasks(0) //showOpenTask() //os.Exit(0) } else if stoptask { closeTask() stdOut() //showLastProject() //getClosedTasks(0) //showOpenTask() } else if (starttime != "now") { showLastProject() newTaskTime(projectid,starttime) os.Exit(0) } else if (stoptime != "now") { closeTaskTime(stoptime) stdOut() //showLastProject() //getClosedTasks(0) //showOpenTask() } else if (deltask>0) { deleteTask(deltask) } else if (edittaskid>0) { editTask(edittaskid) } else if (editprojectid>0) { editProject(editprojectid) } else if (editcustomerid>0) { editCustomer(editcustomerid) } else if (projectid>0) { setProject(projectid) stdOut() //showLastProject() //getClosedTasks(0) //showOpenTask() } else { //showLastProject() //getClosedTasks(0) //showOpenTask() stdOut() } //fmt.Println("Start Act:",actstart) //fmt.Println("Stop Act:",actstop) //fmt.Println("Project:",projectid) //fmt.Println("New Project:",newproject) //fmt.Println("svar:",svar) //fmt.Println("Unknown Commands: ",flag.Args()) }