-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.go
61 lines (48 loc) · 1.3 KB
/
info.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
// Copyright 2015 Ondřej Doněk. All rights reserved.
// See LICENSE file for more details about licensing.
package main
import (
"database/sql"
"fmt"
"github.com/odTimeTracker/odtimetracker-go-lib/database"
"log"
"os"
)
// TODO Display also current work time for today.
// Here is implementation of the "info" command.
var cmdInfo = &Command{
Name: "info",
Desc: "Print info about current status.",
UsageDesc: "",
Run: runInfo,
Help: helpInfo,
}
// Template for help of "list" command.
const cmdInfoHelp = `
Usage:
%s %s
%s
If there is a running activity print its name and duration otherwise print
message that there is no running activity.
`
// Execute "info" command. Called from function "main()".
func runInfo(cmd *Command, db *sql.DB, args []string) {
if len(args) != 0 {
cmd.Usage("\nUsage:\n\n\t", "\n")
os.Exit(1)
}
a, err := database.SelectActivityRunning(db)
if err == sql.ErrNoRows {
fmt.Printf("\nThere is no running activity.\n\n")
} else if err != nil {
fmt.Printf("\nFatal error occured!\n\n")
log.Fatal(err)
} else {
fmt.Printf("\nThere is running activity '%s'.\nTime spent up to now: %s\n\n",
a.Name, a.Duration())
}
}
// Render help for "info" command.
func helpInfo(cmd *Command) {
fmt.Printf(cmdInfoHelp, AppShortName, cmd.Name, cmd.Desc)
}