-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c15f038
commit a9dfb57
Showing
3 changed files
with
38 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,39 @@ | ||
use nostreq::*; | ||
use std::env; | ||
use uuid::Uuid; | ||
|
||
fn main() { | ||
let cli_matches = cli().get_matches(); | ||
|
||
let mut request = request_from_cli(cli_matches); | ||
let args: Vec<String> = env::args().collect(); | ||
|
||
let request_json = request.to_json(); | ||
// Support for --or as an OR filter input separator | ||
let or_list: Vec<Vec<String>> = args[1..].into_iter().fold(Vec::new(), |mut acc, x| { | ||
if x == "--or" || acc.is_empty() { | ||
acc.push(vec![String::from(args[0].to_string())]); | ||
} | ||
if x != "--or" { | ||
acc.last_mut().unwrap().push((&x).to_string()); | ||
} | ||
acc | ||
}); | ||
|
||
println!(r#"["REQ", "{}", {}]"#, request.subscription_id, request_json); | ||
// Process each OR filter | ||
let mut filter: Vec<String> = vec![]; | ||
for or in &or_list { | ||
|
||
let cli_matches = cli().get_matches_from(or); | ||
|
||
let mut request = request_from_cli(cli_matches); | ||
|
||
let request_json = request.to_json(); | ||
filter.push(request_json); | ||
} | ||
|
||
let cli_matches = cli().get_matches_from(&or_list[0]); | ||
let subscription_id = match cli_matches.get_one::<String>("subscription-id") { | ||
None => { Uuid::new_v4().to_string() }, | ||
Some(id) => { id.to_string() } | ||
}; | ||
|
||
println!(r#"["REQ", "{}", {}]"#, subscription_id, filter.join(",")); | ||
} |