Add 'manifest' package and integrate it with 'command_init'
A new package named 'manifest' is introduced in this commit. It comprises a single structure and related functions for managing manifests. Additionally, 'command_init' has been altered to use this new module instead of using its previously hard-coded functionality. A reference to 'manifest' has also been added in the Cargo.lock and command_init/Cargo.toml files.
This commit is contained in:
parent
b09a4a41ff
commit
b3d7c776e8
|
@ -1,2 +1,3 @@
|
|||
/target
|
||||
/.idea
|
||||
/.idea
|
||||
/projects
|
|
@ -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"
|
||||
|
|
|
@ -3,4 +3,4 @@ resolver = '2'
|
|||
members = [
|
||||
'mccli',
|
||||
'command_init',
|
||||
]
|
||||
]
|
||||
|
|
|
@ -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"] }
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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]
|
|
@ -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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue