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

Commit 90c3749

Browse files
Clean up ID selecting code
1 parent 45079f2 commit 90c3749

File tree

1 file changed

+20
-23
lines changed

1 file changed

+20
-23
lines changed

‎src/cmds/pick.rs‎

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -137,32 +137,29 @@ impl Command for PickCommand {
137137

138138
let fid = match m.contains_id("name") {
139139
//check for name specified
140-
true => {
141-
match m.get_one::<String>("name").map(|name| name) {
142-
Some(quesname) => match cache.get_problem_from_name(quesname) {
143-
Ok(p) => p.fid,
144-
Err(_) => 1,
145-
},
146-
None => {
147-
// Pick random without specify id
148-
let problem = &problems[rand::thread_rng().gen_range(0..problems.len())];
149-
problem.fid
150-
}
151-
}
152-
}
153-
false => {
154-
m.get_one::<i32>("id")
155-
.map(|id| *id)
156-
.or(daily_id)
157-
.unwrap_or_else(|| {
158-
// Pick random without specify id
159-
let problem = &problems[rand::thread_rng().gen_range(0..problems.len())];
160-
problem.fid
161-
})
140+
true => match m.get_one::<String>("name").map(|name| name) {
141+
Some(quesname) => match cache.get_problem_id_from_name(quesname) {
142+
Ok(p) => Ok(p),
143+
Err(e) => Err(e),
144+
},
145+
None => Err(Error::NoneError),
146+
},
147+
false => match m.get_one::<i32>("id").map(|id| *id).or(daily_id) {
148+
Some(p) => Ok(p),
149+
None => Err(Error::NoneError),
150+
},
151+
};
152+
153+
let id = match fid {
154+
Ok(id) => id,
155+
Err(_) => {
156+
// Pick random without specify id
157+
let problem = &problems[rand::thread_rng().gen_range(0..problems.len())];
158+
problem.fid
162159
}
163160
};
164161

165-
let r = cache.get_question(fid).await;
162+
let r = cache.get_question(id).await;
166163

167164
match r {
168165
Ok(q) => println!("{}", q.desc()),

0 commit comments

Comments
(0)

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