More crate splitting.
This commit is contained in:
@@ -4,3 +4,13 @@ version = "0.1.0"
|
||||
authors = ["Jordan Petridis <jordanpetridis@protonmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.3.8"
|
||||
loggerv = "0.3.0"
|
||||
structopt = "0.1.0"
|
||||
structopt-derive = "0.1.0"
|
||||
error-chain = "0.11.0"
|
||||
hammond-data = {path = "../hammond-data"}
|
||||
other = {path = "../other"}
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cli = "0.5"
|
||||
@@ -0,0 +1,70 @@
|
||||
extern crate log;
|
||||
extern crate loggerv;
|
||||
|
||||
extern crate structopt;
|
||||
#[macro_use]
|
||||
extern crate structopt_derive;
|
||||
#[macro_use]
|
||||
extern crate error_chain;
|
||||
|
||||
extern crate other;
|
||||
extern crate hammond_data;
|
||||
|
||||
use structopt::StructOpt;
|
||||
use hammond_data::dbqueries;
|
||||
use other::errors::*;
|
||||
use other::downloader;
|
||||
use other::index_feed;
|
||||
|
||||
// Should probably had made an Enum instead.
|
||||
#[derive(StructOpt, Debug)]
|
||||
#[structopt(name = "example", about = "An example of StructOpt usage.")]
|
||||
struct Opt {
|
||||
/// Enable logging, use multiple `v`s to increase verbosity
|
||||
#[structopt(short = "v", long = "verbose")]
|
||||
verbosity: u64,
|
||||
|
||||
#[structopt(long = "update")] up: bool,
|
||||
|
||||
#[structopt(long = "latest")] latest: bool,
|
||||
|
||||
#[structopt(long = "download", default_value = "-1")] dl: i64,
|
||||
|
||||
#[structopt(short = "a", long = "add", default_value = "")] add: String,
|
||||
}
|
||||
|
||||
fn run() -> Result<()> {
|
||||
let args = Opt::from_args();
|
||||
|
||||
loggerv::init_with_verbosity(args.verbosity)?;
|
||||
|
||||
hammond_data::init()?;
|
||||
|
||||
// Initial prototype for testing.
|
||||
// The plan is to write a Gtk+ gui later.
|
||||
if args.add != "".to_string() {
|
||||
let db = hammond_data::establish_connection();
|
||||
let _ = index_feed::insert_return_source(&db, &args.add);
|
||||
}
|
||||
|
||||
if args.up {
|
||||
let db = hammond_data::establish_connection();
|
||||
index_feed::index_loop(db)?;
|
||||
}
|
||||
|
||||
if args.dl >= 0 {
|
||||
let db = hammond_data::establish_connection();
|
||||
downloader::latest_dl(&db, args.dl as u32)?;
|
||||
}
|
||||
|
||||
if args.latest {
|
||||
let db = hammond_data::establish_connection();
|
||||
let foo = dbqueries::get_episodes_with_limit(&db, 10)?;
|
||||
// This ends up horribly but works for now.
|
||||
let _: Vec<_> = foo.iter().map(|x| println!("{:?}", x)).collect();
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
quick_main!(run);
|
||||
@@ -0,0 +1,37 @@
|
||||
extern crate assert_cli;
|
||||
|
||||
// Notes:
|
||||
// The following tests will use your systems local hammond db.
|
||||
// There are no test for failure, cause the behavior have not
|
||||
// been defined/though yet.
|
||||
|
||||
#[test]
|
||||
fn test_update() {
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&["--update"])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_download() {
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&["--download"])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_add() {
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&[
|
||||
"--add",
|
||||
"https://feeds.feedburner.com/InterceptedWithJeremyScahill",
|
||||
])
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_latest() {
|
||||
assert_cli::Assert::main_binary()
|
||||
.with_args(&["--latest"])
|
||||
.unwrap();
|
||||
}
|
||||
Reference in New Issue
Block a user