diff --git a/.gitignore b/.gitignore index 40d9aca..43f23fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/.idea \ No newline at end of file +/.idea +/projects \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 3cdc2f1..9533a52 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,6 +110,7 @@ name = "command_init" version = "0.1.0" dependencies = [ "clap", + "manifest", ] [[package]] @@ -140,6 +141,10 @@ version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456" +[[package]] +name = "manifest" +version = "0.1.0" + [[package]] name = "mccli" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 07f8732..c839548 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,4 @@ resolver = '2' members = [ 'mccli', 'command_init', -] \ No newline at end of file +] diff --git a/command_init/Cargo.toml b/command_init/Cargo.toml index 2c1d42b..e604826 100644 --- a/command_init/Cargo.toml +++ b/command_init/Cargo.toml @@ -6,4 +6,5 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +manifest = {path = "../manifest"} clap = { version = "4.4.8", features = ["derive", "unicode", "wrap_help"] } \ No newline at end of file diff --git a/command_init/src/lib.rs b/command_init/src/lib.rs index 3859e1b..d80caa9 100644 --- a/command_init/src/lib.rs +++ b/command_init/src/lib.rs @@ -1,4 +1,6 @@ +use std::path::PathBuf; use clap::{Args}; +use manifest::Manifest; #[derive(Args, Debug)] pub struct Arguments { @@ -7,20 +9,8 @@ pub struct Arguments { } pub fn execute (_arguments: &Arguments) { - println!("Hello from init!"); -} + let directory: PathBuf = PathBuf::from(_arguments.directory.clone()); -pub fn add(left: usize, right: usize) -> usize { - left + right -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let result = add(2, 2); - assert_eq!(result, 4); - } + let manifest = Manifest::new(&directory); + manifest.init(); } diff --git a/manifest/Cargo.toml b/manifest/Cargo.toml new file mode 100644 index 0000000..1c98fd3 --- /dev/null +++ b/manifest/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "manifest" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/manifest/src/lib.rs b/manifest/src/lib.rs new file mode 100644 index 0000000..be9a577 --- /dev/null +++ b/manifest/src/lib.rs @@ -0,0 +1,33 @@ +use std::fs; +use std::path::{PathBuf}; + +#[derive(Debug)] +pub struct Manifest { + directory: PathBuf +} + +impl Manifest { + pub fn new(path: &PathBuf) -> Manifest { + let mut directory: PathBuf = path.into(); + + if path.is_file() { + directory = path.parent() + .map(|parent| parent.to_path_buf()) + .unwrap_or_else(|| path.into()) + } + + if let Err(_err) = fs::create_dir_all(&directory) { + panic!("Failed to created directory: {:?}", &directory); + } + + Manifest { directory: directory.canonicalize().unwrap() } + } + + pub fn init(&self) -> bool { + let directory: PathBuf = self.directory.clone(); + + println!("init: {:?}", directory); + + true + } +}