summaryrefslogtreecommitdiff
path: root/main.go
blob: 39b48efb43ec04bc42b9a0f49ce9b010a2a93e30 (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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
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())
}