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",
]
[[package]]
name = "heck"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "hermit-abi"
version = "0.1.17"
@ -1254,13 +1245,13 @@ name = "paperoni"
version = "0.1.0-alpha1"
dependencies = [
"async-std",
"clap",
"epub-builder",
"html5ever",
"kuchiki",
"lazy_static",
"md5",
"regex",
"structopt",
"surf",
"url",
]
@ -1424,30 +1415,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "proc-macro-hack"
version = "0.5.19"
@ -1900,30 +1867,6 @@ version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "subtle"
version = "2.3.0"
@ -2168,12 +2111,6 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db8716a166f290ff49dabc18b44aa407cb7c6dbe1aa0971b44b8a24b0ca35aae"
[[package]]
name = "unicode-width"
version = "0.1.8"

View file

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

View file

@ -1,13 +1,21 @@
use structopt::StructOpt;
use clap::{App, AppSettings, Arg};
#[derive(Debug, StructOpt)]
#[structopt(name = "paperoni")]
/// Paperoni is an article downloader.
///
/// It takes a url and downloads the article content from it and
/// saves it to an epub.
pub struct Opts {
// #[structopt(conflicts_with("links"))]
/// Url of a web article
pub urls: Vec<String>,
pub fn cli_init() -> App<'static, 'static> {
App::new("paperoni")
.settings(&[
AppSettings::ArgRequiredElseHelp,
AppSettings::UnifiedHelpMessage,
])
.version("0.1.0-alpha1")
.about(
"
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 epub_builder::{EpubBuilder, EpubContent, ZipLibrary};
use structopt::StructOpt;
use url::Url;
mod cli;
@ -14,10 +13,11 @@ mod moz_readability;
use extractor::Extractor;
fn main() {
let opt = cli::Opts::from_args();
if !opt.urls.is_empty() {
println!("Downloading single article");
download(opt.urls);
let app = cli::cli_init();
let arg_matches = app.get_matches();
if let Some(vals) = arg_matches.values_of("urls") {
let urls = vals.map(|val| val.to_string()).collect::<Vec<_>>();
download(urls);
}
}