-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.js
143 lines (132 loc) · 4.56 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
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
#!/usr/bin/env node
var udebug = require("./lib/udebug.lib");
var uhunt = require("uhunt-node");
var compile = require('./lib/compile');
var table = require("./lib/table")
const prog = require('caporal');
var spinner = require('./lib/spinner');
var testing = require('./lib/testing');
prog
.version(require("./package.json").version)
/**
* Compile command
*/
.command('compile', 'Compile file java or cpp')
.alias('c')
.argument('<file>', 'Codigo fuente .cpp, .java')
.action((args, options, logger) => {
spinner.start("Compiling source code " + args.file);
var file = args.file;
if (file.endsWith('.cpp')) { // Compile cpp
compile.cpp(file).then(_out => {
spinner.stop();
console.log(_out ? _out : 'Compilado')
},
err => {
spinner.stop();
console.log("Error:", err)
});
} else if (file.endsWith('.java')) { // compile java
compile.java(file).then(_out => {
spinner.stop();
console.log(_out ? _out : 'Compilado')
},
err => {
spinner.stop();
console.log("Error:", err)
});
} else {
spinner.stop();
console.log("Error", args.file, " => No aceptado")
}
})
/**
* test command
*/
.command('test', 'test source code java or cpp')
.alias('t')
.argument('<file>', 'Source code *.cpp o *.java')
.argument('[number]', 'Number of exercise *.cpp o *.java')
.action((args, options, logger) => {
spinner.start("Analyzing " + args.file + (args.number ? args.number : ''));
spinner.changeText("Loading fuel for spacecraft", 1000);
testing.test(args.file, args.number).then((result => {
spinner.changeText("Loading fuel for spacecraft", 500);
spinner.changeText("Preparing motor warp", 500);
spinner.stopSucceed("Completed");
}, err => {
spinner.stopFail(err);
console.log("Fallo: ", err);
}));
})
/**
* Describe un ejercicio
*/
.command('desc', 'Describe exercise')
.alias('d')
.argument('<number>', 'Number of exercise')
.action((args, options, logger) => {
spinner.start("Loading exercise description " + args.number);
// console.log("Descripcion del ejercicio: ", args.number)
uhunt.byNum(args.number).then(data => {
spinner.stopSucceed("Completed");
// console.log(data);
table.show(['pid', 'number', 'title', 'limit', 'status'], [data.pid, data.num, data.title, data.rtl, data.status])
})
})
/**
* Casos de pruebas
*/
.command('cases', 'Check test cases')
.alias('cs')
.argument('<number>', 'Number of exercise')
.argument('[save]', 'Save program execution output') // hacer que cuando este argumento este presente entocnes que se gurde los casos de salida
.action((args, options, logger) => {
spinner.start("Loading test cases of the exercise " + args.number);
udebug.get(args.number).then(data => {
spinner.stopSucceed("Completed");
var test_cases = [];
data.map((item, index) => {
// test_cases.push(item.output.input_value);
console.log("-----------Start case-----------")
table.show(['#', 'Number', 'DataID', 'User', 'Date', 'Votes'], [(index + 1), item.number, item.dataid, item.user, item.date, item.votes])
console.log("Case ", (index + 1), " by ", item.user, ":");
console.log(item.output.input_value)
console.log("------------End case------------")
})
// console.log(test_cases)
});
})
/**
* Consultar los envios de un usuario
*/
.command('submissions', 'Submissions by user')
.alias('sb')
.argument('<number>', 'Numero de usuario: ID User')
.action((args, options, logger) => {
spinner.start("Loading submissions by " + args.number);
uhunt.getUserSubmission(args.number).then(submiss => {
spinner.stopSucceed("Completed");
// console.log(submiss);
table.show(['name', 'user name'], [
submiss.name,
submiss.uname
]);
var subs = [];
submiss.subs.map((item) => subs.push([item.reference, item.problem, item.result, item.time, item.code, item.date]));
table.multi(['Reference', 'problem', 'result', 'time', 'code', 'date'], subs, [11, 9, 21, 8, 8, 41]);
}, err => {
console.log("Error: ", submiss);
})
// logger.log("I'm walking !")
})
/**
* Consultar los envios de un usuario
*/
.command('solutions', 'Casos de prueba')
.alias('ss')
.argument('<number>', 'Numero de usuario: ID User')
.action((args, options, logger) => {
// logger.log("I'm walking !")
})
prog.parse(process.argv);