-
Notifications
You must be signed in to change notification settings - Fork 3
/
trello_options.go
145 lines (115 loc) · 2.91 KB
/
trello_options.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
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
package main
import (
"fmt"
"log"
"strconv"
"strings"
trello "github.com/jnormington/go-trello"
)
// TrelloOptions stores options that the user has selected
type TrelloOptions struct {
Board *trello.Board
List *trello.List
User *trello.Member
ProcessImages bool
}
// SetupTrelloOptionsFromUser calls all the functions which consist of questions
// for building TrelloOptions and returns a pointer to TrelloOptions instance
func SetupTrelloOptionsFromUser() *TrelloOptions {
var t TrelloOptions
t.promptUserShouldMigrateAttachments()
t.getCurrentUser()
t.getBoardsAndPromptUser()
t.getListsAndPromptUser()
return &t
}
func (t *TrelloOptions) promptUserShouldMigrateAttachments() {
fmt.Println("Would you like to migrate all attachments from trello cards?")
fmt.Println("This will entail downloading the attachments and uploading to dropbox")
fmt.Println("A dropbox account will be required for the token")
for i, b := range yesNoOpts {
fmt.Printf("[%d] %s\n", i, b)
}
i := promptUserSelectResource()
if i >= len(yesNoOpts) {
log.Fatal(errOutOfRange)
}
if i == 0 {
t.ProcessImages = true
if dropboxToken == "" {
log.Fatal("Dropbox token not supplied unable to continue")
}
}
}
func (t *TrelloOptions) getCurrentUser() {
c, err := trello.NewAuthClient(trelloKey, &trelloToken)
if err != nil {
log.Fatal(err)
}
u, err := c.Member("me")
if err != nil {
log.Fatal(err)
}
t.User = u
}
func (t *TrelloOptions) getBoardsAndPromptUser() {
boards, err := t.User.Boards()
if err != nil {
log.Fatal(err)
}
fmt.Println("Please select a board by its number")
for i, b := range boards {
fmt.Printf("[%d] %s\n", i, b.Name)
}
i := promptUserSelectResource()
if i >= len(boards) {
log.Fatal(errOutOfRange)
}
t.Board = &boards[i]
}
func (t *TrelloOptions) getListsAndPromptUser() {
lists, err := t.Board.Lists()
if err != nil {
log.Fatal(err)
}
fmt.Println("Please select the list to import by number")
for i, l := range lists {
fmt.Printf("[%d] %s\n", i, l.Name)
}
i := promptUserSelectResource()
if i >= len(lists) {
log.Fatal(errOutOfRange)
}
t.List = &lists[i]
}
func (t TrelloOptions) getCards() []trello.Card {
fmt.Println("Please wait while we retrieve your cards... This might take a few minutes.")
cards, err := t.List.Cards()
if err != nil {
log.Fatal(err)
}
return cards
}
func promptUserSelectResource() int {
i, err := stdinReader.ReadString('\n')
if err != nil {
log.Fatal(err)
}
i = strings.TrimRight(i, "\n")
i = strings.TrimRight(i, "\r")
id, err := strconv.Atoi(i)
if err != nil {
log.Fatal("Hmm... did you type a number from the list ?")
}
return id
}
// ListMembers gets the members for the selected board.
// And fails hard if an err occurs.
func (t TrelloOptions) ListMembers() *[]trello.Member {
m, err := t.Board.Members()
if err != nil {
fmt.Println("Error retrieving board members")
log.Fatal(err)
}
return &m
}