Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 7, 2024. It is now read-only.

Commit eefa2f0

Browse files
committed
clean up contest/fun commands code
1 parent b3d8cf5 commit eefa2f0

File tree

2 files changed

+31
-56
lines changed

2 files changed

+31
-56
lines changed

‎src/cmds/contest.rs

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
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+
*/
36
use super::Command;
47
use crate::err::Error;
58
use async_trait::async_trait;
69
use clap::{App, Arg, ArgMatches, SubCommand};
710

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>
1117
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
2123
22-
/*
23-
*
24+
ARGS:
25+
<title> Contest title (e.g. 'weekly-contest-999')
2426
*/
27+
pub struct ContestCommand;
2528

2629
fn time_diff_from_now(time_since_epoch: i64) -> i64 {
2730
use chrono::{Utc,TimeZone};
@@ -47,10 +50,12 @@ impl Command for ContestCommand {
4750
Arg::with_name("update")
4851
.help("push contest problems into db")
4952
.short("u")
53+
.long("update")
5054
).arg(
5155
Arg::with_name("register")
5256
.help("register for contest")
5357
.short("r")
58+
.long("register")
5459
)
5560
}
5661

@@ -61,10 +66,13 @@ impl Command for ContestCommand {
6166
use std::thread::sleep;
6267
use std::time::Duration;
6368

69+
// get contest info
6470
let cache = Cache::new()?;
6571
let contest_slug = m.value_of("title").unwrap();
6672
let mut contest = cache.get_contest(contest_slug).await?;
6773
debug!("{:#?}", contest);
74+
75+
// if requested, register for contest && update contest info
6876
if m.is_present("register") {
6977
if contest.registered {
7078
println!("You are already registered for this contest.");
@@ -76,6 +84,7 @@ impl Command for ContestCommand {
7684
}
7785
}
7886

87+
// if contest has not started, print a countdown
7988
let tdiff = time_diff_from_now(contest.start_time);
8089
if tdiff > 0 {
8190
loop {
@@ -91,10 +100,12 @@ impl Command for ContestCommand {
91100
println!("started {} seconds ago", -tdiff);
92101
};
93102

103+
// display contest header
94104
println!("{}", contest);
95105
println!("fID Points Difficulty Title");
96106
println!("------|------|----------|--------------------");
97107

108+
// get contest problems (pushing them to db if necessary), and display them
98109
for question_stub in contest.questions {
99110
let slug = &question_stub.title_slug;
100111
let (problem,_question) = cache.get_contest_qnp(slug).await?;
@@ -105,7 +116,6 @@ impl Command for ContestCommand {
105116
problem.name
106117
);
107118
debug!("{:#?}", problem);
108-
//println!("{:#?}", cache.get_problem(problem.fid)?);
109119
debug!("----------------------------------");
110120
if m.is_present("update") {
111121
cache.push_problem(problem)?;

‎src/cmds/fun.rs

Lines changed: 4 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,16 @@
11
// TODO: get rid of this debug command? clean it && make it permanent?
22

3-
//! Pick command
3+
//! Fun command
44
use super::Command;
55
use crate::err::Error;
66
use async_trait::async_trait;
77
use clap::{App, Arg, ArgMatches, SubCommand};
8-
/// Abstract contest command
9-
///
10-
/// ```sh
11-
/// leetcode-contest
12-
/// Pick a problem
13-
///
14-
/// USAGE:
15-
/// leetcode contest [OPTIONS] [id]
16-
///
17-
/// FLAGS:
18-
/// -h, --help Prints help information
19-
/// -V, --version Prints version information
20-
///
21-
/// OPTIONS:
22-
/// -q, --query <query> Fliter questions by conditions:
23-
/// Uppercase means negative
24-
/// e = easy E = m+h
25-
/// m = medium M = e+h
26-
/// h = hard H = e+m
27-
/// d = done D = not done
28-
/// l = locked L = not locked
29-
/// s = starred S = not starred
30-
///
31-
/// ARGS:
32-
/// <id> Problem id
33-
/// ```
348
pub struct FunCommand;
359

36-
static _QUERY_HELP: &str = r#"Fliter questions by conditions:
37-
Uppercase means negative
38-
e = easy E = m+h
39-
m = medium M = e+h
40-
h = hard H = e+m
41-
d = done D = not done
42-
l = locked L = not locked
43-
s = starred S = not starred"#;
44-
4510
#[async_trait]
4611
impl Command for FunCommand {
47-
/// `contest` usage
48-
fn usage<'a, 'contest>() -> App<'a, 'contest> {
12+
/// `fun` usage
13+
fn usage<'a, 'fun>() -> App<'a, 'fun> {
4914
SubCommand::with_name("fun")
5015
.about("fun")
5116
.visible_alias("f")
@@ -72,7 +37,7 @@ impl Command for FunCommand {
7237
)
7338
}
7439

75-
/// `contest` handler
40+
/// `fun` handler
7641
async fn handler(m: &ArgMatches<'_>) -> Result<(), Error> {
7742
use crate::cache::Cache;
7843

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /