diff options
-rw-r--r-- | .dev-suite/ticket/closed/3-create-a-find_root-function.toml (renamed from .dev-suite/ticket/open/3-create-a-find_root-function.toml) | 2 | ||||
-rw-r--r-- | Cargo.lock | 8 | ||||
-rw-r--r-- | Cargo.toml | 1 | ||||
-rw-r--r-- | shared/Cargo.toml | 10 | ||||
-rw-r--r-- | shared/src/lib.rs | 23 | ||||
-rw-r--r-- | ticket/Cargo.toml | 1 | ||||
-rw-r--r-- | ticket/src/main.rs | 71 |
7 files changed, 57 insertions, 59 deletions
diff --git a/.dev-suite/ticket/open/3-create-a-find_root-function.toml b/.dev-suite/ticket/closed/3-create-a-find_root-function.toml index 7ec030e..5057356 100644 --- a/.dev-suite/ticket/open/3-create-a-find_root-function.toml +++ b/.dev-suite/ticket/closed/3-create-a-find_root-function.toml @@ -1,5 +1,5 @@ title = 'Create a find_root function' -status = 'Open' +status = 'Closed' number = 3 description = ''' One of the issues with ticket is that it has a bug in init where if it's @@ -374,6 +374,13 @@ dependencies = [ ] [[package]] +name = "shared" +version = "0.1.0" +dependencies = [ + "anyhow 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "strsim" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -437,6 +444,7 @@ dependencies = [ "paw 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustyline 5.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "shared 0.1.0", "structopt 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1,4 +1,5 @@ [workspace] members = [ + "shared", "ticket", ] diff --git a/shared/Cargo.toml b/shared/Cargo.toml new file mode 100644 index 0000000..a072d12 --- /dev/null +++ b/shared/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "shared" +version = "0.1.0" +authors = ["Michael Gattozzi <mgattozzi@gmail.com>"] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = "1.0" diff --git a/shared/src/lib.rs b/shared/src/lib.rs new file mode 100644 index 0000000..9fdcc27 --- /dev/null +++ b/shared/src/lib.rs @@ -0,0 +1,23 @@ +use anyhow::{bail, Result}; +use std::{env, path::PathBuf}; + +pub fn find_root() -> Result<PathBuf> { + let mut location = env::current_dir()?; + let mut found_root = false; + + for loc in location.ancestors() { + let mut loc = loc.join(".git"); + if loc.exists() { + loc.pop(); + found_root = true; + location = loc.canonicalize()?; + break; + } + } + + if found_root { + Ok(location) + } else { + bail!("Unable to find a valid git repo"); + } +} diff --git a/ticket/Cargo.toml b/ticket/Cargo.toml index fd97293..3110147 100644 --- a/ticket/Cargo.toml +++ b/ticket/Cargo.toml @@ -12,5 +12,6 @@ colored = "1.9" paw = "1.0" rustyline = "5.0" serde = { version = "1.0", features = ["derive"] } +shared = { path = "../shared" } structopt = { version = "0.3", features = ["paw"] } toml = "0.5" diff --git a/ticket/src/main.rs b/ticket/src/main.rs index 8b9b542..00b6715 100644 --- a/ticket/src/main.rs +++ b/ticket/src/main.rs @@ -1,31 +1,14 @@ -use anyhow::{ - bail, - Result, -}; +use anyhow::{bail, Result}; use colored::*; -use rustyline::{ - error::ReadlineError, - Editor, -}; -use serde::{ - Deserialize, - Serialize, -}; -use std::{ - env, - fs, - path::PathBuf, - process, - process::Command, -}; +use rustyline::{error::ReadlineError, Editor}; +use serde::{Deserialize, Serialize}; +use shared::find_root; +use std::{env, fs, path::PathBuf, process, process::Command}; #[derive(structopt::StructOpt)] enum Args { /// Initialize the repo to use ticket - Init { - #[structopt(default_value = ".", parse(from_os_str))] - location: PathBuf, - }, + Init, New, Show { id: usize, @@ -38,7 +21,7 @@ enum Args { #[paw::main] fn main(args: Args) { if let Err(e) = match args { - Args::Init { location } => init(location), + Args::Init => init(), Args::New => new(), Args::Show { id } => show(id), Args::Close { id } => close(id), @@ -48,19 +31,11 @@ fn main(args: Args) { } } -fn init(location: PathBuf) -> Result<()> { - if location.join(".git").is_dir() { - let root = location.join(".dev-suite").join("ticket"); - fs::create_dir_all(&root)?; - fs::create_dir_all(&root.join("open"))?; - fs::create_dir_all(&root.join("closed"))?; - Ok(()) - } else { - bail!( - "{} is not a valid git repository", - location.canonicalize()?.display() - ) - } +fn init() -> Result<()> { + let root = find_root()?.join(".dev-suite").join("ticket"); + fs::create_dir_all(&root.join("open"))?; + fs::create_dir_all(&root.join("closed"))?; + Ok(()) } fn new() -> Result<()> { @@ -125,28 +100,8 @@ fn new() -> Result<()> { Ok(()) } -fn find_root() -> Result<PathBuf> { - let mut location = env::current_dir()?; - let mut found_root = false; - - for loc in location.ancestors() { - let loc = loc.join(".dev-suite"); - if loc.exists() { - found_root = true; - location = loc.canonicalize()?; - break; - } - } - - if found_root { - Ok(location) - } else { - bail!("Unable to find a dev-suite enabled repo"); - } -} - fn ticket_root() -> Result<PathBuf> { - Ok(find_root()?.join("ticket")) + Ok(find_root()?.join(".dev-suite").join("ticket")) } fn show(id: usize) -> Result<()> { |