run.rs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. use clap::Values;
  2. use crate::lib::{
  3. config::Config,
  4. repository::Repository,
  5. group::Group,
  6. repotype::RepoType,
  7. action::Action
  8. };
  9. use string_template::Template;
  10. use std::process::Command;
  11. use std::collections::HashMap;
  12. pub fn run(config: &Config, names: Values<'_>) {
  13. for name in names {
  14. println!("Running {}...", name)
  15. }
  16. }
  17. pub fn run_action(config: &Config, name: String) {
  18. let action = config.actions.get(&name.to_string());
  19. match action {
  20. Some(action) => {
  21. if !action.disabled {
  22. Command::new("sh")
  23. .arg("-c")
  24. .arg(&action.command)
  25. .spawn();
  26. }
  27. },
  28. None => panic!("No known action named \"{}\".", name)
  29. }
  30. }
  31. pub fn run_repository_creation(config: &Config, name: String) {
  32. let repository = config.repositories.get(&name.to_string());
  33. match repository {
  34. Some(repository) => {
  35. let repository_type_name = &repository.repo_type;
  36. let repository_type = config.repo_types.get(repository_type_name);
  37. match repository_type {
  38. Some(repository_type) => {
  39. if !repository.disabled {
  40. let mut options: HashMap<&str, &str> = HashMap::new();
  41. for (key, value) in &repository.options {
  42. options.insert(key, value);
  43. }
  44. options.insert("location", &repository.location);
  45. let create_command = Template::new(&repository_type.create);
  46. Command::new("sh")
  47. .arg("-c")
  48. .arg(create_command.render(&options))
  49. .spawn();
  50. }
  51. },
  52. None => panic!("No known repository type named \"{}\".", repository_type_name)
  53. }
  54. },
  55. None => panic!("No known repository named \"{}\".", name)
  56. }
  57. }