-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path_grader.zsh
155 lines (136 loc) · 5.42 KB
/
_grader.zsh
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
146
147
148
149
150
151
152
153
154
155
_grader_completion() {
if [[ -z "$GRADER_HOME" ]] || [[ ! -d "$GRADER_HOME" ]] || [[ ! -e "$GRADER_HOME/config.yml" ]]; then
local -x GRADER_HOME=""
# Guess GRADER_HOME if it's not set.
if [[ -e "$(pwd)/grader.yml" ]]; then
GRADER_HOME=`pwd`
elif [[ ! -z "$(which grader)" ]]; then
GRADER_HOME="$(which grader | rev | cut -d'/' -f3- | rev)"
fi
fi
if [[ ! -e "$GRADER_HOME/grader.yml" ]]; then
return
fi
##### Get all assignments ####
local -a assignments
assignments=( $GRADER_HOME/assignments/* )
# Now trim everything except for the folder names.
assignments=( $( echo "$GRADER_HOME/assignments"/* | xargs -i -d' ' sh -c "echo -e \"{}\" | rev | cut -d'/' -f-1 | rev") )
##############################
#### Get all students ####
local -a students
# Extract students from roster:
students=( $(cat "$GRADER_HOME/grader.yml" | grep -P --color=never "\s+\-?\s*id:" | sed -e 's/\s*\-\?\s*id:\s*\([A-Za-z0-9_]\+\)$/\1/g') )
##########################
local -a verbosity
verbosity=( "DEBUG" "INFO" "WARNING" "ERROR" )
_arguments \
"(- 1 *)-h[display grader help and exit]" \
"(- 1 *)--help[display grader help and exit]" \
"--path[specify grader's root manually]: :" \
"--tracebacks[show grader tracebacks when there is an error]" \
"--verbosity[configure how verbose output]: :{_describe 'verbosity level' verbosity}" \
"1: :->cmds" \
'*:: :->args' && ret=0
case $state in
cmds)
_values "grader command" \
"init[initialize grader by creating grader.yml]" \
"new[Create a new assignment]" \
"build[Build an assignment's docker image]" \
"import[Import student submission(s)]" \
"list[List student submission(s)]" \
"grade[Grade student submission(s)]" \
"cat[Print an assignment's grade output to STDOUT]" \
"report[Generate reports using a gradesheet template]" \
"inspect[Inspect a graded submission's container]" \
"help[Show help for grader and exit]"
ret=0
;;
args)
# Trim assignment list to just have assignment names
case $line[1] in
init)
_arguments \
'--help[View help for init and exit]' \
'--force[Overwrite an existing grader.yml]' \
'--course-id[Unique course ID (for docker)]'
ret=0
;;
build)
_arguments \
'--help[View help for build and exit]' \
'--no-cache[Do not use docker image cache when building]' \
'--pull[Pull the gradesheet repo before building]' \
'--silent[Do not parse and display output from docker]' \
"1: :{_describe 'assignments' assignments}"
ret=0
;;
import)
local -a _kinds
_kinds=("blackboard" "multiple" "single" "repo")
_arguments \
'--help[View help for import and exit]' \
"--kind: :{_describe 'kind of import' _kinds}" \
"1: :{_describe 'assignments' assignments}" \
"2: *:_files"
ret=0
;;
list)
local -a _sortby
_sortby=("time" "name")
_arguments \
'--help[View help for list and exit]' \
"--submissions[Show submissions for each assignment]" \
"--full[Show full length of values]" \
"--sortby[Sort by a specific field]: :{_describe 'sort import by' _sortby}" \
"1: :{_describe 'assignments' assignments}"
ret=0
;;
grade)
_arguments \
'--help[View help for grade and exit]' \
'--rebuild[Rebuild cointainers (if they exist)]' \
"--suppress_output[Don't display output]" \
"1: :{_describe 'assignments' assignments}" \
"2: :{_describe 'students' students }"
ret=0
;;
cat)
local -a _submissions
_submissions=()
# FUTURE: Ideally, this would only grab submissions from the assignment/student you specified...
# http://stackoverflow.com/a/23357277/7065175
while IFS= read -r -d $'\0'; do
# Trim to just the submission ID alone.
_submissions+=($(echo "$REPLY" | rev | cut -d'/' -f-1 | rev))
done < <(find "$GRADER_HOME/assignments/" -wholename '*/*{*}' -print0)
_arguments \
'--help[View help for cat and exit]' \
"--submission_id[ID of a specific submission to cat]: :{_describe 'ALL submissions' _submissions}" \
"1: :{_describe 'assignments' assignments}" \
"2: :{_describe 'students' students }"
ret=0
;;
inspect)
_arguments \
'--help[View help for inspect and exit]' \
"--user[username of a specific container user to inspect as]: :" \
"1: :{_describe 'assignments' assignments}" \
"2: :{_describe 'students' students }"
ret=0
;;
report)
_arguments \
'--help[View help for report and exit]' \
'--template[Type of template to use]:' \
"1: :{_describe 'assignments' assignments}" \
"::OPTIONAL :{_describe 'students' students }"
ret=0
;;
esac
;;
esac
return ret
}
compdef _grader_completion grader