-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (47 loc) · 1.51 KB
/
main.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
package main
import (
"fmt"
"io/ioutil"
"os"
"strings"
"github.com/zachdeibert/canvas-sync/canvas"
"github.com/zachdeibert/canvas-sync/canvassync"
)
func main() {
subdomain := ""
if len(os.Args) >= 2 {
subdomain = os.Args[1]
}
token := ""
if len(os.Args) == 2 {
var err error
var b []byte
if b, err = ioutil.ReadFile(fmt.Sprintf("%s.pri", subdomain)); err != nil {
if os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "Error: no authentication token specified but file '%s.pri' does not exist.\n", subdomain)
}
}
token = string(b)
} else if len(os.Args) >= 3 {
token = os.Args[2]
}
if len(subdomain) == 0 || len(token) == 0 || len(os.Args) > 3 {
fmt.Fprintf(os.Stderr, "Usage: %s <canvas subdomain> [authenication token]\n"+
"\n"+
"canvas subdomain: This is the subdomain of instructure.com to use.\n"+
" For example, this would be 'canvas' for the domain 'canvas.instructure.com'.\n"+
"\n"+
"authenication token: This is the authentication token to use for connecting to Canvas.\n"+
" If this argument is not given, a file named <canvas subdomain>.pri must be\n"+
" present in the current directory that contains the token.\n", os.Args[0])
os.Exit(1)
}
if err := os.RemoveAll("db/tmp"); err != nil {
panic(err)
}
c, err := canvas.CreateCanvas(strings.TrimSpace(subdomain), strings.TrimSpace(token), "db/tmp")
if err != nil {
panic(err)
}
canvassync.Run(c)
}