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 5895ec6

Browse files
Adds argument for filtering problems by id range
1 parent c9f0d59 commit 5895ec6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎src/cmds/list.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static LIST_AFTER_HELP: &str = r#"EXAMPLES:
6565
leetcode list -c database List questions that in database category
6666
leetcode list -q eD List questions that with easy level and not done
6767
leetcode list -t linked-list List questions that under tag "linked-list"
68+
leetcode list -r 50 100 List questions that has id in between 50 and 100
6869
"#;
6970

7071
/// implement Command trait for `list`
@@ -96,6 +97,14 @@ impl Command for ListCommand {
9697
.takes_value(true)
9798
.help(QUERY_HELP),
9899
)
100+
.arg(
101+
Arg::with_name("range")
102+
.short("r")
103+
.long("range")
104+
.takes_value(true)
105+
.min_values(2)
106+
.help("Filter questions by id range"),
107+
)
99108
.after_help(LIST_AFTER_HELP)
100109
.arg(
101110
Arg::with_name("stat")
@@ -163,6 +172,16 @@ impl Command for ListCommand {
163172
crate::helper::filter(&mut ps, query.to_string());
164173
}
165174

175+
// filter range
176+
if m.is_present("range") {
177+
let range: Vec<_> = m.values_of("range")?.collect();
178+
let num_range: Vec<i32> = range
179+
.into_iter()
180+
.map(|x| x.parse::<i32>().unwrap_or(0))
181+
.collect();
182+
ps.retain(|x| num_range[0] <= x.fid && x.fid <= num_range[1]);
183+
}
184+
166185
// retain if keyword exists
167186
if let Some(keyword) = m.value_of("keyword") {
168187
ps.retain(|x| x.name.contains(&keyword));

0 commit comments

Comments
(0)

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