| 30 | } |
| 31 | |
| 32 | pub trait Plugin { |
| 33 | fn name(&self) -> &'static str; |
| 34 | fn install(&self, install_config: InstallConfig) -> Result<()>; |
| 35 | |
| 36 | fn before_install(&self) -> Result<()> { |
| 37 | logger::command_msg("git status --porcelain"); |
| 38 | |
| 39 | let output = std::process::Command::new("git") |
| 40 | .arg("status") |
| 41 | .arg("--porcelain") |
| 42 | .output()?; |
| 43 | |
| 44 | let output = std::str::from_utf8(&output.stdout).unwrap(); |
| 45 | |
| 46 | if !output.is_empty() { |
| 47 | logger::error( |
| 48 | "Please stash and remove any changes (staged, unstaged, and untracked files)", |
| 49 | ); |
| 50 | return Err(anyhow::anyhow!( |
| 51 | "Couldn't add plugin because of a dirty git tree." |
| 52 | )); |
| 53 | } |
| 54 | |
| 55 | Ok(()) |
| 56 | } |
| 57 | |
| 58 | fn after_install(&self, install_config: InstallConfig) -> Result<()> { |
| 59 | // cleanup |
| 60 | project::remove_non_framework_files( |
| 61 | &install_config.project_dir, |
| 62 | install_config.backend_framework, |
| 63 | )?; |
| 64 | |
| 65 | /* |
| 66 | |
| 67 | // TODO: uncomment this after we refactor and add a method to the plugin trait |
| 68 | // which adds plugin-specific binaries to Cargo.toml. Otherwise, we get errors |
| 69 | // like this when running `cargo fmt`: |
| 70 | // |
| 71 | // Error: file `/home/h/w/temp/testoidc2/backend/async_queue.rs` does not exist |
| 72 | // Error: file `/home/h/w/temp/testoidc/.cargo/bin/queue.rs` does not exist |
| 73 | // |
| 74 | logger::command_msg("cargo fmt"); |
| 75 | |
| 76 | let cargo_fmt = std::process::Command::new("cargo") |
| 77 | .current_dir(".") |
| 78 | .arg("fmt") |
| 79 | .stdout(std::process::Stdio::null()) |
| 80 | .status() |
| 81 | .expect("failed to execute process"); |
| 82 | |
| 83 | if !cargo_fmt.success() { |
| 84 | logger::error("Failed to execute `cargo fmt`"); |
| 85 | std::process::exit(1); |
| 86 | } |
| 87 | |
| 88 | */ |
| 89 |
no outgoing calls
no test coverage detected