/
workspaces.go
43 lines (35 loc) · 866 Bytes
/
workspaces.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
package command
import (
"strconv"
"github.com/sachaos/toggl/cache"
"github.com/sachaos/toggl/lib"
"github.com/spf13/viper"
"github.com/urfave/cli"
)
func (app *App) getWorkspaces(c *cli.Context) (workspaces toggl.Workspaces, err error) {
workspaces = cache.GetContent().Workspaces
if len(workspaces) == 0 || !c.GlobalBool("cache") {
workspaces, err = app.client.FetchWorkspaces()
cache.SetWorkspaces(workspaces)
cache.Write()
}
return
}
func (app *App) CmdWorkspaces(c *cli.Context) error {
workspaces, err := app.getWorkspaces(c)
if err != nil {
return err
}
writer := NewWriter(c)
defer writer.Flush()
for _, workspace := range workspaces {
var flg string
if workspace.ID == viper.GetInt("wid") {
flg = "*"
} else {
flg = ""
}
writer.Write([]string{flg, strconv.Itoa(workspace.ID), workspace.Name})
}
return nil
}