Change from structopt to clap

This allows printing the help message if no args are passed
This commit is contained in:
Kenneth Gitere 2020-11-24 09:58:50 +03:00
parent cdfbc2b3f6
commit 37cb4e1fd2
4 changed files with 26 additions and 81 deletions

65
Cargo.lock generated
View file

@ -822,15 +822,6 @@ dependencies = [
"web-sys", "web-sys",
] ]
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
dependencies = [
"unicode-segmentation",
]
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.1.17" version = "0.1.17"
@ -1254,13 +1245,13 @@ name = "paperoni"
version = "0.1.0-alpha1" version = "0.1.0-alpha1"
dependencies = [ dependencies = [
"async-std", "async-std",
"clap",
"epub-builder", "epub-builder",
"html5ever", "html5ever",
"kuchiki", "kuchiki",
"lazy_static", "lazy_static",
"md5", "md5",
"regex", "regex",
"structopt",
"surf", "surf",
"url", "url",
] ]
@ -1424,30 +1415,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]]
name = "proc-macro-error"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"version_check",
]
[[package]]
name = "proc-macro-error-attr"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"version_check",
]
[[package]] [[package]]
name = "proc-macro-hack" name = "proc-macro-hack"
version = "0.5.19" version = "0.5.19"
@ -1900,30 +1867,6 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]]
name = "structopt"
version = "0.3.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "126d630294ec449fae0b16f964e35bf3c74f940da9dca17ee9b905f7b3112eb8"
dependencies = [
"clap",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65e51c492f9e23a220534971ff5afc14037289de430e3c83f9daf6a1b6ae91e8"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.3.0" version = "2.3.0"
@ -2168,12 +2111,6 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "unicode-segmentation"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8716a166f290ff49dabc18b44aa407cb7c6dbe1aa0971b44b8a24b0ca35aae"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.1.8" version = "0.1.8"

View file

@ -13,6 +13,7 @@ readme = "README.md"
[dependencies] [dependencies]
async-std = "1.7.0" async-std = "1.7.0"
clap = "2.33.3"
epub-builder = "0.4.8" epub-builder = "0.4.8"
html5ever = "0.25.1" html5ever = "0.25.1"
kuchiki = "0.8.1" kuchiki = "0.8.1"
@ -20,5 +21,4 @@ lazy_static = "1.4.0"
md5 = "0.7.0" md5 = "0.7.0"
regex = "1.4.2" regex = "1.4.2"
surf = "2.1.0" surf = "2.1.0"
structopt = { version = "0.3" }
url = "2.2.0" url = "2.2.0"

View file

@ -1,13 +1,21 @@
use structopt::StructOpt; use clap::{App, AppSettings, Arg};
#[derive(Debug, StructOpt)] pub fn cli_init() -> App<'static, 'static> {
#[structopt(name = "paperoni")] App::new("paperoni")
/// Paperoni is an article downloader. .settings(&[
/// AppSettings::ArgRequiredElseHelp,
/// It takes a url and downloads the article content from it and AppSettings::UnifiedHelpMessage,
/// saves it to an epub. ])
pub struct Opts { .version("0.1.0-alpha1")
// #[structopt(conflicts_with("links"))] .about(
/// Url of a web article "
pub urls: Vec<String>, Paperoni is an article downloader.
It takes a url and downloads the article content from it and saves it to an epub.
",
)
.arg(
Arg::with_name("urls")
.help("Urls of web articles")
.multiple(true),
)
} }

View file

@ -5,7 +5,6 @@ use std::fs::File;
use async_std::task; use async_std::task;
use epub_builder::{EpubBuilder, EpubContent, ZipLibrary}; use epub_builder::{EpubBuilder, EpubContent, ZipLibrary};
use structopt::StructOpt;
use url::Url; use url::Url;
mod cli; mod cli;
@ -14,10 +13,11 @@ mod moz_readability;
use extractor::Extractor; use extractor::Extractor;
fn main() { fn main() {
let opt = cli::Opts::from_args(); let app = cli::cli_init();
if !opt.urls.is_empty() { let arg_matches = app.get_matches();
println!("Downloading single article"); if let Some(vals) = arg_matches.values_of("urls") {
download(opt.urls); let urls = vals.map(|val| val.to_string()).collect::<Vec<_>>();
download(urls);
} }
} }