forked from bpicode/fritzctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_phonecalls.go
57 lines (49 loc) · 1.15 KB
/
list_phonecalls.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
package cmd
import (
"fmt"
"os"
"github.com/bpicode/fritzctl/console"
"github.com/bpicode/fritzctl/fritz"
"github.com/bpicode/fritzctl/logger"
"github.com/spf13/cobra"
)
var listCallsCmd = &cobra.Command{
Use: "phonecalls",
Short: "List recent phone calls",
Long: "List recently made phone calls.",
Example: "fritzctl list phonecalls",
RunE: listCalls,
}
var callTypeVsDescription = map[string]string{
"1": "incoming",
"2": "missed",
"3": "rejected",
"4": "outgoing",
}
func init() {
listCmd.AddCommand(listCallsCmd)
}
func listCalls(_ *cobra.Command, _ []string) error {
c := clientLogin()
f := fritz.NewPhone(c)
calls, err := f.Calls()
assertNoErr(err, "cannot obtain phone calls")
logger.Success("Recent phone calls:\n")
printCalls(calls)
return nil
}
func printCalls(calls []fritz.Call) {
table := console.NewTable(console.Headers("TYPE", "DATE", "CALLER", "DURATION"))
for _, c := range calls {
table.Append(callColumns(c))
}
table.Print(os.Stdout)
}
func callColumns(c fritz.Call) []string {
return []string{
callTypeVsDescription[c.Type],
c.Date,
fmt.Sprintf("%s %s", c.Caller, c.PhoneNumber),
c.Duration,
}
}