-
Notifications
You must be signed in to change notification settings - Fork 1
/
report.go
113 lines (87 loc) · 2.81 KB
/
report.go
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
// Copyright 2015 Ondřej Doněk. All rights reserved.
// See LICENSE file for more details about licensing.
package main
import (
"database/sql"
"fmt"
// db "github.com/odTimeTracker/odtimetracker-go-lib/database"
"github.com/odTimeTracker/odtimetracker-go-lib/reports"
"log"
"os"
"strings"
)
// Here is implementation of the "report" command.
var cmdReport = &Command{
Name: "report",
Desc: "Render HTML report from the collected data.",
UsageDesc: "[--today|--week|--month] [--file=FILE] [--project=PROJECT_NAME] [--tag=TAG]",
Run: runReport,
Help: helpReport,
}
// Template for help of "report" command.
const cmdReportHelp = `
Usage:
%[1]s %[2]s %[3]s
%[4]s
Report will be written into the specified file. If file doesn't exist will be created if exist will be overwritten.
If FILE is not set the default "report.html" is used.
Report can be created from data for the specified period, currently are supported these:
--today Report for today activities.
--week Report for activities tracked this week.
--month Report for activities tracked this month (default).
Data for report can be also filtered:
--project=PROJECT_NAME Filter activities by the project.
--tag=TAG Filter activites by the tag.
Report is written to the specified file (or is used default file name "report.html"):
--flag=FILE File name for the generated report.
Examples:
%[1]s %[2]s
%[1]s %[2]s --project="odTimeTracker"
%[1]s %[2]s --month --file="test.html"
%[1]s %[2]s --month --project="odTimeTracker" --tag="tag1" --file="test.html"
`
// Execute "report" command. Called from function "main()".
func runReport(cmd *Command, db *sql.DB, args []string) {
if len(args) > 4 {
cmd.Usage("\nUsage:\n\n\t", "\n")
os.Exit(1)
}
log.Println(args)
var rtype = reports.ReportTypeDaily
var pid int64 = 0
var tags string = ""
var format = reports.ReportFormatHtml
for _, a := range args {
switch a {
case "--today":
rtype = reports.ReportTypeDaily
case "--week":
rtype = reports.ReportTypeWeekly
case "--month":
rtype = reports.ReportTypeMonthly
}
if strings.HasPrefix(a, "--project=") == true {
//pname = strings.Replace(a, "--file=", "", 1)
// ...
}
if strings.HasPrefix(a, "--tag=") == true {
//tags = strings.Replace(a, "--tag=", "", 1)
// ...
}
if strings.HasPrefix(a, "--file=") == true {
//filename = strings.Replace(a, "--file=", "", 1)
// ...
}
}
log.Println("TODO Implement 'report' command!")
log.Println(rtype)
log.Println(pid)
log.Println(tags)
log.Println(format)
//r := reports.NewReport(rtype, format, pid, tags)
//log.Println(r)
}
// Render help for "info" command.
func helpReport(cmd *Command) {
fmt.Printf(cmdReportHelp, AppShortName, cmd.Name, cmd.UsageDesc, cmd.Desc)
}