aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoris2022-01-26 14:31:42 +0100
committerJoris2022-01-26 14:31:42 +0100
commitfe0d0196f133bd902b176aa02119b7f2a49ebc35 (patch)
tree64411c7054041e822bd28ffc7debbc3ad6840111
parentb743fc24ec3ba1aa3ff9bfe5c802019e90034312 (diff)
downloadflashcards-fe0d0196f133bd902b176aa02119b7f2a49ebc35.tar.gz
flashcards-fe0d0196f133bd902b176aa02119b7f2a49ebc35.tar.bz2
flashcards-fe0d0196f133bd902b176aa02119b7f2a49ebc35.zip
Read database path from arguments
-rw-r--r--Cargo.lock129
-rw-r--r--Cargo.toml1
-rw-r--r--src/db/db.rs4
-rw-r--r--src/main.rs11
4 files changed, 142 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index afd9423..55d77f0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -14,12 +14,32 @@ dependencies = [
]
[[package]]
+name = "ansi_term"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
+dependencies = [
+ "winapi",
+]
+
+[[package]]
name = "anyhow"
version = "1.0.45"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7"
[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi",
+]
+
+[[package]]
name = "autocfg"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -57,6 +77,21 @@ dependencies = [
]
[[package]]
+name = "clap"
+version = "2.34.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
+dependencies = [
+ "ansi_term",
+ "atty",
+ "bitflags",
+ "strsim",
+ "textwrap",
+ "unicode-width",
+ "vec_map",
+]
+
+[[package]]
name = "fallible-iterator"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -79,6 +114,7 @@ dependencies = [
"rusqlite_migration",
"serde",
"serde_json",
+ "structopt",
"termion",
"tui",
]
@@ -113,12 +149,36 @@ dependencies = [
]
[[package]]
+name = "heck"
+version = "0.3.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
+dependencies = [
+ "unicode-segmentation",
+]
+
+[[package]]
+name = "hermit-abi"
+version = "0.1.19"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
+dependencies = [
+ "libc",
+]
+
+[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
+name = "lazy_static"
+version = "1.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
+
+[[package]]
name = "libc"
version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -193,6 +253,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba"
[[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-macro2"
version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -338,6 +422,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309"
[[package]]
+name = "strsim"
+version = "0.8.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+
+[[package]]
+name = "structopt"
+version = "0.3.26"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
+dependencies = [
+ "clap",
+ "lazy_static",
+ "structopt-derive",
+]
+
+[[package]]
+name = "structopt-derive"
+version = "0.4.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
+dependencies = [
+ "heck",
+ "proc-macro-error",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
name = "syn"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -361,6 +475,15 @@ dependencies = [
]
[[package]]
+name = "textwrap"
+version = "0.11.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+dependencies = [
+ "unicode-width",
+]
+
+[[package]]
name = "time"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -408,6 +531,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
[[package]]
+name = "vec_map"
+version = "0.8.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
+
+[[package]]
name = "version_check"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 2c971db..95f0f5c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,5 +12,6 @@ rusqlite = { version = "0.26", features = [ "chrono" ] }
rusqlite_migration = "0.5"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
+structopt = "0.3"
termion = "1.5"
tui = "0.16"
diff --git a/src/db/db.rs b/src/db/db.rs
index a3398e2..86614ec 100644
--- a/src/db/db.rs
+++ b/src/db/db.rs
@@ -9,8 +9,8 @@ use rusqlite::{params, Connection};
use rusqlite_migration::{Migrations, M};
use std::time::SystemTime;
-pub fn init() -> Result<Connection> {
- let mut conn = Connection::open("database.db")?;
+pub fn init(database: String) -> Result<Connection> {
+ let mut conn = Connection::open(database)?;
let migrations = Migrations::new(vec![M::up(include_str!("sql/1-init.sql"))]);
migrations.to_latest(&mut conn)?;
Ok(conn)
diff --git a/src/main.rs b/src/main.rs
index 4761366..ef47c73 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,9 +6,18 @@ mod space_repetition;
mod util;
use anyhow::Result;
+use structopt::StructOpt;
+
+#[derive(StructOpt)]
+#[structopt()]
+struct Opt {
+ #[structopt(short, long, default_value = "database.db")]
+ database: String,
+}
fn main() -> Result<()> {
- let conn = db::db::init()?;
+ let opt = Opt::from_args();
+ let conn = db::db::init(opt.database)?;
let entries = deck::read()?;
db::db::add_missing_deck_entries(&conn, entries)?;
gui::gui::start(&conn)