-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.js
executable file
·84 lines (74 loc) · 2.24 KB
/
cli.js
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
#! /usr/bin/env node
// Upload grades from a CSV file to Canvas
var postGrades = require('./uploader.js');
var fs = require('fs');
var path = require('path');
var ArgumentParser = require('argparse').ArgumentParser;
// Handle Command Line Args
var parser = new ArgumentParser({
version: '1.0.1',
addHelp: true,
description: 'This script uploads a CSV file to the specified Canvas course.',
epilogue: 'THIS NEEDS TO BE WRITTEN...should describe process for getting a token.'
});
parser.addArgument(
[ '-c', '--course-id' ],
{
help: 'This is the Canvas ID of the course.',
required: true
}
);
parser.addArgument(
[ '-a', '--assignment-id' ],
{
help: 'This is the Canvas ID of the assignment to post grades to.',
required: true
}
);
parser.addArgument(
['-f', '--file' ],
{
help: 'A CSV file of grades. It must include a "SID" column and a "Total Score" column.',
required: true
}
);
parser.addArgument(
[ '-u', '--url' ],
{
help: 'Specify a URL of the Canvas instance to use.\n\tThis currently defaults to Berkeley bCourses.',
defaultValue: 'https://bcourses.berkeley.edu/',
required: false
}
);
parser.addArgument(
[ '-t', '--token' ],
{
help: 'An API token is required to upload scores. Use this option or export CANVAS_TOKEN.',
defaultValue: process.env.CANVAS_TOKEN,
required: process.env.CANVAS_TOKEN ? false : true
}
);
parser.addArgument(
[ '-sid', '--student-id-format' ],
{
// TODO: Un-Berkeley-ify this option
help: 'Canvas SIS id format. This currently defaults to "sis_user_id" which is used at UC Berkeley.' +
'\nThis controls what ID options Canvas uses to find a student.',
defaultValue: 'sis_user_id',
choices: [
'""',
'sis_login_id',
'sis_user_id'
],
required: false
}
);
// TODO: Header SID
// TODO: Header Grade
// Verify Args Exist
var ARG_VALS, gradesFile;
ARG_VALS = parser.parseArgs();
// Specify encoding to return a string
gradesFile = fs.readFileSync(ARG_VALS.file, { encoding: 'utf8'});
// TODO: make the callback be a more useful function.
postGrades(ARG_VALS, gradesFile, console.log);