diff --git a/cli/src/main.rs b/cli/src/main.rs index ac838117..e8d72fe0 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -12,7 +12,7 @@ use git_version::git_version; use printnanny_nats::message_v2::{NatsReply, NatsRequest}; use printnanny_nats::cloud_worker::DEFAULT_NATS_CLOUD_APP_NAME; use printnanny_nats::subscriber::{ NatsSubscriber, DEFAULT_NATS_EDGE_APP_NAME}; -use printnanny_settings::SettingsFormat; +use printnanny_settings::{SettingsFormat}; use printnanny_services::janus::{ JanusAdminEndpoint, janus_admin_api_call }; use printnanny_cli::settings::{SettingsCommand}; use printnanny_cli::cloud_data::CloudDataCommand; @@ -110,6 +110,18 @@ async fn main() -> Result<()> { .version(GIT_VERSION) .arg_required_else_help(true) .about("Interact with PrintNanny device and user settings") + .subcommand(Command::new("clone") + .author(crate_authors!()) + .about(crate_description!()) + .version(GIT_VERSION) + .about("Git clone PrintNanny Settings repo (default settings files for PrintNanny, OctoPrint, Moonraker, Klipper)") + .arg(Arg::new("dir") + .short('d') + .long("dir") + .takes_value(true) + .help("Directory to clone repo to") + ) + ) .subcommand(Command::new("get") .author(crate_authors!()) .about(crate_description!()) diff --git a/cli/src/settings.rs b/cli/src/settings.rs index 1a0ae1f3..ce001502 100644 --- a/cli/src/settings.rs +++ b/cli/src/settings.rs @@ -1,4 +1,5 @@ use std::io::{self, Write}; +use std::path::PathBuf; use printnanny_services::error::ServiceError; use printnanny_settings::printnanny::PrintNannySettings; @@ -10,6 +11,11 @@ impl SettingsCommand { pub async fn handle(sub_m: &clap::ArgMatches) -> Result<(), ServiceError> { let config: PrintNannySettings = PrintNannySettings::new()?; match sub_m.subcommand() { + Some(("clone", args)) => { + let dir = args.value_of("dir").map(PathBuf::from); + let settings = PrintNannySettings::new()?; + settings.init_local_git_repo(dir).await?; + } Some(("get", args)) => { let key = args.value_of("key"); let f: SettingsFormat = args.value_of_t("format").unwrap(); diff --git a/nats/src/message_v2.rs b/nats/src/message_v2.rs index fefa2e2b..703dc889 100644 --- a/nats/src/message_v2.rs +++ b/nats/src/message_v2.rs @@ -702,7 +702,7 @@ mod tests { let settings = PrintNannySettings::new().unwrap(); Runtime::new() .unwrap() - .block_on(settings.init_local_git_repo()) + .block_on(settings.init_local_git_repo(None)) .unwrap(); } diff --git a/settings/src/printnanny.rs b/settings/src/printnanny.rs index 704f0c90..756ad519 100644 --- a/settings/src/printnanny.rs +++ b/settings/src/printnanny.rs @@ -136,8 +136,12 @@ impl PrintNannySettings { Ok(result) } - pub async fn init_local_git_repo(&self) -> Result<(), PrintNannySettingsError> { - let repo = git2::Repository::clone(&self.git.remote, &self.paths.settings_dir)?; + pub async fn init_local_git_repo( + &self, + dir: Option, + ) -> Result<(), PrintNannySettingsError> { + let target_dir = dir.unwrap_or(self.paths.settings_dir.clone()); + let repo = git2::Repository::clone(&self.git.remote, &target_dir)?; let config = repo.config()?; let mut localconfig = config.open_level(git2::ConfigLevel::Local)?; localconfig.set_str("user.email", &self.git.email)?;