// Copyright 2018 n@gotsche.at // All Rights Reserved // Laboravi - Timetracker and Bill generator // // I came, I worked, I Billed package main import ( "fmt" _ "log" "os" "path/filepath" //"strings" "github.com/fatih/color" "github.com/pborman/getopt/v2" _ "os/exec" ) var ( version string compdate string ) //var svar string //var starttime,stoptime,filename string //var projectid int //, edittaskid, editprojectid, editcustomerid int //var deltask,delbill int //var addcustomer bool //var newproject, newtask, stoptask, allproj, allbills, runinter, test, newconfig bool //var billcount int var test, help bool var filename string var interArgs []string //var red, green, yellow, cyan color //var boldRed, boldGreen color func init() { filename = "none" //interArgs = removeStringFromArray(os.Args[1:],"-file",1) getopt.FlagLong(&test, "test", 't', "Test some new Functions") getopt.FlagLong(&help, "help", 'h', "Show Program Usage") getopt.FlagLong(&filename, "file", 'f', "Load different DB than in config") //flag.StringVar(&svar, "svar", "bar", "A String Var") /* flag.BoolVar(&test, "test", false, "Test Some Functions") flag.StringVar(&filename, "file", "none", "Open a different Database than specified in Configuration") // CUSTOMIZE USAGE flag.Usage = func() { //fmt.Fprintf(os.Stderr, "Usage of %s Version %s (%s):\n %s [Options] \n\nOptions:\n", os.Args[0],version,compdate,os.Args[0]) fmt.Fprintf(os.Stdout, "Usage of %s Version %s (%s):\n %s [Options] \n\nOptions:\n", os.Args[0],version,compdate,os.Args[0]) flag.PrintDefaults() interArgs = append([]string{"help"},interArgs...) } //flag.SetOutput(os.Stdout) flag.Parse()*/ } // title prints the colored Laboravi Logo. // // Argument decides if a Frame shpuld be drawn around it. 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.Printf("Version %s (%s)\n", version, compdate) fmt.Println("(c) 2018 - n@gotsche.at\n") } } // stdOut shows the standard output the user can determine // the state of Laboravi immediately. func stdOut() { //showLastProject() //getClosedTasks(0) //showOpenTask() showStatus(false) } func main() { //boldRed := color.New(color.FgRed, color.Bold).SprintFunc() //fmt.Println("Laboravi Started") getopt.Parse() interArgs = getopt.Args() //fmt.Println(interArgs) dbname := "./.mytimes.db" if len(interArgs) > 0 { title(false) } else { title(true) } if help { fmt.Printf("Usage of %s Version %s:\n Use Commands as Parameters\n If Commands or flags other than -f were passed %s exits after execution of command.\n\n", os.Args[0], version, os.Args[0]) getopt.Usage() interArgs = append([]string{"help"}, interArgs...) } else if test { //fmt.Println(Round(12.55,0.5),Round(12.55,0.1),Round(12.55,1),Round(12.55,5)) //fmt.Println(getGitTag()) //multichoice("Fuckoff") fmt.Println(mli,"halllllllooooo",li,li,li) fmt.Println(nli) fmt.Println(sli,"Something something Something") fmt.Println(nli,"And some more text lalala") fmt.Println(fli,"And some End") fmt.Println("Nothing to test") fmt.Println(frame("HEADLINE",true)) fmt.Println(sli,"Something something Something") fmt.Println(nli,"And some more text lalala") fmt.Println(nli) fmt.Println(sli,"More Something Something") fmt.Println(nli,"And even some more text lalala") fmt.Println(nli) fmt.Println(frame("FOOTER",false)) //tmpltest() //newBill(1) //c := []int{2,3} //a,b := getUnfinishedList(c) //fmt.Println(a,b) os.Exit(0) } else { initConf() } haveone := false if filename != "none" { if haveone { fmt.Println("Only One DB Allowed! Will ignore", filename) } else { haveone = true dbname = filename if filepath.Ext(filename) != ".db" || filepath.Ext(filename) != ".sql" { fmt.Println("Please consider to use a file extension like .db or .sql \n like ~/..db") } } } else { dbname = config.Database } if !help { initDB(dbname) pausetask = getPauseTask() getLastProject() getOpenTask() } interact() fmt.Println("Laboravi finietur...") }