Browse Source

Merge pull request #10 from jbiason/clap

Added command line interface with clap
master
Julio Biason 3 years ago committed by GitHub
parent
commit
2ccee8e7b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 54
      Cargo.lock
  2. 16
      Cargo.toml
  3. 43
      src/args/mod.rs
  4. 10
      src/main.rs

54
Cargo.lock generated

@ -15,6 +15,15 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi 0.3.8",
]
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.4.11" version = "0.4.11"
@ -171,6 +180,21 @@ dependencies = [
"time", "time",
] ]
[[package]]
name = "clap"
version = "2.33.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
dependencies = [
"ansi_term",
"atty",
"bitflags",
"strsim",
"textwrap",
"unicode-width",
"vec_map",
]
[[package]] [[package]]
name = "cloudabi" name = "cloudabi"
version = "0.0.3" version = "0.0.3"
@ -303,9 +327,10 @@ checksum = "923dea538cea0aa3025e8685b20d6ee21ef99c4f77e954a30febbaac5ec73a97"
[[package]] [[package]]
name = "downfav" name = "downfav"
version = "0.4.0" version = "0.4.1"
dependencies = [ dependencies = [
"chrono", "chrono",
"clap",
"elefren", "elefren",
"env_logger", "env_logger",
"html2md", "html2md",
@ -1723,6 +1748,12 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc" checksum = "b1884d1bc09741d466d9b14e6d37ac89d6909cbcac41dd9ae982d4d063bbedfc"
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]] [[package]]
name = "syn" name = "syn"
version = "0.15.44" version = "0.15.44"
@ -1807,6 +1838,15 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "textwrap"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
dependencies = [
"unicode-width",
]
[[package]] [[package]]
name = "thread_local" name = "thread_local"
version = "0.3.6" version = "0.3.6"
@ -2011,6 +2051,12 @@ dependencies = [
"smallvec", "smallvec",
] ]
[[package]]
name = "unicode-width"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
version = "0.1.0" version = "0.1.0"
@ -2075,6 +2121,12 @@ version = "0.2.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95" checksum = "33dd455d0f96e90a75803cfeb7f948768c08d70a6de9a8d2362461935698bf95"
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.1.5" version = "0.1.5"

16
Cargo.toml

@ -1,19 +1,21 @@
[package] [package]
name = "downfav" name = "downfav"
version = "0.4.0" version = "0.4.1"
authors = ["Julio Biason <julio.biason@pm.me>"] authors = ["Julio Biason <julio.biason@pm.me>"]
edition = "2018" edition = "2018"
description = "Download Mastodon favourites"
[dependencies] [dependencies]
chrono = "0.4"
clap = "2.33"
elefren = { version = "0.20", features = ["toml"] } elefren = { version = "0.20", features = ["toml"] }
env_logger = "0.8"
html2md = "0.2" html2md = "0.2"
html5ever = "0.25"
log = "0.4"
markup5ever = "0.10"
markup5ever_rcdom = "0.1"
reqwest = "0.9" reqwest = "0.9"
serde = "*" serde = "*"
serde_derive = "*" serde_derive = "*"
toml = "0.5" toml = "0.5"
log = "0.4"
env_logger = "0.8"
chrono = "0.4"
html5ever = "0.25"
markup5ever_rcdom = "0.1"
markup5ever = "0.10"

43
src/args/mod.rs

@ -0,0 +1,43 @@
/*
DOWNFAV - Download Favourites
Copyright (C) 2020 Julio Biason
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
use clap::App;
use clap::SubCommand;
/// Possible commands
pub enum Command {
/// Got a command that we don't know
Unknown,
/// Fetch all new favourites
Fetch,
}
/// Parse the command line, returning the necessary command.
pub fn parse() -> Command {
let parser = App::new(clap::crate_name!())
.version(clap::crate_version!())
.author(clap::crate_authors!())
.about(clap::crate_description!())
.subcommand(SubCommand::with_name("fetch").about("Fetch the new favourites"));
let matches = parser.get_matches();
match matches.subcommand() {
("", _) => Command::Fetch,
("fetch", _) => Command::Fetch,
_ => Command::Unknown,
}
}

10
src/main.rs

@ -27,12 +27,21 @@ use crate::storage::joplin::Joplin;
use crate::storage::org::Org; use crate::storage::org::Org;
use crate::storage::storage::Storage; use crate::storage::storage::Storage;
mod args;
mod config; mod config;
mod storage; mod storage;
fn main() { fn main() {
env_logger::init(); env_logger::init();
match args::parse() {
args::Command::Fetch => fetch_favourites(),
_ => println!("Unknown command"),
}
}
/// Retrieve favourites
fn fetch_favourites() {
let config = match config::Config::get() { let config = match config::Config::get() {
Ok(config) => config, Ok(config) => config,
Err(e) => { Err(e) => {
@ -80,7 +89,6 @@ fn main() {
config.save(&new_favourite); config.save(&new_favourite);
} }
} }
/// Create a connection to a mastodon server. /// Create a connection to a mastodon server.
fn connect_to_mastodon() -> elefren::data::Data { fn connect_to_mastodon() -> elefren::data::Data {
println!("Your server URL: "); println!("Your server URL: ");

Loading…
Cancel
Save