diff --git a/README.md b/README.md index 4996b0f..150d290 100644 --- a/README.md +++ b/README.md @@ -259,19 +259,13 @@ ml-cellar clone {your_ml_registry} - Materialize all files. ```sh -ml-cellar get-all +ml-cellar materialize-all ``` -- Materialize a specific directory. +- Materialize a specific directory or file. ```sh -ml-cellar get {path to a directory} -``` - -- Materialize a specific file. - -```sh -ml-cellar get {path to a file} +ml-cellar materialize {path to a directory or a file} ``` ## Reference diff --git a/src/bin/ml-cellar/main.rs b/src/bin/ml-cellar/main.rs index 0dbf92d..8d0ae1e 100644 --- a/src/bin/ml-cellar/main.rs +++ b/src/bin/ml-cellar/main.rs @@ -4,6 +4,7 @@ use std::path::PathBuf; mod check; mod clone; mod init; +mod materialize; mod rack; #[derive(Parser, Debug)] @@ -35,6 +36,13 @@ enum Commands { /// Path to the artifacts path: PathBuf, }, + /// Materialize all files managed by Git LFS + MaterializeAll {}, + /// Materialize a file managed by Git LFS + Materialize { + /// Path to the file + path: PathBuf, + }, } fn main() { let cli = Cli::parse(); @@ -51,5 +59,11 @@ fn main() { Commands::Check { path } => { check::check(path); } + Commands::MaterializeAll {} => { + materialize::materialize_all(); + } + Commands::Materialize { path } => { + materialize::materialize(path); + } } } diff --git a/src/bin/ml-cellar/materialize.rs b/src/bin/ml-cellar/materialize.rs new file mode 100644 index 0000000..468e64d --- /dev/null +++ b/src/bin/ml-cellar/materialize.rs @@ -0,0 +1,52 @@ +use std::path::PathBuf; +use std::process::{Command, Stdio}; + +pub fn materialize_all() { + let status = Command::new("git") + .arg("lfs") + .arg("pull") + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status(); + + match status { + Ok(s) if s.success() => { + println!("git lfs pull done"); + } + Ok(s) => { + eprintln!("git lfs pull failed: {s}"); + std::process::exit(1); + } + Err(e) => { + eprintln!("failed to execute git: {e}"); + std::process::exit(1); + } + } +} + +pub fn materialize(path: PathBuf) { + let status = Command::new("git") + .arg("lfs") + .arg("pull") + .arg("-I") + .arg(path.to_str().unwrap()) + .stdin(Stdio::null()) + .stdout(Stdio::null()) + .stderr(Stdio::null()) + .status(); + + match status { + Ok(s) if s.success() => { + println!("git lfs pull -I {} done", path.display()); + } + Ok(s) => { + eprintln!("git lfs pull failed: {s}"); + std::process::exit(1); + } + Err(e) => { + eprintln!("failed to execute git: {e}"); + std::process::exit(1); + } + } +}