diff --git a/Cargo.lock b/Cargo.lock index 9d48a1c..6351afc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -24,6 +24,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + [[package]] name = "assert_cmd" version = "1.0.2" @@ -68,12 +80,29 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "base64" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + [[package]] name = "bitflags" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +[[package]] +name = "blake2b_simd" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa748e348ad3be8263be728124b24a24f268266f6f5d58af9d75f6a40b5c587" +dependencies = [ + "arrayref", + "arrayvec", + "constant_time_eq", +] + [[package]] name = "cc" version = "1.0.66" @@ -134,6 +163,23 @@ dependencies = [ "tracing-error", ] +[[package]] +name = "constant_time_eq" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" + +[[package]] +name = "crossbeam-utils" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" +dependencies = [ + "autocfg", + "cfg-if 1.0.0", + "lazy_static", +] + [[package]] name = "difference" version = "2.0.0" @@ -146,9 +192,30 @@ version = "0.1.0" dependencies = [ "assert_cmd", "color-eyre", + "directories", "structopt", ] +[[package]] +name = "directories" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fed639d60b58d0f53498ab13d26f621fd77569cc6edb031f4cc36a2ad9da0f" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e93d7f5705de3e49895a2b5e0b8855a1c27f080192ae9c32a6432d50741a57a" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "doc-comment" version = "0.3.3" @@ -178,6 +245,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi", +] + [[package]] name = "gimli" version = "0.23.0" @@ -350,6 +428,35 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "redox_syscall" +version = "0.1.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" + +[[package]] +name = "redox_users" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" +dependencies = [ + "getrandom", + "redox_syscall", + "rust-argon2", +] + +[[package]] +name = "rust-argon2" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b18820d944b33caa75a71378964ac46f58517c92b6ae5f762636247c09e78fb" +dependencies = [ + "base64", + "blake2b_simd", + "constant_time_eq", + "crossbeam-utils", +] + [[package]] name = "rustc-demangle" version = "0.1.18" @@ -590,6 +697,12 @@ dependencies = [ "libc", ] +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index 9d514f5..9723d9a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ path = "src/main.rs" [dependencies] color-eyre = "0.5.10" +directories = "3.0.1" structopt = "0.3.21" [dev-dependencies] diff --git a/README.md b/README.md index d1ee852..318e721 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,14 @@ A CLI tool for the creation and maintenance of Digital Gardens. ## Commands +## Setting the garden path + +```shell +GARDEN_PATH=~/github/my-digital-garden garden write +garden -p ~/github/my-digital-garden write +garden --garden_path ~/github/my-digital-garden write +``` + ### write Open a new file to write in our digital garden. Since we don't necessarily know what we want to title what we're writing, we'll leave the title as optional and ask the user for it later if they don't provide it up-front. diff --git a/src/main.rs b/src/main.rs index d8f1c8c..3ece957 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,7 @@ -use color_eyre::eyre::Result; +use color_eyre::eyre::{eyre, Result, WrapErr}; use digital_garden::write; +use directories::UserDirs; +use std::path::PathBuf; use structopt::StructOpt; /// A CLI for the growing and curation of a digital garden @@ -8,6 +10,9 @@ use structopt::StructOpt; #[derive(StructOpt, Debug)] #[structopt(name = "garden")] struct Opt { + #[structopt(parse(from_os_str), short = "p", long, env)] + garden_path: Option, + #[structopt(subcommand)] cmd: Command, } @@ -24,12 +29,21 @@ enum Command { title: Option, }, } + +fn get_default_garden_dir() -> Result { + let user_dirs = UserDirs::new().ok_or_else(|| eyre!("Could not find home directory"))?; + Ok(user_dirs.home_dir().join(".garden")) +} fn main() -> Result<()> { color_eyre::install()?; let opt = Opt::from_args(); dbg!(&opt); + let garden_path = match opt.garden_path { + Some(pathbuf) => Ok(pathbuf), + None => get_default_garden_dir().wrap_err("`garden_path` was not supplied"), + }?; match opt.cmd { - Command::Write { title } => write(title), + Command::Write { title } => write(garden_path, title), } } diff --git a/src/write.rs b/src/write.rs index 445e8f0..1b4b310 100644 --- a/src/write.rs +++ b/src/write.rs @@ -1,5 +1,7 @@ use color_eyre::Result; +use std::path::PathBuf; -pub fn write(_title: Option) -> Result<()> { +pub fn write(garden_path: PathBuf, title: Option) -> Result<()> { + dbg!(garden_path, title); todo!() }