Add -f flag for adding links from a file instead of needing to use cat
This commit is contained in:
parent
b98c0a69a6
commit
3d56023592
3 changed files with 35 additions and 3 deletions
|
@ -12,7 +12,13 @@ Paperoni is a web article downloader written in Rust. The downloaded articles ar
|
||||||
paperoni https://en.wikipedia.org/wiki/Pepperoni
|
paperoni https://en.wikipedia.org/wiki/Pepperoni
|
||||||
```
|
```
|
||||||
|
|
||||||
Paperoni also supports passing multiple links as arguments. If you are on a Unix-like OS, you can simply do something like this:
|
Paperoni also supports passing multiple links as arguments. These can be read from a file using the `-f` flag.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
paperoni -f links.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
Alternatively, if you are on a Unix-like OS, you can simply do something like this:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
cat links.txt | xargs paperoni
|
cat links.txt | xargs paperoni
|
||||||
|
|
|
@ -18,4 +18,11 @@ It takes a url and downloads the article content from it and saves it to an epub
|
||||||
.help("Urls of web articles")
|
.help("Urls of web articles")
|
||||||
.multiple(true),
|
.multiple(true),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("file")
|
||||||
|
.short("f")
|
||||||
|
.long("file")
|
||||||
|
.help("Input file containing links")
|
||||||
|
.takes_value(true),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
23
src/main.rs
23
src/main.rs
|
@ -1,7 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate lazy_static;
|
extern crate lazy_static;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::{fs::File, io::Read};
|
||||||
|
|
||||||
use async_std::task;
|
use async_std::task;
|
||||||
use epub_builder::{EpubBuilder, EpubContent, ZipLibrary};
|
use epub_builder::{EpubBuilder, EpubContent, ZipLibrary};
|
||||||
|
@ -15,8 +15,27 @@ use extractor::Extractor;
|
||||||
fn main() {
|
fn main() {
|
||||||
let app = cli::cli_init();
|
let app = cli::cli_init();
|
||||||
let arg_matches = app.get_matches();
|
let arg_matches = app.get_matches();
|
||||||
|
let mut urls: Vec<String> = match arg_matches.value_of("file") {
|
||||||
|
Some(file_name) => {
|
||||||
|
if let Ok(mut file) = File::open(file_name) {
|
||||||
|
let mut content = String::new();
|
||||||
|
match file.read_to_string(&mut content) {
|
||||||
|
Ok(_) => content.lines().map(|line| line.to_owned()).collect(),
|
||||||
|
Err(_) => vec![],
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
println!("Unable to open file: {}", file_name);
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => vec![],
|
||||||
|
};
|
||||||
|
|
||||||
if let Some(vals) = arg_matches.values_of("urls") {
|
if let Some(vals) = arg_matches.values_of("urls") {
|
||||||
let urls = vals.map(|val| val.to_string()).collect::<Vec<_>>();
|
urls.extend(vals.map(|val| val.to_string()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if !urls.is_empty() {
|
||||||
download(urls);
|
download(urls);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue