summaryrefslogtreecommitdiff
path: root/main.go
blob: 4ba74197cb8b3ea923a43c6aa24e6ccb40fae2a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main

import (
    "fmt"
    //"flag"
    "path/filepath"
    _ "log"
    //"bufio"
    "os"
    //"strings"
    _ "os/exec"
    "github.com/fatih/color"
    "github.com/pborman/getopt/v2"
)

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] <Commands>\n\nOptions:\n", os.Args[0],version,compdate,os.Args[0])
        fmt.Fprintf(os.Stdout, "Usage of %s   Version %s  (%s):\n   %s [Options] <Commands>\n\nOptions:\n", os.Args[0],version,compdate,os.Args[0])
        flag.PrintDefaults()
        interArgs = append([]string{"help"},interArgs...)
    }
    //flag.SetOutput(os.Stdout)
    flag.Parse()*/

}


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")
    }
}

func stdOut() {

    showLastProject()
    getClosedTasks(0)
    showOpenTask()
}

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  (%s):\n  Use Commands as Parameters\n\n", os.Args[0],version,compdate)
        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())
        fmt.Println("Nothing to test")
        //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 ~/.<name>.db")
            }
        }
    }else{
        dbname = config.Database
    }

    if !help {
    initDB(dbname)
    getLastProject()
    getOpenTask()
    }

    interact()

}