1
- // TODO: clean this entire file
2
- //! Pick command
1
+ //! Contest command (WIP)
2
+ /** TODO:
3
+ * Improve pretty printing of contest info
4
+ * (maybe) make a UI to play a full contest in
5
+ */
3
6
use super :: Command ;
4
7
use crate :: err:: Error ;
5
8
use async_trait:: async_trait;
6
9
use clap:: { App , Arg , ArgMatches , SubCommand } ;
7
10
8
- /// TODO: put the actual correct docstring here
9
- /// ```
10
- pub struct ContestCommand ;
11
+ /**
12
+ leetcode-contest
13
+ Run a contest
14
+
15
+ USAGE:
16
+ leetcode contest [FLAGS] <title>
11
17
12
- // TODO: and here
13
- static _QUERY_HELP: & str = r#"Fliter questions by conditions:
14
- Uppercase means negative
15
- e = easy E = m+h
16
- m = medium M = e+h
17
- h = hard H = e+m
18
- d = done D = not done
19
- l = locked L = not locked
20
- s = starred S = not starred"# ;
18
+ FLAGS:
19
+ -h, --help Prints help information
20
+ -r, --register register for contest
21
+ -u, --update push contest problems into db
22
+ -V, --version Prints version information
21
23
22
- /*
23
- *
24
+ ARGS:
25
+ <title> Contest title (e.g. 'weekly-contest-999')
24
26
*/
27
+ pub struct ContestCommand ;
25
28
26
29
fn time_diff_from_now ( time_since_epoch : i64 ) -> i64 {
27
30
use chrono:: { Utc , TimeZone } ;
@@ -47,10 +50,12 @@ impl Command for ContestCommand {
47
50
Arg :: with_name ( "update" )
48
51
. help ( "push contest problems into db" )
49
52
. short ( "u" )
53
+ . long ( "update" )
50
54
) . arg (
51
55
Arg :: with_name ( "register" )
52
56
. help ( "register for contest" )
53
57
. short ( "r" )
58
+ . long ( "register" )
54
59
)
55
60
}
56
61
@@ -61,10 +66,13 @@ impl Command for ContestCommand {
61
66
use std:: thread:: sleep;
62
67
use std:: time:: Duration ;
63
68
69
+ // get contest info
64
70
let cache = Cache :: new ( ) ?;
65
71
let contest_slug = m. value_of ( "title" ) . unwrap ( ) ;
66
72
let mut contest = cache. get_contest ( contest_slug) . await ?;
67
73
debug ! ( "{:#?}" , contest) ;
74
+
75
+ // if requested, register for contest && update contest info
68
76
if m. is_present ( "register" ) {
69
77
if contest. registered {
70
78
println ! ( "You are already registered for this contest." ) ;
@@ -76,6 +84,7 @@ impl Command for ContestCommand {
76
84
}
77
85
}
78
86
87
+ // if contest has not started, print a countdown
79
88
let tdiff = time_diff_from_now ( contest. start_time ) ;
80
89
if tdiff > 0 {
81
90
loop {
@@ -91,10 +100,12 @@ impl Command for ContestCommand {
91
100
println ! ( "started {} seconds ago" , -tdiff) ;
92
101
} ;
93
102
103
+ // display contest header
94
104
println ! ( "{}" , contest) ;
95
105
println ! ( "fID Points Difficulty Title" ) ;
96
106
println ! ( "------|------|----------|--------------------" ) ;
97
107
108
+ // get contest problems (pushing them to db if necessary), and display them
98
109
for question_stub in contest. questions {
99
110
let slug = & question_stub. title_slug ;
100
111
let ( problem, _question) = cache. get_contest_qnp ( slug) . await ?;
@@ -105,7 +116,6 @@ impl Command for ContestCommand {
105
116
problem. name
106
117
) ;
107
118
debug ! ( "{:#?}" , problem) ;
108
- //println!("{:#?}", cache.get_problem(problem.fid)?);
109
119
debug ! ( "----------------------------------" ) ;
110
120
if m. is_present ( "update" ) {
111
121
cache. push_problem ( problem) ?;
0 commit comments